Macaulay2 » Documentation
Packages » Graphs :: graph
next | previous | forward | backward | up | index | toc

graph -- Constructs a simple graph

Synopsis

Description

A graph consists of two sets, a vertex set and an edge set which is a subset of the collection of subsets of the vertex set. Edges in graphs are symmetric or two-way; if u and v are vertices then if {u,v} is an edge connecting them, {v,u} is also an edge (which is implicit in the definition, we will almost always just use one of the pairs). Graphs are defined uniquely from their Adjacency Matrices. These matrices use the entries as 0 or 1 to signal the existence of an edge connecting vertices. The options for EntryMode are "neighbors" and "edges" (the default). This means that in including EntryMode => "edges" in the constructor allows the user to simply type in a list of edges to construct a graph. See example 1 below. Using the default takes an input of a list of pairs, where the first entry of each pair is a vertex and the second entry of each pair is that vertex's neighborhood. The options for Singletons allows the user to enter Singletons => {list of single points} in a graph if they desire to have isolated points in a graph. See second example below.

i1 : G = graph({{1,2},{2,3},{3,4}})

o1 = Graph{1 => {2}   }
           2 => {1, 3}
           3 => {2, 4}
           4 => {3}

o1 : Graph
i2 : G = graph({{1,2},{2,3},{3,4}}, Singletons => {5,6,7})

o2 = Graph{1 => {2}   }
           2 => {1, 3}
           3 => {2, 4}
           4 => {3}
           5 => {}
           6 => {}
           7 => {}

o2 : Graph
i3 : G = graph ({{a,{b,c,d,e}}, {b,{d,e}}, {e,{a}}})

o3 = Graph{a => {e, b, c, d}}
           b => {e, a, d}
           c => {a}
           d => {a, b}
           e => {a, b}

o3 : Graph
i4 : G = graph hashTable {{1,{2}},{2,{1,3}},{3,{2,4}},{4,{3}}}

o4 = Graph{1 => {2}   }
           2 => {1, 3}
           3 => {2, 4}
           4 => {3}

o4 : Graph
i5 : G = graph(matrix {{0,1,1},{1,0,0},{1,0,0}})

o5 = Graph{0 => {1, 2}}
           1 => {0}
           2 => {0}

o5 : Graph
i6 : G = graph({a,b,c}, matrix {{0,1,1},{1,0,0},{1,0,0}})

o6 = Graph{a => {b, c}}
           b => {a}
           c => {a}

o6 : Graph

See also

Ways to use graph :

For the programmer

The object graph is a method function with options.