09.02.2015 Views

Sage Reference Manual: Graph Theory - Mirrors

Sage Reference Manual: Graph Theory - Mirrors

Sage Reference Manual: Graph Theory - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Graph</strong> <strong>Theory</strong>, Release 6.1.1<br />

sage: G.coarsest_equitable_refinement(Pi)<br />

[[’000’], [’011’, ’101’, ’110’], [’111’], [’001’, ’010’, ’100’]]<br />

Note that given an equitable partition, this function returns that partition:<br />

sage: P = graphs.Petersen<strong>Graph</strong>()<br />

sage: prt = [[0], [1, 4, 5], [2, 3, 6, 7, 8, 9]]<br />

sage: P.coarsest_equitable_refinement(prt)<br />

[[0], [1, 4, 5], [2, 3, 6, 7, 8, 9]]<br />

sage: ss = (graphs.Wheel<strong>Graph</strong>(6)).line_graph(labels=False)<br />

sage: prt = [[(0, 1)], [(0, 2), (0, 3), (0, 4), (1, 2), (1, 4)], [(2, 3), (3, 4)]]<br />

sage: ss.coarsest_equitable_refinement(prt)<br />

Traceback (most recent call last):<br />

...<br />

TypeError: Partition ([[(0, 1)], [(0, 2), (0, 3), (0, 4), (1, 2), (1, 4)], [(2, 3), (3, 4)]]<br />

sage: ss = (graphs.Wheel<strong>Graph</strong>(5)).line_graph(labels=False)<br />

sage: ss.coarsest_equitable_refinement(prt)<br />

[[(0, 1)], [(1, 2), (1, 4)], [(0, 3)], [(0, 2), (0, 4)], [(2, 3), (3, 4)]]<br />

ALGORITHM: Brendan D. McKay’s Master’s Thesis, University of Melbourne, 1976.<br />

complement()<br />

Returns the complement of the (di)graph.<br />

The complement of a graph has the same vertices, but exactly those edges that are not in the original graph.<br />

This is not well defined for graphs with multiple edges.<br />

EXAMPLES:<br />

sage: P = graphs.Petersen<strong>Graph</strong>()<br />

sage: P.plot() # long time<br />

sage: PC = P.complement()<br />

sage: PC.plot() # long time<br />

sage: graphs.Tetrahedral<strong>Graph</strong>().complement().size()<br />

0<br />

sage: graphs.Cycle<strong>Graph</strong>(4).complement().edges()<br />

[(0, 2, None), (1, 3, None)]<br />

sage: graphs.Cycle<strong>Graph</strong>(4).complement()<br />

complement(Cycle graph): <strong>Graph</strong> on 4 vertices<br />

sage: G = <strong>Graph</strong>(multiedges=True, sparse=True)<br />

sage: G.add_edges([(0,1)]*3)<br />

sage: G.complement()<br />

Traceback (most recent call last):<br />

...<br />

TypeError: complement not well defined for (di)graphs with multiple edges<br />

connected_component_containing_vertex(vertex)<br />

Returns a list of the vertices connected to vertex.<br />

EXAMPLES:<br />

sage: G = <strong>Graph</strong>( { 0 : [1, 3], 1 : [2], 2 : [3], 4 : [5, 6], 5 : [6] } )<br />

sage: G.connected_component_containing_vertex(0)<br />

[0, 1, 2, 3]<br />

sage: D = Di<strong>Graph</strong>( { 0 : [1, 3], 1 : [2], 2 : [3], 4 : [5, 6], 5 : [6] } )<br />

sage: D.connected_component_containing_vertex(0)<br />

[0, 1, 2, 3]<br />

1.1. Generic graphs 29

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!