Skip to content

Commit 2adbad9

Browse files
committed
minor fix of nc_k_shortest_simple_paths
1 parent 2e0b083 commit 2adbad9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/sage/graphs/path_enumeration.pyx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ def shortest_simple_paths(self, source, target, weight_function=None,
542542
543543
Check that "Yen", "Feng" and "PNC" provide same results on random undirected graphs::
544544
545-
sage: from sage.graphs.generators.random import RandomGNP
546-
sage: G = RandomGNP(30, .05)
545+
sage: G = graphs.RandomGNP(30, .5)
547546
sage: for u, v in list(G.edges(labels=False, sort=False)):
548547
....: G.set_edge_label(u, v, randint(1, 10))
549548
sage: V = G.vertices(sort=False)
@@ -1012,8 +1011,8 @@ def nc_k_shortest_simple_paths(self, source, target, weight_function=None,
10121011
sage: g = Graph([(1, 2, 20), (1, 3, 10), (1, 4, 30), (2, 5, 20), (3, 5, 10), (4, 5, 30)])
10131012
sage: list(nc_k_shortest_simple_paths(g, 5, 1, by_weight=True))
10141013
[[5, 3, 1], [5, 2, 1], [5, 4, 1]]
1015-
sage: list(nc_k_shortest_simple_paths(g, 5, 1))
1016-
[[5, 2, 1], [5, 4, 1], [5, 3, 1]]
1014+
sage: [len(P) for P in nc_k_shortest_simple_paths(g, 5, 1)]
1015+
[3, 3, 3]
10171016
10181017
TESTS::
10191018
@@ -1174,11 +1173,14 @@ def nc_k_shortest_simple_paths(self, source, target, weight_function=None,
11741173
return
11751174

11761175
if self.has_loops() or self.allows_multiple_edges():
1177-
G = self.to_simple(to_undirected=self.is_directed(), keep_label='min', immutable=False)
1176+
G = self.to_simple(to_undirected=False, keep_label='min', immutable=False)
1177+
if not G.is_directed():
1178+
G = G.to_directed()
1179+
elif not self.is_directed():
1180+
# Turn the graph into a mutable directed graph
1181+
G = self.to_directed(data_structure='sparse')
11781182
else:
11791183
G = self.copy(immutable=False)
1180-
if not G.is_directed():
1181-
G = G.to_directed()
11821184

11831185
G.delete_edges(G.incoming_edges(source, labels=False))
11841186
G.delete_edges(G.outgoing_edges(target, labels=False))

0 commit comments

Comments
 (0)