field_coverage_test.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 #include <gtest/gtest.h>
8 #include <utility>
10 #include "fields2cover/types.h"
11 
12 TEST(fields2cover_obj_field_coverage, get_best_value) {
13  double width {2.0};
14 
15  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 1.0), F2CPoint(4.0, 1.0)}), width);
16  F2CSwath swath2(F2CLineString({F2CPoint(0.0, 3.0), F2CPoint(4.0, 3.0)}), width);
17  F2CSwath swath3(F2CLineString({F2CPoint(0.0, 2.0), F2CPoint(4.0, 2.0)}), width);
19 
20  F2CCell field;
21  F2CLinearRing line;
22  line.addPoint(0, 0);
23  line.addPoint(4, 0);
24  line.addPoint(4, 4);
25  line.addPoint(0, 4);
26  line.addPoint(0, 0);
27  field.addRing(line);
28  F2CCells fields{field};
29 
31  EXPECT_NEAR(obj.computeCost(field, swaths), 0.5, 1e-5);
32  EXPECT_NEAR(obj.computeCost(fields, swaths), 0.5, 1e-5);
33 
34  swaths.emplace_back(swath3);
35  EXPECT_NEAR(obj.computeCost(fields, swaths), 0.75, 1e-5);
36 
37  swaths.emplace_back(swath2);
38  EXPECT_NEAR(obj.computeCost(fields, swaths), 1.0, 1e-5);
39 }
40 
41 TEST(fields2cover_obj_field_coverage, computeCost_cost) {
42  double width {2.0};
43  F2CLineString path1, path2, path3;
44  path1.addPoint( 0.0, 1.0);
45  path1.addPoint( 4.0, 1.0);
46  path2.addPoint( 0.0, 3.0);
47  path2.addPoint( 4.0, 3.0);
48  path3.addPoint( 0.0, 2.0);
49  path3.addPoint( 4.0, 2.0);
50  F2CSwath swath1(path1, width);
51  F2CSwath swath2(path2, width);
52  F2CSwath swath3(path3, width);
53 
54  F2CSwaths swaths_full {swath1,swath2};
55  F2CSwaths swaths_overlap {swath1,swath3};
56  F2CSwaths swaths_half {swath1};
57 
58  F2CCells fields;
59  F2CCell field;
60 
61  F2CLinearRing line;
62  line.addPoint(0, 0);
63  line.addPoint(4, 0);
64  line.addPoint(4, 4);
65  line.addPoint(0, 4);
66  line.addPoint(0, 0);
67  field.addRing(line);
68  fields.addGeometry(field);
69 
70  f2c::obj::FieldCoverage coverage;
71 
72  EXPECT_EQ(coverage.computeCost(fields, swaths_full), 1.0);
73  EXPECT_EQ(coverage.computeCostWithMinimizingSign(fields, swaths_full), -1.0);
74 
75  EXPECT_EQ(coverage.computeCost(fields, swaths_overlap), 0.75);
76  EXPECT_EQ(coverage.computeCostWithMinimizingSign(fields, swaths_overlap), -0.75);
77 
78  EXPECT_EQ(coverage.computeCost(fields, swaths_half), 0.5);
79  EXPECT_EQ(coverage.computeCostWithMinimizingSign(fields, swaths_half), -0.5);
80 }
81 
82 TEST(fields2cover_obj_field_coverage, params_check) {
83  f2c::obj::FieldCoverage objective;
84  EXPECT_TRUE(objective.isMaximizing());
85  EXPECT_FALSE(objective.isMinimizing());
86  EXPECT_FALSE(objective.isFastCompAvailable());
87 }
88 
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
field_coverage.h
types.h
f2c::types::Cells::addGeometry
void addGeometry(const Cell &c)
Definition: Cells.cpp:126
f2c::types::Swath
Definition: Swath.h:23
f2c::obj::FieldCoverage::computeCost
double computeCost(const F2CCell &poly, const F2CSwaths &swaths) override
Compute the cost function.
Definition: field_coverage.cpp:11
f2c::types::LinearRing::addPoint
void addPoint(double x, double y, double z=0)
Definition: LinearRing.cpp:105
f2c::types::LinearRing
Definition: LinearRing.h:18
2_objective_functions.swath1
swath1
Definition: 2_objective_functions.py:30
f2c::types::Cell
Definition: Cell.h:32
7_decomposition.obj
obj
Definition: 7_decomposition.py:32
f2c::obj::BaseObjective::isMaximizing
virtual bool isMaximizing() const
Return true if the objective is to maximize the cost function.
Definition: base_objective.h:52
2_objective_functions.swath3
swath3
Definition: 2_objective_functions.py:34
f2c::obj::FieldCoverage
SG objective function as the percentage of the field covered.
Definition: field_coverage.h:20
2_objective_functions.width
float width
Definition: 2_objective_functions.py:29
f2c::types::LineString
Definition: LineString.h:19
f2c::types::Cells
Definition: Cells.h:21
F2CLineString
f2c::types::LineString F2CLineString
Definition: types.h:40
f2c::types::LineString::addPoint
void addPoint(double x, double y, double z=0)
Definition: LineString.cpp:107
f2c::obj::SGObjective::isFastCompAvailable
virtual bool isFastCompAvailable() const
Definition: sg_objective.h:23
2_objective_functions.field
field
Definition: 2_objective_functions.py:16
f2c::obj::FieldCoverage::isMinimizing
bool isMinimizing(void) const override
Return true if the objective is to minimize the cost function.
Definition: field_coverage.cpp:28
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
TEST
TEST(fields2cover_obj_field_coverage, get_best_value)
Definition: field_coverage_test.cpp:12
f2c::obj::BaseObjective::computeCostWithMinimizingSign
double computeCostWithMinimizingSign(const T1 &t1)
Compute the cost function with minimizing sign.
Definition: base_objective.h:26


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