AbstractGraph interface assumes a continous set of vertex ids? Alternative Interface?

I’ve implemented a custom Graph representation and wanted to use the functionality of the Graphs package, so I’ve implemented the AbstractGraph interface as explained in the packages manual here:

Wanting to use some algorithms from the package, I ran into errors that, if I interpreted them right, stem from the assumption of the package that if my graph has N nodes their labels will be in 1:N. That is not the case for my graph as I keep adding and deleting nodes and need them to keep their ids so I might have 100 nodes but their labels/ids are anywhere in 1:1000.

Does anyone know if can get Graphs to work with that or if there is another Interface for graphs, that would have no issues with discontinuous ids?

I mean I could write a mapping from my labels to a continuous set for a point in time, but that seems inefficient and unelegant.

Thanks in advance!


You could try SimpleGraphs.jl:


There is also MetaGraphsNext.jl which allows you to work with labels, although the underlying graph remains numbered from 1 to N.
The discussions around the Graphs.jl interface are far from settled, so feel free to contribute eg here


Thank you for your answers!

Looks like I’ll have to write a mapping from my labels to {1,…,N} then for now. But I’m excited to see that the currently discussed definition of the interface plans to not assume range based labels but rather have it as a special trait.

1 Like