| Crates.io | wl_isomorphism |
| lib.rs | wl_isomorphism |
| version | 0.1.1 |
| created_at | 2025-01-22 22:36:28.933631+00 |
| updated_at | 2025-01-23 09:03:44.845374+00 |
| description | Implementation of the WL and 2-WL algorithms for graph isomorphism testing |
| homepage | |
| repository | https://github.com/Anemoonvis/Weisfeiler-Leman_Rust |
| max_upload_size | |
| id | 1527211 |
| size | 43,815 |
This crate provides an implementation of the Weisfeiler-Leman (WL) graph isomorphism algorithm for petgraph graphs.
WL is a sound but incomplete isomorphism test, that because of its speed is often used as a subroutine in complete tests and feature extraction for graph kernels. Additionally, it includes an implementation of the two-dimensional version of the algorithm, which offers greater distinguishing power—particularly for regular graphs—at the cost of a significant runtime penalty.
The crate's most basic usage is to compare two graphs for isomorphism using the invariant function.
The function will return the same graph hash for isomorphic graphs (hence it is called an "invariant"), and in most cases different hashes for non-isomorphic graphs.
use petgraph::graph::{UnGraph, DiGraph};
let g1 = UnGraph::<u64, ()>::from_edges([(0,1), (1,2), (2,0), (2,3)]);
let g2 = UnGraph::<u64, ()>::from_edges([(0,1), (1,2), (2,0), (0,3)]);
let g3 = UnGraph::<u64, ()>::from_edges([(0,1), (1,2), (2,3), (0,3)]);
let g4 = DiGraph::<u64, ()>::from_edges([(0,1), (1,2), (2,0), (2,3)]);
let hash1 = wl_isomorphism::invariant(g1);
let hash2 = wl_isomorphism::invariant(g2);
let hash3 = wl_isomorphism::invariant(g3);
let hash4 = wl_isomorphism::invariant(g4);
println!("The final hashes (u64) are:");
println!("1: {}, 2: {}, 3: {}, and: {}", hash1, hash2, hash3, hash4);
// 1: 16339153988175251892, 2: 16339153988175251892, 3: 14961629621624962419, and: 15573326168912649736
invariant, or if you want the algorithm to run for a specific number of iterations, use invariant_iters.invariant_2wl and iter_2wl, which offer greater distinguishing power—particularly for regular graphs—at the cost of a significant runtime penalty.neighbourhood_hash for a fixed number of iterations or neighbourhood_stable to run until stabilisation.invariant_dot or iter_dot.ungraph_from_edgelist or digraph_from_edgelist.