Skip to content

Commit 3e16dbf

Browse files
dcoudertdimpase
authored andcommitted
fix another issue
1 parent f014a53 commit 3e16dbf

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/sage/graphs/generic_graph_pyx.pyx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,10 +1239,14 @@ cpdef tuple find_hamiltonian(G, long max_iter=100000, long reset_bound=30000,
12391239
path::
12401240
12411241
sage: G = graphs.HyperStarGraph(5, 2)
1242-
sage: fh(G,find_path=False)
1243-
(False, ['01100', '10100', '00110', '10010', '00011', '10001', '01001', '11000', '01010'])
1244-
sage: fh(G,find_path=True)
1245-
(False, ['00110', '10010', '01010', '11000', '01100', '10100', '00101', '10001', '00011'])
1242+
sage: G.order()
1243+
10
1244+
sage: b, P = fh(G,find_path=False)
1245+
sage: b, len(P)
1246+
(False, 9)
1247+
sage: b, P = fh(G,find_path=True)
1248+
sage: b, len(P)
1249+
(False, 9)
12461250
12471251
The method can also be used for directed graphs::
12481252
@@ -1256,8 +1260,10 @@ cpdef tuple find_hamiltonian(G, long max_iter=100000, long reset_bound=30000,
12561260
(False, ['d', 'c', 'b', 'a'])
12571261
sage: H = DiGraph()
12581262
sage: H.add_cycle('abcdefgh')
1259-
sage: fh(H)
1260-
(True, ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'a'])
1263+
sage: H.add_edge('dg')
1264+
sage: b, C = fh(H)
1265+
sage: b, len(C)
1266+
(True, 8)
12611267
sage: H.delete_edge('ab')
12621268
sage: fh(H, find_path=False)
12631269
(False, ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'a'])
@@ -1312,6 +1318,13 @@ cpdef tuple find_hamiltonian(G, long max_iter=100000, long reset_bound=30000,
13121318
(False, [0, 1, 2, 3])
13131319
sage: fh(G, find_path=True)
13141320
(False, [0, 1, 2, 3])
1321+
1322+
Check that the method is robust to incomparble vertices::
1323+
1324+
sage: G = Graph([(1, 'a'), ('a', 2), (2, 3), (3, 1)])
1325+
sage: b, C = fh(G, find_path=False)
1326+
sage: b, len(C)
1327+
(True, 4)
13151328
"""
13161329
G._scream_if_not_simple()
13171330

@@ -1471,7 +1484,7 @@ cpdef tuple find_hamiltonian(G, long max_iter=100000, long reset_bound=30000,
14711484
longest = length
14721485
longest_reversed = reverse
14731486

1474-
if not directed and not longer:
1487+
if not directed and not longer and out_degree(sd, path[length - 1]) > 1:
14751488
# We revert a cycle to change the extremity of the path
14761489
degree = out_degree(sd, path[length - 1])
14771490
while True:

0 commit comments

Comments
 (0)