n_swath_modified_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_n_swath_mod, computeCost_cost) {
12  f2c::obj::NSwathModified objective;
13  F2CCell cell;
14 
15  F2CLinearRing ext_ring;
16  ext_ring.addPoint(0, 0);
17  ext_ring.addPoint(4, 0);
18  ext_ring.addPoint(4, 5);
19  ext_ring.addPoint(0, 4);
20  ext_ring.addPoint(0, 0);
21 
22  F2CLinearRing int_ring1;
23  int_ring1.addPoint(0.1, 0.1);
24  int_ring1.addPoint(0.1, 3.0);
25  int_ring1.addPoint(0.2, 3.6);
26  int_ring1.addPoint(0.2, 0.1);
27  int_ring1.addPoint(0.1, 0.1);
28 
29  F2CLinearRing int_ring2;
30  int_ring2.addPoint(2.1, 0.1);
31  int_ring2.addPoint(2.1, 3.0);
32  int_ring2.addPoint(2.2, 3.6);
33  int_ring2.addPoint(2.2, 0.1);
34  int_ring2.addPoint(2.1, 0.1);
35 
36  EXPECT_EQ(objective.computeCost(cell), 0.0);
37  cell.addRing(ext_ring);
38  EXPECT_NEAR(objective.computeCost(cell), 0.0, 1e-7);
39  EXPECT_NEAR(objective.computeCost(0.0, 0.1, cell), 50.0, 1e-7);
40  EXPECT_NEAR(objective.computeCost(M_PI * 0.5, 0.1, cell), 40.0, 1e-7);
41  EXPECT_NEAR(objective.computeCost(M_PI, 0.1, cell), 50.0, 1e-7);
42  cell.addRing(int_ring1);
43  EXPECT_NEAR(objective.computeCost(0.0, 0.1, cell), 85.0, 1e-7);
44  EXPECT_NEAR(objective.computeCost(M_PI * 0.5, 0.1, cell), 41.0, 1e-7);
45  EXPECT_NEAR(objective.computeCost(M_PI, 0.1, cell), 85.0, 1e-7);
46  cell.addRing(int_ring2);
47  EXPECT_NEAR(objective.computeCost(0.0, 0.1, cell), 120.0, 1e-7);
48  EXPECT_NEAR(objective.computeCost(M_PI * 0.5, 0.1, cell), 42.0, 1e-7);
49  EXPECT_NEAR(objective.computeCostWithMinimizingSign(M_PI, 0.1, cell), 120.0, 1e-7);
50 }
51 
52 TEST(fields2cover_obj_n_swath_mod, params_check) {
53  f2c::obj::NSwathModified objective;
54 
55  EXPECT_FALSE(objective.isMaximizing());
56  EXPECT_TRUE(objective.isMinimizing());
57  EXPECT_TRUE(objective.isFastCompAvailable());
58 }
59 
n_swath_modified.h
types.h
f2c::obj::NSwathModified::isFastCompAvailable
bool isFastCompAvailable() const override
Definition: n_swath_modified.h:23
1_basic_types.cell
cell
Definition: 1_basic_types.py:88
f2c::types::LinearRing::addPoint
void addPoint(double x, double y, double z=0)
Definition: LinearRing.cpp:105
f2c::types::LinearRing
Definition: LinearRing.h:18
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
TEST
TEST(fields2cover_obj_n_swath_mod, computeCost_cost)
Definition: n_swath_modified_test.cpp:11
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::NSwathModified
SG cost function as the number of swaths .
Definition: n_swath_modified.h:20
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