Skip to content

Commit ec9bc14

Browse files
committed
minor fix
1 parent 52228c9 commit ec9bc14

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/sage/graphs/path_enumeration.pyx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,15 +1431,14 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
14311431
a path is returned. Otherwise a tuple of path length and path is
14321432
returned.
14331433
1434-
OUTPUT: iterator
14351434
ALGORITHM:
14361435
14371436
This algorithm is based on the ``feng_k_shortest_simple_paths`` algorithm
14381437
in [Feng2014]_, but postpones the shortest path tree computation when non-simple
14391438
deviations occur. See Postponed Node Classification algorithm in [ACN2023]_
14401439
for the algorithm description.
14411440
1442-
EXAMPLES:
1441+
EXAMPLES::
14431442
14441443
sage: from sage.graphs.path_enumeration import pnc_k_shortest_simple_paths
14451444
sage: g = DiGraph([(1, 2, 20), (1, 3, 10), (1, 4, 30), (2, 5, 20), (3, 5, 10), (4, 5, 30)])
@@ -1448,7 +1447,7 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
14481447
sage: list(pnc_k_shortest_simple_paths(g, 1, 5, report_weight=True))
14491448
[(2.0, [1, 2, 5]), (2.0, [1, 4, 5]), (2.0, [1, 3, 5])]
14501449
1451-
TESTS:
1450+
TESTS::
14521451
14531452
sage: from sage.graphs.path_enumeration import pnc_k_shortest_simple_paths
14541453
sage: g = DiGraph([(0, 1, 9), (0, 3, 1), (0, 4, 2), (1, 6, 4),
@@ -1515,9 +1514,9 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
15151514
G.delete_edges(G.incoming_edges(source, labels=False))
15161515
G.delete_edges(G.outgoing_edges(target, labels=False))
15171516

1518-
by_weight, weight_function = self._get_weight_function(by_weight=by_weight,
1519-
weight_function=weight_function,
1520-
check_weight=check_weight)
1517+
by_weight, weight_function = G._get_weight_function(by_weight=by_weight,
1518+
weight_function=weight_function,
1519+
check_weight=check_weight)
15211520

15221521
def reverse_weight_function(e):
15231522
return weight_function((e[1], e[0], e[2]))
@@ -1545,7 +1544,7 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
15451544
if e[0] in dist and e[1] in dist}
15461545

15471546
def sidetrack_length(path):
1548-
return sum(sidetrack_cost[e] for e in zip(path[:-1], path[1:]))
1547+
return sum(sidetrack_cost[e] for e in zip(path, path[1:]))
15491548

15501549
# v-t path in the first shortest path tree T_0
15511550
def tree_path(v):
@@ -1585,22 +1584,22 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
15851584
# from ``path[t]``.
15861585
ancestor_idx_dict = {v: i for i, v in enumerate(path)}
15871586

1588-
def ancestor_idx_func(v, t):
1587+
def ancestor_idx_func(v, t, len_path):
15891588
if v not in successor:
15901589
# target vertex is not reachable from v
15911590
return -1
15921591
if v in ancestor_idx_dict:
1593-
if ancestor_idx_dict[v] <= t or ancestor_idx_dict[v] == len(path) - 1:
1592+
if ancestor_idx_dict[v] <= t or ancestor_idx_dict[v] == len_path - 1:
15941593
return ancestor_idx_dict[v]
1595-
ancestor_idx_dict[v] = ancestor_idx_func(successor[v], t)
1594+
ancestor_idx_dict[v] = ancestor_idx_func(successor[v], t, len_path)
15961595
return ancestor_idx_dict[v]
15971596

15981597
if is_simple:
15991598
# output
16001599
if report_edges and labels:
1601-
P = [edge_labels[e] for e in zip(path[:-1], path[1:])]
1600+
P = [edge_labels[e] for e in zip(path, path[1:])]
16021601
elif report_edges:
1603-
P = list(zip(path[:-1], path[1:]))
1602+
P = list(zip(path, path[1:]))
16041603
else:
16051604
P = path
16061605
if report_weight:
@@ -1614,7 +1613,7 @@ def pnc_k_shortest_simple_paths(self, source, target, weight_function=None,
16141613
for e in G.outgoing_edge_iterator(path[deviation_i]):
16151614
if e[1] in path[:deviation_i + 2]: # e[1] is red or e in path
16161615
continue
1617-
ancestor_idx = ancestor_idx_func(e[1], deviation_i)
1616+
ancestor_idx = ancestor_idx_func(e[1], deviation_i, len(path))
16181617
if ancestor_idx == -1:
16191618
continue
16201619
new_path = path[:deviation_i + 1] + tree_path(e[1])

0 commit comments

Comments
 (0)