2_objective_functions.cpp
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 
8 #include "fields2cover.h"
9 #include <iostream>
10 
11 int main() {
12  std::cout << "####### Tutorial 2.1.1 Remaining Area ######" << std::endl;
14  {F2CPoint(-2,-2), F2CPoint(6,-2), F2CPoint(6,6), F2CPoint(-2,6), F2CPoint(-2,-2)})));
16  {F2CPoint(0,0), F2CPoint(4,0), F2CPoint(4,4), F2CPoint(0,4), F2CPoint(0,0)})));
17 
18 
20  std::cout << "The remaining area is "
21  << rem_area.computeCost(total_field, field) << std::endl;
22  std::cout << "The remaining area with sign is "
23  << rem_area.computeCostWithMinimizingSign(total_field, field) <<std::endl;
24  std::cout << std::endl << std::endl;
25 
26  std::cout << "####### Tutorial 2.2.1 Field Coverage ######" << std::endl;
27  double width {2.0};
28  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 1.0), F2CPoint(4.0, 1.0)}), width);
29  F2CSwath swath2(F2CLineString({F2CPoint(0.0, 3.0), F2CPoint(4.0, 3.0)}), width);
30  F2CSwath swath3(F2CLineString({F2CPoint(0.0, 2.0), F2CPoint(4.0, 2.0)}), width);
31 
32 
34  std::cout << "The field coverage with swath1 is "
35  << field_cov.computeCost(field, F2CSwaths({swath1})) << " and with all of the swaths "
36  << field_cov.computeCost(field, F2CSwaths({swath1, swath2, swath3})) << std::endl;
37  std::cout << "The field coverage with sign for all of the swaths is "
38  << field_cov.computeCostWithMinimizingSign(
39  field, F2CSwaths({swath1, swath2, swath3})) <<std::endl;
40 
41  std::cout << std::endl;
42  std::cout << "####### Tutorial 2.2.2 Number of swaths ######" << std::endl;
44  std::cout << "The number of swaths with swath1 is "
45  << n_swaths.computeCost(F2CSwaths({swath1})) << " and with all of the swaths "
46  << n_swaths.computeCost(field, F2CSwaths({swath1, swath2, swath3})) <<std::endl;
47 
48  f2c::obj::NSwathModified n_swaths_mod;
49  std::cout << "The number of swaths with swath1 is "
50  << n_swaths_mod.computeCost(F2CSwaths({swath1})) << " and with all of the swaths "
51  << n_swaths_mod.computeCost(field, F2CSwaths({swath1, swath2, swath3})) <<std::endl;
52 
53 
54  std::cout << std::endl;
55  std::cout << "####### Tutorial 2.2.3 Overlap ######" << std::endl;
57  std::cout << "The field overlapping with swath1 is "
58  << overlaps.computeCost(field, F2CSwaths({swath1})) << " and with all of the swaths "
59  << overlaps.computeCost(field, F2CSwaths({swath1, swath2, swath3})) << std::endl;
60 
61  std::cout << std::endl;
62  std::cout << "####### Tutorial 2.2.4 Swath length ######" << std::endl;
64  std::cout << "The swath length with swath1 is "
65  << swath_length.computeCost(field, F2CSwaths({swath1})) << " and with all of the swaths "
66  << swath_length.computeCost(field, F2CSwaths({swath1, swath2, swath3})) << std::endl;
67 
68  std::cout << std::endl << std::endl;
69  std::cout << "####### Tutorial 2.3.1 Distance with turns ######" << std::endl;
71  F2CSwath(F2CLineString({F2CPoint(0.0, 0.0), F2CPoint(0.0, 1.0)})),
72  F2CSwath(F2CLineString({F2CPoint(1.0, 1.0), F2CPoint(1.0, 0.0)}))});
73  F2CRobot robot(2.0, 3.0);
74  robot.setMinTurningRadius(0.5);
76  std::cout << "The complete length is: " <<
77  complete_length.computeCost(swaths_path) <<
78  " =~= " << 1 + 1 + M_PI/2.0 << std::endl;
79 
80  std::cout << std::endl;
81  std::cout << "####### Tutorial 2.3.2 Direct distance without turns ######" << std::endl;
83  std::cout << "The aproximated length is: " <<
84  direct_dist.computeCost(swaths_path) << std::endl;
85 
86  std::cout << std::endl << std::endl;
87  std::cout << "####### Tutorial 2.4.1 Path length ######" << std::endl;
88  F2CPath path;
89  path.appendSwath(swaths_path.at(0), 1);
90  path.appendSwath(swaths_path.at(1), 1);
91 
93  std::cout << "The path length is: " <<
94  path_length.computeCost(path) << std::endl;
95 
96 
97  return 0;
98 }
99 
f2c::obj::SwathLength
Global cost function as the length of the swaths.
Definition: swath_length.h:18
2_objective_functions.n_swaths
n_swaths
Definition: 2_objective_functions.py:50
2_objective_functions.path_length
path_length
Definition: 2_objective_functions.py:92
f2c::obj::NSwath
SG cost function as the number of swaths.
Definition: n_swath.h:20
2_objective_functions.path
path
Definition: 2_objective_functions.py:88
2_objective_functions.field_cov
field_cov
Definition: 2_objective_functions.py:42
2_objective_functions.rem_area
rem_area
Definition: 2_objective_functions.py:20
F2CCell
f2c::types::Cell F2CCell
Definition: types.h:43
f2c::obj::DirectDistPathObj
Path cost function as the straight distance between points in a route.
Definition: direct_dist_path_obj.h:17
2_objective_functions.direct_dist
direct_dist
Definition: 2_objective_functions.py:83
f2c::types::Swath
Definition: Swath.h:23
f2c::obj::RemArea
Compute the area of the mainland (field - headlands).
Definition: rem_area.h:17
2_objective_functions.robot
robot
Definition: 2_objective_functions.py:76
fields2cover.h
2_objective_functions.complete_length
complete_length
Definition: 2_objective_functions.py:78
2_objective_functions.swath1
swath1
Definition: 2_objective_functions.py:30
2_objective_functions.swath3
swath3
Definition: 2_objective_functions.py:34
2_objective_functions.overlaps
overlaps
Definition: 2_objective_functions.py:56
f2c::obj::FieldCoverage
SG objective function as the percentage of the field covered.
Definition: field_coverage.h:20
f2c::types::Path
Definition: Path.h:23
2_objective_functions.width
float width
Definition: 2_objective_functions.py:29
F2CLinearRing
f2c::types::LinearRing F2CLinearRing
Definition: types.h:41
f2c::obj::PathLength
Compute the length of the coverage path, including turns.
Definition: path_length.h:16
f2c::types::Cells
Definition: Cells.h:21
F2CSwaths
f2c::types::Swaths F2CSwaths
Definition: types.h:51
F2CLineString
f2c::types::LineString F2CLineString
Definition: types.h:40
f2c::obj::CompleteTurnPathObj
Class to compute the cost of turning from one point to another.
Definition: complete_turn_path_obj.h:26
f2c::types::Robot
Definition: Robot.h:25
2_objective_functions.swath_length
swath_length
Definition: 2_objective_functions.py:62
2_objective_functions.field
field
Definition: 2_objective_functions.py:16
2_objective_functions.total_field
total_field
Definition: 2_objective_functions.py:13
main
int main()
Definition: 2_objective_functions.cpp:11
F2CSwath
f2c::types::Swath F2CSwath
Definition: types.h:50
f2c::obj::NSwathModified::computeCost
double computeCost(double ang, double op_width, const F2CCell &cell) override
Compute the cost function.
Definition: n_swath_modified.cpp:11
f2c::obj::Overlaps
SG cost function as the percentage of the field overlapped.
Definition: overlaps.h:19
f2c::types::Swaths
Definition: Swaths.h:20
F2CPoint
f2c::types::Point F2CPoint
Definition: types.h:38
2_objective_functions.swath2
swath2
Definition: 2_objective_functions.py:32
f2c::obj::NSwathModified
SG cost function as the number of swaths .
Definition: n_swath_modified.h:20
2_objective_functions.swaths_path
swaths_path
Definition: 2_objective_functions.py:73


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31