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: D = Di<strong>Graph</strong>( { 0: [1,2,3], 1: [4,5], 2: [5], 3: [6], 5: [7], 6: [7], 7: [0]})<br />

sage: list(D.breadth_first_search(5,neighbors=D.neighbors_in, distance=2))<br />

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

sage: list(D.breadth_first_search(5,neighbors=D.neighbors_out, distance=2))<br />

[5, 7, 0]<br />

sage: list(D.breadth_first_search(5,neighbors=D.neighbors, distance=2))<br />

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

TESTS:<br />

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

sage: list(D.breadth_first_search(0))<br />

[0]<br />

sage: list(D.breadth_first_search(0, ignore_direction=True))<br />

[0, 1, 2]<br />

canonical_label(partition=None, certify=False, verbosity=0, edge_labels=False)<br />

Returns the unique graph on {0, 1, ..., n − 1} ( n = self.order() ) which<br />

•is isomorphic to self,<br />

•is invariant in the isomorphism class.<br />

In other words, given two graphs G and H which are isomorphic, suppose G_c and H_c are the graphs<br />

returned by canonical_label. Then the following hold:<br />

•G_c == H_c<br />

•G_c.adjacency_matrix() == H_c.adjacency_matrix()<br />

•G_c.graph6_string() == H_c.graph6_string()<br />

INPUT:<br />

•partition - if given, the canonical label with respect to this set partition will be computed. The<br />

default is the unit set partition.<br />

•certify - if True, a dictionary mapping from the (di)graph to its canonical label will be given.<br />

•verbosity - gets passed to nice: prints helpful output.<br />

•edge_labels - default False, otherwise allows only permutations respecting edge labels.<br />

EXAMPLES:<br />

sage: D = graphs.Dodecahedral<strong>Graph</strong>()<br />

sage: E = D.canonical_label(); E<br />

Dodecahedron: <strong>Graph</strong> on 20 vertices<br />

sage: D.canonical_label(certify=True)<br />

(Dodecahedron: <strong>Graph</strong> on 20 vertices, {0: 0, 1: 19, 2: 16, 3: 15, 4: 9, 5: 1, 6: 10, 7: 8, 8:<br />

sage: D.is_isomorphic(E)<br />

True<br />

Multigraphs:<br />

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

sage: G.add_edge((0,1))<br />

sage: G.add_edge((0,1))<br />

sage: G.add_edge((0,1))<br />

sage: G.canonical_label()<br />

Multi-graph on 2 vertices<br />

sage: <strong>Graph</strong>(’A’, implementation=’c_graph’).canonical_label()<br />

<strong>Graph</strong> on 2 vertices<br />

1.1. Generic graphs 21

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

Saved successfully!

Ooh no, something went wrong!