overlaps_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>
9 #include "fields2cover/types.h"
10 
11 TEST(fields2cover_obj_overlaps, computeCost_cost) {
12  F2CLineString path1, path2, path3;
13  double width {2.0};
14  path1.addPoint( 0.0, 1.0);
15  path1.addPoint( 4.0, 1.0);
16  path2.addPoint( 0.0, 3.0);
17  path2.addPoint( 4.0, 3.0);
18  path3.addPoint( 0.0, 2.0);
19  path3.addPoint( 4.0, 2.0);
20  F2CSwath swath1(path1, width);
21  F2CSwath swath2(path2, width);
22  F2CSwath swath3(path3, width);
23 
24  F2CSwaths swaths_no_overlap {swath1,swath2};
25  F2CSwaths swaths_overlap_025 {swath1,swath3};
26  F2CSwaths swaths_overlap_050_1 {swath1,swath2,swath3};
27  F2CSwaths swaths_overlap_050_2 {swath2,swath1,swath3};
28  F2CSwaths swaths_overlap_050_3 {swath2,swath2};
29 
30  F2CCell field;
31  F2CCells fields;
32 
33  F2CLinearRing line;
34  line.addPoint(0, 0);
35  line.addPoint(4, 0);
36  line.addPoint(4, 4);
37  line.addPoint(0, 4);
38  line.addPoint(0, 0);
39  field.addRing(line);
40  fields.addGeometry(field);
41 
42  f2c::obj::Overlaps overlap;
43 
44  EXPECT_EQ(overlap.computeCost(field, swaths_no_overlap), 0.0);
45  EXPECT_EQ(overlap.computeCost(fields, swaths_no_overlap), 0.0);
46  EXPECT_EQ(overlap.computeCostWithMinimizingSign(fields, swaths_no_overlap), 0.0);
47 
48  EXPECT_EQ(overlap.computeCost(fields, swaths_overlap_025), 0.25);
49  EXPECT_EQ(overlap.computeCostWithMinimizingSign(fields, swaths_overlap_025), 0.25);
50 
51  EXPECT_EQ(overlap.computeCost(fields, swaths_overlap_050_1), 0.5);
52  EXPECT_EQ(overlap.computeCostWithMinimizingSign(fields, swaths_overlap_050_1), 0.5);
53 
54  EXPECT_EQ(overlap.computeCost(fields, swaths_overlap_050_2), 0.5);
55  EXPECT_EQ(overlap.computeCostWithMinimizingSign(fields, swaths_overlap_050_2), 0.5);
56 
57  EXPECT_EQ(overlap.computeCost(fields, swaths_overlap_050_3), 0.5);
58  EXPECT_EQ(overlap.computeCostWithMinimizingSign(fields, swaths_overlap_050_3), 0.5);
59 }
60 
61 TEST(fields2cover_obj_overlaps, params_check) {
62  f2c::obj::Overlaps objective;
63 
64  EXPECT_FALSE(objective.isMaximizing());
65  EXPECT_TRUE(objective.isMinimizing());
66  EXPECT_FALSE(objective.isFastCompAvailable());
67 }
68 
f2c::obj::Overlaps::computeCost
double computeCost(const F2CCell &poly, const F2CSwaths &swaths) override
Compute the cost function.
Definition: overlaps.cpp:11
types.h
f2c::types::Cells::addGeometry
void addGeometry(const Cell &c)
Definition: Cells.cpp:126
f2c::types::Swath
Definition: Swath.h:23
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
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
2_objective_functions.width
float width
Definition: 2_objective_functions.py:29
f2c::types::LineString
Definition: LineString.h:19
overlaps.h
f2c::types::Cells
Definition: Cells.h:21
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::Overlaps
SG cost function as the percentage of the field overlapped.
Definition: overlaps.h:19
TEST
TEST(fields2cover_obj_overlaps, computeCost_cost)
Definition: overlaps_test.cpp:11
f2c::types::Swaths
Definition: Swaths.h:20
2_objective_functions.swath2
swath2
Definition: 2_objective_functions.py:32
f2c::obj::BaseObjective::computeCostWithMinimizingSign
double computeCostWithMinimizingSign(const T1 &t1)
Compute the cost function with minimizing sign.
Definition: base_objective.h:26
f2c::obj::BaseObjective::isMinimizing
virtual bool isMinimizing() const
Return true if the objective is to minimize the cost function.
Definition: base_objective.h:50


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