Modular Decomposition
A library to compute the modular decomposition of a simple, undirected graph.
A node set M is a module if every node has the same neighborhood outside M. The set of all nodes V and the sets with a single node {u} are trivial modules.
The modular decomposition algorithm in this library has a O(n + m log n) running time and is based on [HPV99] and [CHM02]. Although linear time algorithms exists, they perform worse in comparison.
Examples
The smallest prime graph is the path graph on 4 nodes.
use UnGraph;
use ;
// a path graph with 4 nodes
let graph = from_edges;
let md = modular_decomposition?;
assert_eq!;
Determining whether a graph is a cograph.
use UnGraph;
use ;
// a complete graph with 3 nodes
let graph = from_edges;
let md = modular_decomposition?;
// a graph is a cograph exactly if none of its modules is prime
let is_cograph = md.module_kinds.all;
assert!;
// we can also use the method `is_cograph`
assert!;
Iterating over twins, true twins or false twins.
use ;
use modular_decomposition;
let normalize = ;
// a K_2 + 2 K_1
let graph = from_edges;
let md = modular_decomposition?;
let twins: = md.twins.collect;
assert_eq!;
let true_twins: = md.true_twins.collect;
assert_eq!;
let false_twins: = md.false_twins.collect;
assert_eq!;
Walking the modular decomposition tree in DFS order.
use ;
use modular_decomposition;
// some graph
let graph = from_edges;
let md = modular_decomposition?;
let mut stack = vec!;
while let Some = stack.pop
Generics
The algorithm is implemented for structs that implement the petgraph
traits NodeCompactIndexable, IntoNeighbors, and GraphProp<EdgeType = Undirected>.
Evaluation

As part of a thesis, we evaluated four implementations of modular decomposition algorithms.
The fracture algorithm performs best and is provided in this library. For more information see
the repository.
Citing
Jonas Spinner. "A Practical Evaluation of Modular Decomposition Algorithms". https://doi.org/10.5445/IR/1000170363