59 std::vector<Point_on_edge_t>
64 std::vector<pgr_edge_t>
72 std::vector<Point_on_edge_t> p_points,
73 std::vector<pgr_edge_t> p_edges_of_points,
79 m_edges_of_points(p_edges_of_points),
80 m_driving_side(p_driving_side),
81 m_directed(p_directed) {
96 if (point.side ==
'r') {
98 }
else if (point.side ==
'l') {
101 point.fraction = 1 - point.fraction;
113 log <<
"original points" << *
this;
120 if (a.pid != b.pid) return a.pid < b.pid;
121 if (a.edge_id != b.edge_id) return a.edge_id < b.edge_id;
122 if (a.fraction != b.fraction) return a.fraction < b.fraction;
123 return a.side < b.side;
125 log <<
"after sorting" << *
this;
128 return a.pid == b.pid &&
129 a.edge_id == b.edge_id &&
130 a.fraction == b.fraction &&
134 size_t total_points =
m_points.size();
136 log <<
"after deleting repetitions" << *
this;
137 log <<
"We have " << total_points <<
" different points";
141 return a.pid == b.pid;
144 log <<
"after deleting points with same id" << *
this;
146 if (
m_points.size() != total_points) {
147 error <<
"Unexpected point(s) with same pid"
148 <<
" but different edge/fraction/side combination found.";
155 auto point_ptr = std::find_if(
158 {return pid == -point.pid;});
159 return point_ptr !=
m_points.end() ?
166 auto e_itr = std::find_if(
169 {return eid == edge.id;});
181 if (path.
empty())
return;
188 for (
auto pathstop : path) {
193 if (!((pathstop.node == path.start_id())
194 || (pathstop.node > 0))) {
203 if (pathstop.node != path.start_id()) {
210 && edge_ptr->id != edge_id) {
211 pathstop.cost = pathstop.node == edge_ptr->source?
213 edge_ptr->reverse_cost;
234 if (path.
empty())
return path;
238 for (
const auto &pathstop : path) {
239 if ((pathstop.node == path.start_id())
240 || (pathstop.node == path.end_id())
241 || (pathstop.node > 0)) {
243 if (pathstop.node != path.end_id()) cost = 0.0;
246 cost += pathstop.cost;
249 newPath[0].cost = newPath[1].agg_cost;
250 for (
unsigned int i = 1; i < newPath.
size() - 2; ++i) {
256 int64_t edge_to_find = newPath[i].edge;
257 auto edge_ptr = std::find_if(
260 {return edge_to_find == edge.id;});
262 newPath[i].cost = edge_ptr->target == newPath[i+1].node ?
263 edge_ptr->cost : edge_ptr->reverse_cost;
266 newPath[newPath.
size()-2].cost += cost;
274 const std::vector< Point_on_edge_t > &points,
275 const int64_t &start_pid,
276 const int64_t &end_pid,
278 if (path.
empty())
return;
282 for (
auto &path_stop : path) {
283 for (
const auto point :
points) {
284 if (point.vertex_id == path_stop.node) {
285 path_stop.node = -point.pid;
294 const std::vector< Point_on_edge_t > &points,
299 if (path.
empty())
return;
303 int64_t start_vid = path.
start_id();
304 int64_t end_vid = path.
end_id();
306 int64_t start_pid = 0;
310 if (p.vertex_id == start_vid) {
313 if (p.vertex_id == end_vid) {
322 std::vector<pgr_edge_t>
329 for (
const auto &point :
m_points) {
332 << point.edge_id <<
"\t"
333 << point.fraction <<
"\t"
334 << point.side <<
"\t"
335 << point.vertex_id <<
"\n";
338 int64_t vertex_id = 1;
339 std::vector< Point_on_edge_t > new_points;
341 std::set< Point_on_edge_t, pointCompare> points_on_edge;
343 if (
edge.
id == point.edge_id) {
344 points_on_edge.insert(point);
345 log <<
"working points: "
347 << point.edge_id <<
"\t"
348 << point.fraction <<
"\t"
349 << point.side <<
"\t"
350 << point.vertex_id <<
"\n";
353 if (points_on_edge.empty()) {
354 error <<
"For some reason didn't find a point belonging to the edge"
355 <<
", must be an error\n";
359 log <<
"breaking: \n"
368 double prev_fraction = 0;
369 double prev_rfraction = 0;
371 double agg_rcost = 0;
372 double last_cost = 0;
373 double last_rcost = 0;
374 std::vector<Point_on_edge_t> the_points(
375 points_on_edge.begin(), points_on_edge.end());
377 for (
auto &point : the_points) {
385 <<
"\teid" << point.edge_id
386 <<
"/t" << point.fraction
387 <<
"\t" << point.side <<
"\n";
388 if (point.fraction < 0 || point.fraction > 1) {
389 error <<
"For some reason an invalid fraction was accepted,"
390 <<
" must be an error\n";
393 if (point.fraction == 0) {
397 if (point.fraction == 1) {
401 if (point.fraction > 0 && point.fraction < 1) {
402 log <<
"vertex_id of the point is " << -point.pid <<
"\n";
403 point.vertex_id = -point.pid;
406 new_points.push_back(point);
408 double deltaFraction = point.fraction - prev_fraction;
409 double deltarFraction = point.fraction - prev_rfraction;
412 || point.side ==
'b') {
413 log <<
"Edge is one way "
414 <<
" or driving side is both or point side is both\n";
415 log <<
"Edge is one way: "
419 log <<
"point side: " << point.side <<
"\n";
420 if (point.fraction > 0 && point.fraction < 1) {
422 last_cost = deltaFraction *
edge.
cost;
431 <<
"id, source, target, cost, reverse_cost) = ("
432 << new_edge.
id <<
"\t"
433 << new_edge.
source <<
"\t"
434 << new_edge.
target <<
"\t"
435 << new_edge.
cost <<
"\t"
448 <<
"id, source, target, cost, reverse_cost) = ("
449 << new_edge.
id <<
"\t"
450 << new_edge.
source <<
"\t"
451 << new_edge.
target <<
"\t"
452 << new_edge.
cost <<
"\t"
456 prev_target = point.vertex_id;
457 prev_fraction = point.fraction;
458 agg_cost += last_cost;
460 prev_rtarget = point.vertex_id;
461 prev_rfraction = point.fraction;
462 agg_rcost += last_rcost;
470 log <<
"two way and driving side == the side of the point\n";
471 log <<
"Breaking (source, target) when its not the extreme\n";
472 if (point.fraction > 0 && point.fraction < 1) {
473 last_cost = deltaFraction *
edge.
cost;
475 edge.
id, prev_target, point.vertex_id, last_cost, -1};
478 <<
"id, source, target, cost, reverse_cost) = ("
479 << new_edge.
id <<
"\t"
480 << new_edge.
source <<
"\t"
481 << new_edge.
target <<
"\t"
482 << new_edge.
cost <<
"\t"
485 prev_target = point.vertex_id;
486 prev_fraction = point.fraction;
487 agg_cost += last_cost;
491 log <<
"\ntwo way and driving side != the side of the point";
492 if (point.fraction > 0 && point.fraction < 1) {
501 log <<
"\nnew_edge(id, source, target, cost, reverse_cost) = ("
502 << new_edge.
id <<
"\t"
503 << new_edge.
source <<
"\t"
504 << new_edge.
target <<
"\t"
505 << new_edge.
cost <<
"\t"
508 prev_rtarget = point.vertex_id;
509 prev_rfraction = point.fraction;
510 agg_rcost += last_rcost;
521 log <<
"last edge: (id, source, target, cost, reverse_cost) = ("
522 << new_edge.
id <<
"\t"
523 << new_edge.
source <<
"\t"
524 << new_edge.
target <<
"\t"
525 << new_edge.
cost <<
"\t"
531 log <<
"last edge: (id, source, target, cost, reverse_cost) = ("
532 << new_edge.
id <<
"\t"
533 << new_edge.
source <<
"\t"
534 << new_edge.
target <<
"\t"
535 << new_edge.
cost <<
"\t"
541 for (
const auto &point :
m_points) {
544 << point.edge_id <<
"\t"
545 << point.fraction <<
"\t"
546 << point.side <<
"\t"
547 << point.vertex_id <<
"\n";