Skip to content

Commit

Permalink
Updated "join" algorithm in BiDirectional
Browse files Browse the repository at this point in the history
 - Added stopping criteria for backward label comparisons.
 - Added filtering for forward labels using halway point.
 - Tested with maps instead of for-loops. Is a bit slower.
  • Loading branch information
torressa committed Mar 26, 2020
1 parent 9228be7 commit 818d42c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cspy/algorithms/bidirectional.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,23 +411,29 @@ def _process_bwd_label(self, label):

def _join_paths(self):
"""
Path joining algorithm from `Righini and Salani (2006)`_.
The procedure "Join" or Algorithm 3 from `Righini and Salani (2006)`_.
:return: list with the final path.
.. _Righini and Salani (2006): https://www.sciencedirect.com/science/article/pii/S1572528606000417
"""
halfway = (self.max_res[0] - self.min_res[0]) / 2
# Parameter required for the Half-way procedure
difference = 1 # difference in the monotone resource of any pair of labels
for i in self.G.nodes():
for fwd_label in (l for l in self.processed_labels["forward"]
if l.node == i and l.res[0] <= self.max_res[0]):
if l.node == i and l.res[0] > halfway):
for j in self.G.nodes():
for bwd_label in (
l for l in self.processed_labels["backward"]
if l.node == j and l.res[0] >= self.min_res[0]):
bwd_labels_sorted = sorted(deque(
l for l in self.processed_labels["backward"]
if l.node == j),
key=lambda x: x.weight)
for bwd_label in bwd_labels_sorted:
# Merge two labels
merged_label = self._merge_labels(fwd_label, bwd_label)
if ((self.best_label and merged_label) and
merged_label.weight > self.best_label.weight):
break
# Check resource feasibility
if (merged_label and merged_label.feasibility_check(
self.max_res_in, self.min_res_in)
Expand Down Expand Up @@ -528,4 +534,4 @@ def _invert_bwd_res(self, label_to_invert):
label = Label(0, label_to_invert.node, self.max_res_in, [])
# Extend the dummy along the dummy edge to apply the custom REF
label_inverted = label.get_new_label(edge, "backward")
return label_inverted.res
return label_inverted.res

0 comments on commit 818d42c

Please sign in to comment.