rp_objective.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 
8 
9 namespace f2c::obj {
10 
12  const F2CPoint& p1, const F2CPoint& p2) {
13  return p1.distance(p2);
14 }
15 
17  const F2CPoint& p1, double ang1, const F2CPoint& p2) {
18  return computeCost(p1, p2);
19 }
20 
21 
23  const F2CPoint& p1, const F2CPoint& p2, double ang2) {
24  return computeCost(p1, p2);
25 }
26 
28  const F2CPoint& p1, double ang1, const F2CPoint& p2, double ang2) {
29  return computeCost(p1, p2);
30 }
31 
32 double RPObjective::computeCost(const F2CSwath& s, const F2CPoint& p) {
33  return computeCost(s.endPoint(), s.getOutAngle(), p);
34 }
35 
36 double RPObjective::computeCost(const F2CSwath& s1, const F2CSwath& s2) {
37  return this->computeCost(
38  s1.endPoint(), s1.getOutAngle(), s2.startPoint(), s2.getInAngle());
39 }
40 
42  const F2CSwath& s, const F2CPoint& p, double ang) {
43  return computeCost(s.endPoint(), s.getOutAngle(), p, ang);
44 }
45 
46 double RPObjective::computeCost(const F2CPoint& p, const F2CSwath& s) {
47  return computeCost(p, s.startPoint(), s.getInAngle());
48 }
49 
51  const F2CPoint& p, double ang, const F2CSwath& s) {
52  return computeCost(p, ang, s.startPoint(), s.getInAngle());
53 }
54 
55 double RPObjective::computeCost(const std::vector<F2CPoint>& ps) {
56  auto dist {0.0};
57  for (size_t i = 1; i < ps.size(); ++i) {
58  dist += computeCost(ps[i-1], ps[i]);
59  }
60  return dist;
61 }
62 
64  if (ps.isEmpty()) {
65  return 0.0;
66  }
67  auto dist {0.0};
68  for (size_t i = 1; i < ps.size(); ++i) {
69  dist += computeCost(ps.getGeometry(i-1), ps.getGeometry(i));
70  }
71  return dist;
72 }
73 
75  if (ps.isEmpty()) {
76  return 0.0;
77  }
78  return computeCost(s.endPoint(), s.getOutAngle(), ps.getGeometry(0));
79 }
80 
82  if (ps.isEmpty()) {
83  return 0.0;
84  }
85  return computeCost(s.back(), ps);
86 }
87 
89  if (ps->IsEmpty()) {
90  return 0.0;
91  }
92  return computeCost(ps.getGeometry(ps.size()-1),
93  s.startPoint(), s.getInAngle());
94 }
95 
97  return computeCost(ps, s[0]);
98 }
99 
101  double dist {0.0};
102  for (size_t i = 1; i < s.numPoints(); ++i) {
103  dist += computeCost(s.getPoint(i-1), s.getPoint(i));
104  }
105  return dist;
106 }
107 
109  double dist {0.0};
110  for (auto&& s : swaths) {
111  dist += computeCost(s);
112  }
113  for (size_t i = 1; i < swaths.size(); ++i) {
114  dist += computeCost(swaths[i-1].endPoint(), swaths[i-1].getOutAngle(),
115  swaths[i].startPoint(), swaths[i].getInAngle());
116  }
117  return dist;
118 }
119 
121  double dist {0.0};
122  for (auto&& s : r.getVectorSwaths()) {
123  dist += computeCost(s);
124  }
125  for (auto&& s : r.getConnections()) {
126  dist += computeCost(s);
127  }
128  for (size_t i = 0; i < r.sizeVectorSwaths(); ++i) {
129  dist += computeCost(r.getConnection(i), r.getSwaths(i));
130  if (i + 1 < r.sizeConnections()) {
131  dist += computeCost(r.getSwaths(i), r.getConnection(i + 1));
132  }
133  }
134  return dist;
135 }
136 
137 } // namespace f2c::obj
138 
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
f2c::types::Swath::numPoints
size_t numPoints() const
Definition: Swath.cpp:139
1_basic_types.p1
p1
Definition: 1_basic_types.py:11
f2c::types::Route::getConnections
const std::vector< MultiPoint > & getConnections() const
Definition: Route.cpp:107
f2c::types::Swath::getInAngle
double getInAngle() const
Definition: Swath.cpp:77
f2c::types::Route::getSwaths
Swaths & getSwaths(size_t i)
Definition: Route.cpp:15
f2c::types::Swath
Definition: Swath.h:23
f2c::obj
Objective algorithms' namespace.
Definition: base_objective.h:14
1_basic_types.p2
p2
Definition: 1_basic_types.py:15
f2c::types::Route::sizeVectorSwaths
size_t sizeVectorSwaths() const
Definition: Route.cpp:142
f2c::types::Route::getVectorSwaths
const std::vector< Swaths > & getVectorSwaths() const
Definition: Route.cpp:11
f2c::types::Swath::endPoint
Point endPoint() const
Definition: Swath.cpp:99
f2c::types::MultiPoint
Definition: MultiPoint.h:18
8_complete_flow.ps
list ps
Definition: 8_complete_flow.py:43
f2c::types::Swath::getPoint
Point getPoint(int i)
Definition: Swath.cpp:143
f2c::types::Swath::startPoint
Point startPoint() const
Definition: Swath.cpp:92
f2c::types::Swaths::back
Swath & back()
Definition: Swaths.cpp:62
f2c::types::Route::sizeConnections
size_t sizeConnections() const
Definition: Route.cpp:146
f2c::types::Route
Definition: Route.h:23
f2c::types::Point
Definition: Point.h:21
f2c::types::Route::getConnection
MultiPoint & getConnection(size_t i)
Definition: Route.cpp:111
rp_objective.h
f2c::obj::RPObjective::computeCost
virtual double computeCost(const F2CPoint &p1, const F2CPoint &p2)
Definition: rp_objective.cpp:11
f2c::types::Swath::getOutAngle
double getOutAngle() const
Definition: Swath.cpp:84
f2c::types::Swaths
Definition: Swaths.h:20


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