Files
reachability-algorithms/README.md

1.4 KiB

Reachability algorithms by Roditty and Zwick

The goal of this repository is to implement a collection of decremental/dynamic reachability algorithms, inspired by "Improved Dynamic Reachability Algorithms for Directed Graphs" by Liam Roditty and Uri Zwick.

A code example

#include "roditty_zwick.h"

int main() {
    // Initialize directed graph G
    graph::Digraph<int> G(
        {1, {2}}, {2, {3, 4}}, {3, {1, 5, 9}},
        {4, {5, 6}},
        {5, {6, 7}}, {6, {8}}, {7, {8, 9}}, {8, {9}}, {9, {5}}
    );
    
    // Initialize dynamic reachability algorithm for general directed graphs
    auto hk = new algo::HenzingerKing(G);
    hk->init();

    // Remove edges
    std::vector<std::pair<int, int>> delEdges( {4, 6}, {5, 6}, {3, 1} );
    for (const auto& [u, v] : delEdges)
      hk.remove(u, v);

    // Insert edges
    std::pair<int, std::vector<int>> addEdges( { 1 , {2, 3, 4, 5} } );
    hk.insert(u, addEdges);

    // Search query
    std::cout << "Path from 4 to 8 exists: " << hk.query(4, 8) << '\n';

    return 0;    
}

Run locally

Clone the repository with submodules (doctest/nanobench):

git clone --recurse-submodules https://github.com/stefiosif/dynamic-reachability-algorithms
cd dynamic-reachability-algorithms

References