generate_tournament#
- graph_tool.generation.generate_tournament(N)[git][source]#
Generate a uniformly random tournament.
- Parameters:
- N
int Number of vertices.
- N
- Returns:
- g
Graph The generated directed graph.
- g
See also
graph_tool.structure.is_tournamentTest for tournaments
graph_tool.structure.tournament_hamiltonian_pathHamiltonian path
named_graphDeterministic graphs, including the transitive tournament
Notes
A tournament is an orientation of the complete graph: every pair of vertices is connected by a single directed edge, whose direction is chosen uniformly at random. The algorithm runs in time \(O(N^2)\).
Examples
>>> g = gt.generate_tournament(10) >>> print(g.num_edges(), g.get_out_degrees(g.get_vertices())) 45 [6 5 4 3 5 2 5 7 3 5]
A smaller instance is drawn as follows, with the vertices placed on a circle:
>>> g = gt.generate_tournament(7) >>> x = 2 * np.pi * np.arange(g.num_vertices()) / g.num_vertices() >>> pos = g.new_vp("vector<double>", ... vals=np.array([np.cos(x), np.sin(x)]).T) >>> gt.graph_draw(g, pos=pos, ... output="generate_tournament-small.pdf") <...>
Random tournament with \(N=7\) vertices, placed on a circle in the order of their indices.#