Developing Alternate Graph Types

This section is designed to guide developers who wish to write their own graph structures.

All LightGraphs functions rely on a standard API to function. As long as your graph structure is a subtype of AbstractGraph and implements the following API functions, all functions within the LightGraphs package should just work:

must be implemented with the following signature:

  • is_directed(::Type{CustomGraph})::Bool (example: is_directed(::Type{<:CustomGraph}) = false)

The following signature is optional:

  • is_directed(g::CustomGraph)::Bool

If the graph structure is designed to represent weights on edges, the weights function should also be defined. Note that the output does not necessarily have to be a dense matrix, but it must be a subtype of AbstractMatrix{<:Real} and indexable via [u, v].

Contiguous vertices

Some LightGraphs functions work under the assumption that the vertices are contiguous integers from one(eltype(g)) to nv(g). For graph types which do not respect this assumption, the method has_contiguous_vertices should be implemented and set to false. The following methods, which use this assumption when possible, should also be redefined:

Inheriting from AbstractSimpleGraph

AbstractSimpleGraph is the supertype of both SimpleGraph and SimpleDiGraph. Every subtype of AbstractSimpleGraph must return neighbors in ascending order.