@@ -1581,7 +1581,7 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
1581
1581
1582
1582
# ancestor_idx_vec[v] := the first vertex of ``path[:t+1]`` or ``id_target`` reachable by
1583
1583
# edges of first shortest path tree from v.
1584
- cdef vector[int ] ancestor_idx_vec = [- 1 for _ in range (len (G))]
1584
+ cdef vector[int ] ancestor_idx_vec = [- 1 for _ in range (len (G) + len (unnecessary_vertices) )]
1585
1585
1586
1586
def ancestor_idx_func (v , t , target_idx ):
1587
1587
if ancestor_idx_vec[v] != - 1 :
@@ -1596,9 +1596,8 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
1596
1596
cdef dict pred = {}
1597
1597
1598
1598
# calculate shortest path from dev to one of green vertices
1599
- def shortest_path_to_green (dev , exclude_vertices ):
1599
+ def shortest_path_to_green (dev , exclude_vertices , target_idx ):
1600
1600
t = len (exclude_vertices)
1601
- ancestor_idx_vec[id_target] = t + 1
1602
1601
# clear
1603
1602
while not pq.empty():
1604
1603
pq.pop()
@@ -1612,7 +1611,7 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
1612
1611
v, d = pq.top()
1613
1612
pq.pop()
1614
1613
1615
- if ancestor_idx_func(v, t, t + 1 ) == t + 1 : # green
1614
+ if ancestor_idx_func(v, t, target_idx ) == target_idx : # green
1616
1615
path = []
1617
1616
while v in pred:
1618
1617
path.append(v)
@@ -1667,7 +1666,7 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
1667
1666
yield P
1668
1667
1669
1668
# GET DEVIATION PATHS
1670
- original_cost = cost
1669
+ original_cost = cost - sidetrack_cost[(path[ - 2 ], path[ - 1 ])]
1671
1670
former_part = set (path)
1672
1671
for deviation_i in range (len (path) - 2 , dev_idx - 1 , - 1 ):
1673
1672
for e in G.outgoing_edge_iterator(path[deviation_i]):
@@ -1687,7 +1686,8 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
1687
1686
original_cost -= sidetrack_cost[(path[deviation_i - 1 ], path[deviation_i])]
1688
1687
former_part.remove(path[deviation_i + 1 ])
1689
1688
else :
1690
- deviations = shortest_path_to_green(path[dev_idx], set (path[:dev_idx]))
1689
+ ancestor_idx_vec[id_target] = len (path)
1690
+ deviations = shortest_path_to_green(path[dev_idx], set (path[:dev_idx]), len (path))
1691
1691
if not deviations:
1692
1692
continue # no path to target in G \ path[:dev_idx]
1693
1693
deviation_weight, deviation = deviations
0 commit comments