@@ -542,8 +542,7 @@ def shortest_simple_paths(self, source, target, weight_function=None,
542
542
543
543
Check that "Yen", "Feng" and "PNC" provide same results on random undirected graphs::
544
544
545
- sage: from sage. graphs. generators. random import RandomGNP
546
- sage: G = RandomGNP( 30, . 05)
545
+ sage: G = graphs. RandomGNP( 30, . 5)
547
546
sage: for u, v in list( G. edges( labels=False, sort=False)) :
548
547
.... : G. set_edge_label( u, v, randint( 1, 10))
549
548
sage: V = G. vertices( sort=False)
@@ -1012,8 +1011,8 @@ def nc_k_shortest_simple_paths(self, source, target, weight_function=None,
1012
1011
sage: g = Graph( [(1, 2, 20), (1, 3, 10), (1, 4, 30), (2, 5, 20), (3, 5, 10), (4, 5, 30) ])
1013
1012
sage: list( nc_k_shortest_simple_paths( g, 5, 1, by_weight=True))
1014
1013
[[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 ]
1017
1016
1018
1017
TESTS::
1019
1018
@@ -1174,11 +1173,14 @@ def nc_k_shortest_simple_paths(self, source, target, weight_function=None,
1174
1173
return
1175
1174
1176
1175
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' )
1178
1182
else :
1179
1183
G = self .copy(immutable = False )
1180
- if not G.is_directed():
1181
- G = G.to_directed()
1182
1184
1183
1185
G.delete_edges(G.incoming_edges(source, labels = False ))
1184
1186
G.delete_edges(G.outgoing_edges(target, labels = False ))
0 commit comments