Section 3.1 Construction and Basic Properties
Sage “knows” many graphs, and families of graphs. The graphs
object has many graphs as properties, so hit the TAB
key at the end of the next cell to see all the possibilities.
Some graphs are single versions of popular or useful graphs, such as the Heawood graph.
Others are parameterized families.
Notice that the default labeling of the vertices is integers, starting at zero.
Rather than use a pre-built graph, we can specify the edges of a graph in a list and use the Graph()
constructor.
Notice that the vertex labels now start from one. Notice too, that the default is to create a simple graph (undirected, no multiple edges, no loops). We can create a directed graph, also known as a digraph with the DiGraph()
constructor, and use letters (strings, really) as vertex labels.
We can build the underlying simple graph from this directed graph, and then test that it is indeed isomorphic to the first graph of this section. In the isomorphism check, we use the certificate
keyword to request an explicit isomorpism (in the form of a Python dictionary).
You can compute a wide variety of properties for a graph. We illustrate a few now, with the graph H
from above. If you type H.
and hit TAB
you will see a long list of others. Explore! If you type something like H.degree?
you will get documentation for the .degree()
method of a graph, which includes examples that are guaranteed to work and produce the output immediately following. What would you expect to be different about commands related to degree for a simple graph versus a directed graph?
There is more that could go into this section:
- Alternate input forms for the
Graph()
constructor. - Manipulations of a graph, such as adding and removing edges.
- Constructions of subgraphs.