boustrophedon_order_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 <random>
9 #include "fields2cover/types.h"
12 
13 TEST(fields2cover_route_boustrophedon, genSortedSwaths) {
14  const int n = 5;
16  for (int i = 1; i < n; ++i) {
17  swaths.emplace_back(F2CLineString({F2CPoint(i, 0), F2CPoint(i, 1)}), i, i);
18  }
19 
20  auto rng = std::default_random_engine {};
21  std::shuffle(swaths.begin(), swaths.end(), rng);
22 
23  f2c::rp::BoustrophedonOrder swath_sorter;
25 
26  swaths = swath_sorter.genSortedSwaths(swaths);
27  EXPECT_EQ(swaths.size(), n - 1);
28  EXPECT_EQ(swaths[0].startPoint().getY(), 0);
29  for (int i = 1; i < n; ++i) {
30  EXPECT_EQ(swaths[i - 1].getWidth(), i);
31  }
32  EXPECT_EQ(objective.computeCost(swaths), 2*(n-1)-1);
33  swaths = swath_sorter.genSortedSwaths(swaths, 1);
34  EXPECT_EQ(swaths[0].startPoint().getY(), 0);
35  EXPECT_EQ(swaths[0].getWidth(), n-1);
36  EXPECT_EQ(swaths[1].getWidth(), n-2);
37  EXPECT_EQ(swaths[2].getWidth(), n-3);
38  EXPECT_EQ(objective.computeCost(swaths), 2*(n-1)-1);
39  swaths = swath_sorter.genSortedSwaths(swaths, 2);
40  EXPECT_EQ(swaths[0].startPoint().getY(), 1);
41  EXPECT_EQ(swaths[0].getWidth(), 1);
42  EXPECT_EQ(swaths[1].getWidth(), 2);
43  EXPECT_EQ(swaths[2].getWidth(), 3);
44  EXPECT_EQ(objective.computeCost(swaths), 2*(n-1)-1);
45  swaths = swath_sorter.genSortedSwaths(swaths, 3);
46  EXPECT_EQ(swaths[0].startPoint().getY(), 1);
47  EXPECT_EQ(swaths[0].getWidth(), n-1);
48  EXPECT_EQ(swaths[1].getWidth(), n-2);
49  EXPECT_EQ(swaths[2].getWidth(), n-3);
50  EXPECT_EQ(objective.computeCost(swaths), 2*(n-1)-1);
51 }
52 
53 TEST(fields2cover_route_boustrophedon, genSortedSwaths_empty_swaths) {
55  f2c::rp::BoustrophedonOrder swath_sorter;
56  auto new_swaths = swath_sorter.genSortedSwaths(swaths);
57  EXPECT_EQ(swaths.size(), 0);
58  EXPECT_EQ(new_swaths.size(), 0);
59 }
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
types.h
TEST
TEST(fields2cover_route_boustrophedon, genSortedSwaths)
Definition: boustrophedon_order_test.cpp:13
f2c::obj::DirectDistPathObj
Path cost function as the straight distance between points in a route.
Definition: direct_dist_path_obj.h:17
f2c::rp::BoustrophedonOrder
Definition: boustrophedon_order.h:16
f2c::rp::SingleCellSwathsOrderBase::genSortedSwaths
virtual F2CSwaths genSortedSwaths(const F2CSwaths &swaths, uint32_t variant=0) const
Definition: single_cell_swaths_order_base.cpp:12
F2CLineString
f2c::types::LineString F2CLineString
Definition: types.h:40
boustrophedon_order.h
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


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