complement_graph#
- graph_tool.generation.complement_graph(g, self_loops=False)[git][source]#
Return the complement of a graph.
- Parameters:
- g
Graph Graph to be used.
- self_loops
bool(optional, default:False) If
True, every vertex without a self-loop gets one.
- g
- Returns:
- u
Graph The graph on the same vertices (in the order of their indices) with an edge exactly between the pairs that are not adjacent in
g.
- u
See also
graph_joinJoin of two graphs
graph_differenceDifference of two graphs
complete_graphComplete graph
Notes
The complement of \(G=(V,E)\) is the graph with the same vertices and the edge set
\[\bar E = \{(u, v) : u, v \in V,\ u \neq v,\ (u, v)\notin E\},\]with ordered pairs for directed graphs and unordered ones for undirected graphs, so that the complement has no parallel edges and parallel edges of
gcount as a single adjacency. Withself_loops=True, the condition \(u \neq v\) is dropped, so that every vertex without a self-loop ingreceives one. The algorithm runs in time \(O(V^2)\).Examples
>>> g = gt.circular_graph(5) >>> print(gt.isomorphism(g, gt.complement_graph(g))) True
The complement of a cycle is drawn as follows, with the vertices placed on a circle:
>>> g = gt.complement_graph(gt.circular_graph(10)) >>> 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="complement_graph-cycle.pdf") <...>
Complement of the cycle \(C_{10}\), with the vertices placed on a circle in the order of their indices.#