Skip to content

Commit f7589de

Browse files
second chance loop for bidir
1 parent 3d40022 commit f7589de

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

src/route.cc

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace osr {
3030

3131
constexpr auto const kMaxMatchingDistanceSquaredRatio = 9.0;
3232

33-
#define trace(...)
33+
#define trace(...)
3434

3535
struct connecting_way {
3636
constexpr bool valid() const { return way_ != way_idx_t::invalid(); }
@@ -528,68 +528,73 @@ std::optional<path> route_bidirectional(ways const& w,
528528
b.distance_lon_degrees_) /
529529
kMaxMatchingDistanceSquaredRatio;
530530

531-
for (auto const [i, start] : utl::enumerate(from_match)) {
532-
if (b.max_reached_1_ && component_seen(w, from_match, i)) {
533-
continue;
534-
}
535-
auto const start_way = start.way_;
536-
for (auto const* nc : {&start.left_, &start.right_}) {
537-
if (nc->valid() && nc->cost_ < max) {
538-
Profile::resolve_start_node(
539-
*w.r_, start.way_, nc->node_, from.lvl_, dir, [&](auto const node) {
540-
auto label = typename Profile::label{node, nc->cost_};
541-
label.track(label, *w.r_, start_way, node.get_node(), false);
542-
b.add_start(w, label, sharing);
543-
});
544-
}
545-
}
546-
if (b.pq1_.empty()) {
547-
continue;
548-
}
549-
for (auto const [j, end] : utl::enumerate(to_match)) {
550-
if (w.r_->way_component_[start.way_] != w.r_->way_component_[end.way_]) {
551-
continue;
552-
}
553-
if (b.max_reached_2_ && component_seen(w, to_match, j)) {
531+
for (auto const accept_bad_max_matching_dist : {false, true}) {
532+
for (auto const [i, start] : utl::enumerate(from_match)) {
533+
if (b.max_reached_1_ && component_seen(w, from_match, i)) {
554534
continue;
555535
}
556-
if (std::pow(end.dist_to_way_, 2) > limit_squared_max_matching_distance) {
557-
break;
558-
}
559-
auto const end_way = end.way_;
560-
for (auto const* nc : {&end.left_, &end.right_}) {
536+
auto const start_way = start.way_;
537+
for (auto const* nc : {&start.left_, &start.right_}) {
561538
if (nc->valid() && nc->cost_ < max) {
562539
Profile::resolve_start_node(
563-
*w.r_, end_way, nc->node_, to.lvl_, opposite(dir),
540+
*w.r_, start.way_, nc->node_, from.lvl_, dir,
564541
[&](auto const node) {
565542
auto label = typename Profile::label{node, nc->cost_};
566-
label.track(label, *w.r_, end_way, node.get_node(), false);
567-
b.add_end(w, label, sharing);
543+
label.track(label, *w.r_, start_way, node.get_node(), false);
544+
b.add_start(w, label, sharing);
568545
});
569546
}
570547
}
571-
if (b.pq2_.empty()) {
548+
if (b.pq1_.empty()) {
572549
continue;
573550
}
574-
auto const should_continue =
575-
b.run(w, *w.r_, max, blocked, sharing, elevations, dir);
576-
577-
if (b.meet_point_1_.get_node() == node_idx_t::invalid()) {
578-
if (should_continue) {
551+
for (auto const [j, end] : utl::enumerate(to_match)) {
552+
if (w.r_->way_component_[start.way_] !=
553+
w.r_->way_component_[end.way_]) {
579554
continue;
580555
}
581-
return std::nullopt;
582-
}
556+
if (b.max_reached_2_ && component_seen(w, to_match, j)) {
557+
continue;
558+
}
559+
if (std::pow(end.dist_to_way_, 2) >
560+
limit_squared_max_matching_distance) {
561+
break;
562+
}
563+
auto const end_way = end.way_;
564+
for (auto const* nc : {&end.left_, &end.right_}) {
565+
if (nc->valid() && nc->cost_ < max) {
566+
Profile::resolve_start_node(
567+
*w.r_, end_way, nc->node_, to.lvl_, opposite(dir),
568+
[&](auto const node) {
569+
auto label = typename Profile::label{node, nc->cost_};
570+
label.track(label, *w.r_, end_way, node.get_node(), false);
571+
b.add_end(w, label, sharing);
572+
});
573+
}
574+
}
575+
if (b.pq2_.empty()) {
576+
continue;
577+
}
578+
auto const should_continue =
579+
b.run(w, *w.r_, max, blocked, sharing, elevations, dir);
583580

584-
auto const cost = b.get_cost_to_mp(b.meet_point_1_, b.meet_point_2_);
581+
if (b.meet_point_1_.get_node() == node_idx_t::invalid()) {
582+
if (should_continue) {
583+
continue;
584+
}
585+
return std::nullopt;
586+
}
587+
588+
auto const cost = b.get_cost_to_mp(b.meet_point_1_, b.meet_point_2_);
585589

586-
return reconstruct_bi(w, l, blocked, sharing, elevations, b, from, to,
587-
start, end, cost, dir);
590+
return reconstruct_bi(w, l, blocked, sharing, elevations, b, from, to,
591+
start, end, cost, dir);
592+
}
593+
b.pq1_.clear();
594+
b.pq2_.clear();
595+
b.cost2_.clear();
596+
b.max_reached_2_ = false;
588597
}
589-
b.pq1_.clear();
590-
b.pq2_.clear();
591-
b.cost2_.clear();
592-
b.max_reached_2_ = false;
593598
}
594599
return std::nullopt;
595600
}

0 commit comments

Comments
 (0)