swath_length_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_swath_length, computeCost_cost) {
12  F2CLineString path1, path2, path3;
13  path1.addPoint( 0.0, 1.0);
14  path1.addPoint( 4.0, 1.0);
15  path2.addPoint( 0.0, 3.0);
16  path2.addPoint( 4.0, 3.0);
17  path3.addPoint( 0.0, 0.0);
18  path3.addPoint( 1.0, 1.0);
19  F2CSwath swath1(path1);
20  F2CSwath swath2(path2);
21  F2CSwath swath3(path3);
22 
24  F2CSwaths swaths2 {swath3};
27 
28  f2c::obj::SwathLength length;
29 
30 
31  EXPECT_EQ(length.computeCost(swath1), 4.0);
32 
33  EXPECT_EQ(length.computeCost(swaths1), 4.0);
34  EXPECT_EQ(length.computeCostWithMinimizingSign(swaths1), length.computeCost(swaths1));
35 
36  EXPECT_NEAR(length.computeCost(swaths2)*length.computeCost(swaths2), 2.0, 0.001);
37  EXPECT_EQ(length.computeCostWithMinimizingSign(swaths2), length.computeCost(swaths2));
38 
39  EXPECT_EQ(length.computeCost(swaths3), 8.0);
40  EXPECT_EQ(length.computeCostWithMinimizingSign(swaths3), length.computeCost(swaths3));
41 
42  EXPECT_EQ(length.computeCost(swaths4), 16.0);
43  EXPECT_EQ(length.computeCostWithMinimizingSign(swaths4), length.computeCost(swaths4));
44 }
45 
46 TEST(fields2cover_obj_swath_length, params_check) {
47  f2c::obj::SwathLength objective;
48 
49  EXPECT_FALSE(objective.isMaximizing());
50  EXPECT_TRUE(objective.isMinimizing());
51  EXPECT_FALSE(objective.isFastCompAvailable());
52 }
53 
f2c::obj::SwathLength
Global cost function as the length of the swaths.
Definition: swath_length.h:18
f2c::obj::SwathLength::computeCost
double computeCost(const F2CSwath &s) override
Compute the cost function.
Definition: swath_length.cpp:11
swath_length.h
types.h
f2c::types::Swath
Definition: Swath.h:23
2_objective_functions.swaths1
swaths1
Definition: 2_objective_functions.py:37
2_objective_functions.swath1
swath1
Definition: 2_objective_functions.py:30
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::LineString
Definition: LineString.h:19
f2c::types::LineString::addPoint
void addPoint(double x, double y, double z=0)
Definition: LineString.cpp:107
TEST
TEST(fields2cover_obj_swath_length, computeCost_cost)
Definition: swath_length_test.cpp:11
f2c::obj::SGObjective::isFastCompAvailable
virtual bool isFastCompAvailable() const
Definition: sg_objective.h:23
2_objective_functions.swaths3
swaths3
Definition: 2_objective_functions.py:39
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