tournament_hamiltonian_path#
- graph_tool.structure.tournament_hamiltonian_path(g)[git][source]#
Return a Hamiltonian path of a tournament.
- Parameters:
- g
Graph Tournament (see
is_tournament()).
- g
- Returns:
- path
numpy.ndarray The vertices in the order of a directed path that visits all of them.
- path
See also
is_tournamentTest for tournaments
tsp_tourTraveling salesman tour
Notes
Every tournament has a Hamiltonian path [redei-kombinatorischer-1934]. It is built by inserting every vertex at the front, at the back, or, found by binary search, between two consecutive vertices \(u \to v\) of the path such that \(u \to w \to v\), with \(O(V\log V)\) adjacency tests after the edges are hashed in time \(O(E)\). A
ValueErroris raised if the graph is not a tournament.References
[redei-kombinatorischer-1934]László Rédei, “Ein kombinatorischer Satz”, Acta Litterarum ac Scientiarum Szeged 7, 39-43 (1934).
Examples
>>> g = gt.Graph([(i, j) if (i + j) % 2 else (j, i) ... for i in range(6) for j in range(i + 1, 6)]) >>> p = gt.tournament_hamiltonian_path(g) >>> print(p, all(g.edge(u, v) is not None for u, v in zip(p[:-1], p[1:]))) [4 2 0 5 3 1] True