There's an implementation using LightGraphs in https://github.com/JuliaIntervals/IntervalOptimisation.jl/pull/5 It doesn't seem so easy to write an implementation by hand. It's basically a [union-find algorithm](https://juliacollections.github.io/DataStructures.jl/latest/disjoint_sets/#Disjoint-Sets-1)