generate_tournament

generate_tournament#

graph_tool.generation.generate_tournament(N)[git][source]#

Generate a uniformly random tournament.

Parameters:
Nint

Number of vertices.

Returns:
gGraph

The generated directed graph.

See also

graph_tool.structure.is_tournament

Test for tournaments

graph_tool.structure.tournament_hamiltonian_path

Hamiltonian path

named_graph

Deterministic 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")
<...>
../_images/generate_tournament-small.png

Random tournament with \(N=7\) vertices, placed on a circle in the order of their indices.#