Part 2: Objective functions =========================== One of the main problems in the Coverage Path Planning problem is to define the objective function. The objective function defines how good is our optimizer solving our problem. By default, objective functions are defined as minimization problems. Fields2Cover defines different objective functions for each module: Decomp (Decomposition), HG (Headland Generator), SG (Swath Generator), RP (Route Planner) and PP (Path Planner). Decomp objective functions -------------------------- *There is none yet* HG objective functions ---------------------- Remaining area ^^^^^^^^^^^^^^ Compute the percentage of main field over the total field. The cost is a value between [0, 1], and it is defined as a maximization problem. .. tabs:: lang .. code-tab:: c :caption: C++ F2CCells total_field(F2CCell(F2CLinearRing( {F2CPoint(-2,-2), F2CPoint(6,-2), F2CPoint(6,6), F2CPoint(-2,6), F2CPoint(-2,-2)}))); F2CCells field(F2CCell(F2CLinearRing( {F2CPoint(0,0), F2CPoint(4,0), F2CPoint(4,4), F2CPoint(0,4), F2CPoint(0,0)}))); f2c::obj::RemArea rem_area; std::cout << "The remaining area is " << rem_area.computeCost(total_field, field) << std::endl; std::cout << "The remaining area with sign is " << rem_area.computeCostWithMinimizingSign(total_field, field) < complete_length(robot); std::cout << "The complete length is: " << complete_length.computeCost(swaths_path) << " =~= " << 1 + 1 + M_PI/2.0 << std::endl; .. code-tab:: python :caption: Python :linenos: line1 = f2c.LineString(f2c.VectorPoint([f2c.Point(0.0, 0.0), f2c.Point(0.0, 1.0)])); swath1 = f2c.Swath(line1); line2 = f2c.LineString(f2c.VectorPoint([f2c.Point(1.0, 1.0), f2c.Point(1.0, 0.0)])); swath2 = f2c.Swath(line2); swaths_path = f2c.Swaths(); swaths_path.push_back(swath1); swaths_path.push_back(swath2); robot = f2c.Robot(2.0, 3.0); robot.setMinTurningRadius(0.5); complete_length = f2c.OBJ_CompleteTurnPathObj_Dubins(robot); print("The complete length is: ", complete_length.computeCost(swaths_path), " =~= ", 1 + 1 + math.pi/2.0); *The complete length is: 3.57166 =~= 3.5708* On line 7, we define the cost function with the class to compute the turns. In this case, ``f2c::pp::DubinsCurves``. Direct distance without turns ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Compute an approximation of the distance of the path, replacing turns by straight lines. This is faster than computing the turns and doesn't require to provide a class to compute the turns. .. tabs:: lang .. code-tab:: cpp :caption: C++ f2c::obj::DirectDistPathObj direct_dist; std::cout << "The aproximated length is: " << direct_dist.computeCost(swaths_path) << std::endl; .. code-tab:: python :caption: Python direct_dist = f2c.OBJ_DirectDistPathObj(); print("The aproximated length is: ", direct_dist.computeCost(swaths_path)); *The aproximated length is: 3* PP objective functions ---------------------- Path length ^^^^^^^^^^^ Compute the length of the path .. tabs:: lang .. code-tab:: cpp :caption: C++ F2CPath path; path.appendSwath(swaths_path.at(0), 1); path.appendSwath(swaths_path.at(1), 1); f2c::obj::PathLength path_length; std::cout << "The path length is: " << path_length.computeCost(path) << std::endl; .. code-tab:: python :caption: Python path = f2c.Path() path.appendSwath(swaths_path.at(0), 1); path.appendSwath(swaths_path.at(1), 1); path_length = f2c.OBJ_PathLength(); print("The path length is: ", path_length.computeCost(path)); *The path length is: 3*