direct_dist_path_obj_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 "fields2cover/types.h"
10 
11 TEST(fields2cover_obj_direct_dist_path_obj, computeCost_cost) {
12  F2CSwath swath1(F2CLineString({F2CPoint(0.0, 1.0), F2CPoint(4.0, 1.0)}));
13  F2CSwath swath2(F2CLineString({F2CPoint(4.0, 3.0), F2CPoint(0.0, 3.0)}));
14  F2CSwath swath3(F2CLineString({F2CPoint(0.0, 0.0), F2CPoint(1.0, 1.0)}));
15 
16  auto createRoute = [](const F2CSwaths& s) {
18  route.addConnection();
19  route.addSwaths(s);
20  route.addConnection();
21  return route;
22  };
23 
25  F2CSwaths swaths2 {swath2};
27 
28  auto r1 = createRoute(swaths1);
29  auto r2 = createRoute(swaths2);
30  auto r4 = createRoute(swaths4);
31 
33 
34  F2CPoint p1(0,0), p2(4,0);
35 
36  EXPECT_EQ(length.computeCost(p1, p2), 4.0);
37 
38  std::vector<F2CPoint> ps1 {p1, p2};
39  F2CMultiPoint ps2;
40  ps2.addGeometry(p1);
41  ps2.addGeometry(p2);
42 
43  EXPECT_EQ(length.computeCost(ps1), 4.0);
44  EXPECT_EQ(length.computeCost(ps2), 4.0);
45  EXPECT_EQ(length.computeCost(p1, p2, 0.0), 4.0);
46  EXPECT_EQ(length.computeCost(p1, 0.0, p2), 4.0);
47  EXPECT_EQ(length.computeCost(p1, 0.0, p2, 0.0), 4.0);
48  EXPECT_EQ(length.computeCost(p1, swath2), 5.0);
49  EXPECT_EQ(length.computeCost(swath2, p1), 3.0);
50  EXPECT_EQ(length.computeCost(p1, 0.0, swath2), 5.0);
51  EXPECT_EQ(length.computeCost(swath2, p1, 0.0), 3.0);
52 
53  EXPECT_EQ(length.computeCost(swath2, ps2), 3.0);
54  EXPECT_EQ(length.computeCost(swaths2, ps2), 3.0);
55  EXPECT_EQ(length.computeCost(ps2, swath2), 3.0);
56  EXPECT_EQ(length.computeCost(ps2, swaths2), 3.0);
57 
58  EXPECT_EQ(length.computeCost(swath2), 4.0);
59  EXPECT_EQ(length.computeCost(swaths4), 22.0);
60 
61  EXPECT_EQ(length.computeCost(F2CMultiPoint(), swath2), 0.0);
62  EXPECT_EQ(length.computeCost(swath2, F2CMultiPoint()), 0.0);
63 
64  EXPECT_EQ(length.computeCost(r1), 4.0);
65  EXPECT_EQ(length.computeCostWithMinimizingSign(r1), length.computeCost(r1));
66  EXPECT_EQ(length.computeCost(r2), 4.0);
67  EXPECT_EQ(length.computeCostWithMinimizingSign(r2), length.computeCost(r2));
68  EXPECT_EQ(length.computeCost(r4), 22.0);
69  EXPECT_EQ(length.computeCostWithMinimizingSign(r4), length.computeCost(r4));
70 }
71 
72 TEST(fields2cover_obj_direct_dist_path_obj, params_check) {
74 
75  EXPECT_FALSE(objective.isMaximizing());
76  EXPECT_TRUE(objective.isMinimizing());
77 }
78 
1_basic_types.p1
p1
Definition: 1_basic_types.py:11
types.h
f2c::obj::DirectDistPathObj
Path cost function as the straight distance between points in a route.
Definition: direct_dist_path_obj.h:17
f2c::types::Swath
Definition: Swath.h:23
2_objective_functions.swaths1
swaths1
Definition: 2_objective_functions.py:37
5_route_planning.route
route
Definition: 5_route_planning.py:29
2_objective_functions.swath1
swath1
Definition: 2_objective_functions.py:30
1_basic_types.p2
p2
Definition: 1_basic_types.py:15
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::types::MultiPoint::addGeometry
void addGeometry(const Point &p)
Definition: MultiPoint.cpp:83
TEST
TEST(fields2cover_obj_direct_dist_path_obj, computeCost_cost)
Definition: direct_dist_path_obj_test.cpp:11
f2c::types::MultiPoint
Definition: MultiPoint.h:18
F2CLineString
f2c::types::LineString F2CLineString
Definition: types.h:40
f2c::types::Route
Definition: Route.h:23
f2c::types::Point
Definition: Point.h:21
direct_dist_path_obj.h
f2c::obj::DirectDistPathObj::computeCost
double computeCost(const F2CPoint &p1, const F2CPoint &p2) override
Definition: direct_dist_path_obj.cpp:11
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::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