AbstractGraph interface
Graphs.jl defines the AbstractGraph
interface for compatibility with external graph formats.
Index
Graphs.AbstractEdge
Graphs.AbstractEdgeIter
Graphs.AbstractGraph
Graphs.NotImplementedError
Base.eltype
Base.reverse
Base.zero
Base.zero
Graphs.dst
Graphs.edges
Graphs.edgetype
Graphs.has_edge
Graphs.has_vertex
Graphs.inneighbors
Graphs.is_directed
Graphs.ne
Graphs.nv
Graphs.outneighbors
Graphs.src
Graphs.vertices
Full docs
Graphs.AbstractEdge
— TypeAbstractEdge
An abstract type representing a single edge between two vertices of a graph.
Graphs.AbstractEdgeIter
— TypeAbstractEdgeIter
An abstract type representing an edge iterator.
Graphs.AbstractGraph
— TypeAbstractGraph
An abstract type representing a graph.
Graphs.NotImplementedError
— TypeNotImplementedError{M}(m)
Exception
thrown when a method from the AbstractGraph
interface is not implemented by a given graph type.
Base.eltype
— Methodeltype(G)
Return the type of the graph's vertices (must be <: Integer)
Base.reverse
— Methodreverse(e)
Create a new edge from e
with source and destination vertices reversed.
Examples
julia> using Graphs
julia> g = SimpleDiGraph(2);
julia> add_edge!(g, 1, 2);
julia> reverse(first(edges(g)))
Edge 2 => 1
Base.zero
— Methodzero(G)
Return a zero-vertex, zero-edge version of the graph type G
. The fallback is defined for graph values zero(g::G) = zero(G)
.
Examples
julia> using Graphs
julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
julia> zero(typeof(g))
{0, 0} directed simple Int64 graph
julia> zero(g)
{0, 0} directed simple Int64 graph
Graphs.dst
— Methoddst(e)
Return the destination vertex of edge e
.
Examples
julia> using Graphs
julia> g = SimpleGraph(2);
julia> add_edge!(g, 1, 2);
julia> dst(first(edges(g)))
2
Graphs.edges
— Methodedges(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(g)
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
.
Examples
julia> using Graphs
julia> g = path_graph(3);
julia> collect(edges(g))
2-element Vector{Graphs.SimpleGraphs.SimpleEdge{Int64}}:
Edge 1 => 2
Edge 2 => 3
Graphs.edgetype
— Methodedgetype(g)
Return the type of graph g
's edge
Graphs.has_edge
— Methodhas_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 in edges(g)
or e ∈ edges(g)
evaluate as calls to has_edge
, c.f. edges
.
Examples
julia> using Graphs
julia> g = SimpleDiGraph(2);
julia> add_edge!(g, 1, 2);
julia> has_edge(g, 1, 2)
true
julia> has_edge(g, 2, 1)
false
Graphs.has_vertex
— Methodhas_vertex(g, v)
Return true if v
is a vertex of g
.
Examples
julia> using Graphs
julia> has_vertex(SimpleGraph(2), 1)
true
julia> has_vertex(SimpleGraph(2), 3)
false
Graphs.inneighbors
— Methodinneighbors(g, v)
Return a list of all neighbors connected to vertex v
by an incoming edge.
Implementation Notes
Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.
Examples
julia> using Graphs
julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
julia> inneighbors(g, 4)
2-element Vector{Int64}:
3
5
Graphs.is_directed
— Methodis_directed(G)
Return true
if the graph type G
is a directed graph; false
otherwise. New graph types must implement is_directed(::Type{<:G})
. The method can also be called with is_directed(g::G)
Examples
julia> using Graphs
julia> is_directed(SimpleGraph(2))
false
julia> is_directed(SimpleGraph)
false
julia> is_directed(SimpleDiGraph(2))
true
Graphs.ne
— Methodne(g)
Return the number of edges in g
.
Examples
julia> using Graphs
julia> g = path_graph(3);
julia> ne(g)
2
Graphs.nv
— Methodnv(g)
Return the number of vertices in g
.
Examples
julia> using Graphs
julia> nv(SimpleGraph(3))
3
Graphs.outneighbors
— Methodoutneighbors(g, v)
Return a list of all neighbors connected to vertex v
by an outgoing edge.
Implementation Notes
Returns a reference to the current graph's internal structures, not a copy. Do not modify result. If the graph is modified, the behavior is undefined: the array behind this reference may be modified too, but this is not guaranteed.
Examples
julia> using Graphs
julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
julia> outneighbors(g, 4)
1-element Vector{Int64}:
5
Graphs.src
— Methodsrc(e)
Return the source vertex of edge e
.
Examples
julia> using Graphs
julia> g = SimpleGraph(2);
julia> add_edge!(g, 1, 2);
julia> src(first(edges(g)))
1
Graphs.vertices
— Methodvertices(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
.
Examples
julia> using Graphs
julia> collect(vertices(SimpleGraph(4)))
4-element Vector{Int64}:
1
2
3
4
Base.zero
— Methodzero(G)
Return a zero-vertex, zero-edge version of the graph type G
. The fallback is defined for graph values zero(g::G) = zero(G)
.
Examples
julia> using Graphs
julia> g = SimpleDiGraph([0 1 0 0 0; 0 0 1 0 0; 1 0 0 1 0; 0 0 0 0 1; 0 0 0 1 0]);
julia> zero(typeof(g))
{0, 0} directed simple Int64 graph
julia> zero(g)
{0, 0} directed simple Int64 graph