#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):
LightGraphs.AbstractEdge
LightGraphs.AbstractEdgeIter
LightGraphs.AbstractGraph
Base.reverse
LightGraphs.dst
LightGraphs.edges
LightGraphs.edgetype
LightGraphs.has_edge
LightGraphs.has_vertex
LightGraphs.inneighbors
LightGraphs.is_directed
LightGraphs.ne
LightGraphs.nv
LightGraphs.outneighbors
LightGraphs.src
LightGraphs.vertices
Full Docs for AbstractGraph Functions
LightGraphs.AbstractEdge
— Type.AbstractEdge
An abstract type representing a single edge between two vertices of a graph.
LightGraphs.AbstractEdgeIter
— Type.AbstractEdgeIter
An abstract type representing an edge iterator.
LightGraphs.AbstractGraph
— Type.AbstractGraph
An abstract type representing a graph.
Base.reverse
— Method.reverse(e)
Create a new edge from e
with source and destination vertices reversed.
LightGraphs.dst
— Method.dst(e)
Return the destination vertex of edge e
.
LightGraphs.edges
— Method.edges(g)
Return (an iterator to or collection of) the edges of a graph. For AbstractSimpleGraph
s 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
.
LightGraphs.edgetype
— Method.edgetype(g)
Return the type of graph g
's edge
LightGraphs.has_edge
— Method.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
.
LightGraphs.has_vertex
— Method.has_vertex(g, v)
Return true if v
is a vertex of g
.
LightGraphs.inneighbors
— Method.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.
LightGraphs.is_directed
— Method.is_directed(g)
Return true if the graph is a directed graph; false otherwise.
LightGraphs.ne
— Method.ne(g)
Return the number of edges in g
.
LightGraphs.nv
— Method.nv(g)
Return the number of vertices in g
.
LightGraphs.outneighbors
— Method.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.
LightGraphs.src
— Method.src(e)
Return the source vertex of edge e
.
LightGraphs.vertices
— Method.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
.