LightGraphs Types

#LightGraphs Types

LightGraphs.jl supports both the AbstractGraph type and two concrete simple graph types- - SimpleGraph for undirected graphs and SimpleDiGraph for directed graphs – that are subtypes of AbstractGraph.

Concrete Types

LightGraphs.jl provides two concrete graph types: SimpleGraph is an undirected graph, and SimpleDiGraph is its directed counterpart. Both of these types can be parameterized to specifying how vertices are identified (by default, SimpleGraph and SimpleDiGraph use the system default integer type, usually Int64).

A graph G is described by a set of vertices V and edges E: G = {V, E}. V is an integer range 1:n; E is represented as forward (and, for directed graphs, backward) adjacency lists indexed by vertices. Edges may also be accessed via an iterator that yields Edge types containing (src<:Integer, dst<:Integer) values. Both vertices and edges may be integers of any type, and the smallest type that fits the data is recommended in order to save memory.

Graphs are created using SimpleGraph() or SimpleDiGraph(); there are several options (see the tutorials for examples).

Multiple edges between two given vertices are not allowed: an attempt to add an edge that already exists in a graph will not raise an error. This event can be detected using the return value of add_edge!.

AbstractGraph Type

To encourage experimentation and development within the JuliaGraphs ecosystem, LightGraphs.jl defines the AbstractGraph type, which is used by libraries like MetaGraphs.jl (for graphs with associated meta-data) and SimpleWeightedGraphs.jl (for weighted graphs). All types that are a subset of AbstractGraph must implement the following functions (most of which are described in more detail in Accessing Graph Properties and Making and Modifying Graphs):

Full Docs for AbstractGraph Functions

AbstractEdge

An abstract type representing a single edge between two vertices of a graph.

source
AbstractEdgeIter

An abstract type representing an edge iterator.

source
AbstractGraph

An abstract type representing a graph.

source
Base.reverseMethod.
reverse(e)

Create a new edge from e with source and destination vertices reversed.

source
LightGraphs.dstMethod.
dst(e)

Return the destination vertex of edge e.

source
LightGraphs.edgesMethod.
edges(g)

Return (an iterator to or collection of) the edges of a graph. For AbstractSimpleGraphs it returns a SimpleEdgeIter. The expressions e in edges(g) and e ∈ edges(ga) evaluate as calls to has_edge.

Implementation Notes

A returned iterator is valid for one pass over the edges, and is invalidated by changes to g.

source
edgetype(g)

Return the type of graph g's edge

source
has_edge(g, s, d)

Return true if the graph g has an edge from node s to node d.

An optional has_edge(g, e) can be implemented to check if an edge belongs to a graph, including any data other than source and destination node.

e ∈ edges(g) or e ∈ edges(g) evaluate as calls to has_edge, c.f. edges.

source
has_vertex(g, v)

Return true if v is a vertex of g.

source
inneighbors(g, v)

Return a list of all neighbors connected to vertex v by an incoming edge.

Implementation Notes

Returns a reference, not a copy. Do not modify result.

source
is_directed(g)

Return true if the graph is a directed graph; false otherwise.

source
LightGraphs.neMethod.
ne(g)

Return the number of edges in g.

source
LightGraphs.nvMethod.
nv(g)

Return the number of vertices in g.

source
outneighbors(g, v)

Return a list of all neighbors connected to vertex v by an outgoing edge.

Implementation Notes

Returns a reference, not a copy. Do not modify result.

source
LightGraphs.srcMethod.
src(e)

Return the source vertex of edge e.

source
vertices(g)

Return (an iterator to or collection of) the vertices of a graph.

Implementation Notes

A returned iterator is valid for one pass over the edges, and is invalidated by changes to g.

source