Custom Value Graph types

While this package provides some concrete graph types, one is often interested in creating their own graph types. This section will explain how one can create a custom graph type that will work well with the methods from as package as well as the ones from Graphs.jl

The AbstractValGraph type

All value graphs should be subtypes of AbstractValGraph that has the signature

    AbstractValGraph{V <: Integer, V_VALS, E_VALS, G_VALS} <: Graphs.AbstractGraph{V}

where the parameters have the following meaning:

  • V is the type used for indexing vertices, called the eltype of the graph. Should be a subtype of Integer.
  • V_VALS is the type of the vertex values.
  • E_VALS is the type of the edge values.
  • G_VALS is the type of the graph values.

The value types V_VALS, E_VALS and G_VALS are either subtypes of Tuple for unnamed values or of NamedTuple for named values.

A subtype of AbstractValGraph is free to restrict some of these parameters, for example

MyGraphType{W} <: AbstractValGraph{Int, Tuple{}, Tuple{Int, W}, Tuple{}}

is a graph type that has neither vertex nor graph values and two edge values, one of them of type Int and the other of type W.

As a subtype of Graphs.AbstractGraph, an AbstractValGraph should implement the methods required by Graphs.jl as well as some other methods. Luckily a lot of the methods required for AbstractGraph already have a default implementation, so the number of necessary methods is actually much shorter.

We distinguish between methods that need to be implemented, methods that only need to be implemented in some cases to enable extra features, and methods that have a default implementation that can be overridden for performance or other reasons.

Necessary methods

methodbrief description
nv(g)number of vertices
has_edge(g, s, d)true if there is an edge from vertex s to d
is_directed(G)true if graph type G is directed
zero(G)create an instance of graph type G without vertices

Necessary in some cases

methodnecessary ifbrief description
get_graphval(g, i)g has graph valuesi-th graph value of g
get_vertexval(g, v, i)g has vertex valuesi-th vertex value of vertex v
get_edgevalval(g, s, d, i)g has edge valuesi-th edge value of the edge s -> d
set_graphval!(g, i, val)one can set graph valuesset the i-th graph value of g
set_vertexval!(g, v, i, val)one can set vertex valuesset the i-th vertex value of vertex v
set_edgevalval!(g, s, d, i, val)one can set edge valuesset the i-th edge value of the edge s -> d
add_vertex!(g, vals)one can add verticesadd a vertex with values vals
rem_vertex!(g, v)one can remove verticesremove vertex v
add_edge!(g, s, d, vals)one can add edgesadd an edge s -> d with values vals
rem_edge!(g, s, d)one can remove edgesremove the edge s -> d

Methods with default implementations

methodbrief description
ne(g)number of edges

TODO there are more

Changing the edgetype

TODO