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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

The following syntax is supported, but note that you must use the label keyword:<br />

sage: G = <strong>Graph</strong>()<br />

sage: G.add_edge((1,2), label=’label’)<br />

sage: G.edges()<br />

[(1, 2, ’label’)]<br />

sage: G = <strong>Graph</strong>()<br />

sage: G.add_edge((1,2), ’label’)<br />

sage: G.edges()<br />

[(’label’, (1, 2), None)]<br />

Vertex name cannot be None, so:<br />

sage: G = <strong>Graph</strong>()<br />

sage: G.add_edge(None, 4)<br />

sage: G.vertices()<br />

[0, 4]<br />

add_edges(edges)<br />

Add edges from an iterable container.<br />

EXAMPLES:<br />

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

sage: H = <strong>Graph</strong>()<br />

sage: H.add_edges( G.edge_iterator() ); H<br />

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

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

sage: H = Di<strong>Graph</strong>()<br />

sage: H.add_edges( G.edge_iterator() ); H<br />

Digraph on 20 vertices<br />

add_path(vertices)<br />

Adds a cycle to the graph with the given vertices. If the vertices are already present, only the edges are<br />

added.<br />

For digraphs, adds the directed path vertices[0], ..., vertices[-1].<br />

INPUT:<br />

•vertices - a list of indices for the vertices of the cycle to be added.<br />

EXAMPLES:<br />

sage: G = <strong>Graph</strong>()<br />

sage: G.add_vertices(range(10)); G<br />

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

sage: show(G)<br />

sage: G.add_path(range(20)[10:20])<br />

sage: show(G)<br />

sage: G.add_path(range(10))<br />

sage: show(G)<br />

sage: D = Di<strong>Graph</strong>()<br />

sage: D.add_path(range(4))<br />

sage: D.edges()<br />

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

add_vertex(name=None)<br />

Creates an isolated vertex. If the vertex already exists, then nothing is done.<br />

INPUT:<br />

1.1. Generic graphs 7

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

Saved successfully!

Ooh no, something went wrong!