diff --git a/algorithm/decremental_scc.h b/algorithm/decremental_scc.h index e0574ef..a3e7a01 100644 --- a/algorithm/decremental_scc.h +++ b/algorithm/decremental_scc.h @@ -1,11 +1,10 @@ #ifndef DECREMENTAL_SCC_H_ #define DECREMENTAL_SCC_H_ -#include "graph/digraph.h" -#include "graph/scc.h" -#include "algorithm/tarjan.h" -#include "algorithm/bfs.h" #include "algorithm/roditty_zwick.h" +#include "algorithm/tarjan.h" +#include "algorithm/breadth_first_search.h" +#include "tree/breadth_first_tree.h" using namespace graph; @@ -16,16 +15,12 @@ class DecrementalSCC : public RodittyZwick { public: DecrementalSCC(Digraph G) : G(G) {} - // void init(); - // void findSCC(); - // bool query(const T& u, const T& v); - // void remove(const T& u, const T& v); private: Digraph G; @@ -49,13 +44,13 @@ void DecrementalSCC::init() { template void DecrementalSCC::findSCC() { - auto SCCs = Tarjan(G).findSCC(); + auto SCCs = Tarjan(G).execute(); for (auto& C : SCCs) { const auto& w = C.representative(); // Create shortest-paths out-tree/in-tree - auto outTree = Digraph(BFS(C).run(w)); + auto outTree = Digraph(BreadthFirstSearch(C).execute(w)); SPT[w] = std::make_pair(outTree, outTree.reverse()); // Update A with current SCCs vertices @@ -89,7 +84,7 @@ void DecrementalSCC::remove(const T& u, const T& v) { // Update In(w) and Out(w) connection[w].adjMatrix[u].erase(v); G.adjMatrix[u].erase(v); - auto inTree = Digraph(BFS(connection[w]).run(w)); + auto inTree = Digraph(BreadthFirstSearch(connection[w]).execute(w)); SPT[w] = std::make_pair(inTree, inTree.reverse()); // If a SCC is broken, compute all SCCs again diff --git a/algorithm/decremental_tc.h b/algorithm/decremental_tc.h index b8c4298..5380c26 100644 --- a/algorithm/decremental_tc.h +++ b/algorithm/decremental_tc.h @@ -1,11 +1,14 @@ #ifndef DECREMENTAL_TC_H_ #define DECREMENTAL_TC_H_ -#include "graph/digraph.h" -#include "graph/scc.h" -#include "algorithm/tarjan.h" -#include "algorithm/bfs.h" #include "algorithm/roditty_zwick.h" +#include "algorithm/tarjan.h" +#include "algorithm/breadth_first_search.h" +#include "tree/breadth_first_tree.h" + +#include + +using namespace graph; namespace algo { @@ -14,14 +17,21 @@ class DecrementalTC : public RodittyZwick { public: DecrementalTC(Digraph G) : G(G) {} - // void init(); - // bool query(const T& u, const T& v); - // void remove(const T& u, const T& v); +private: + // Every vertex u has a pointer C(u) to the component containing it + std::map vc; + + // For every component C, the algorithm maintains three linked lists + // Ein(C), Eout(C), and Eint(C) of the incoming, outgoing, and the internal + // edges of the component C + std::forward_list Ein; + std::forward_list Eout; + std::forward_list Eint; }; diff --git a/algorithm/dynamic_reachability.h b/algorithm/dynamic_reachability.h index cf9b3d5..9cb5ad4 100644 --- a/algorithm/dynamic_reachability.h +++ b/algorithm/dynamic_reachability.h @@ -1,31 +1,16 @@ #ifndef DYNAMIC_REACHABILITY_ #define DYNAMIC_REACHABILITY_ -#include "graph/digraph.h" -#include "graph/scc.h" -#include "algorithm/tarjan.h" -#include "algorithm/bfs.h" #include "algorithm/roditty_zwick.h" -using namespace graph; - namespace algo { template class DynamicReachability : public RodittyZwick { ~DynamicReachability(); - // - virtual void init() =0; - - // - virtual bool query(const T& u, const T& v) =0; - - // - virtual void remove(const T& u, const T& v) =0; - - // - virtual void insert() =0; + // Insert edge e(u,v) and maintain the transitive closure matrix + virtual void insert(const T& u, const T& v) =0; }; template diff --git a/algorithm/roditty_zwick.h b/algorithm/roditty_zwick.h index 5386fdd..1181649 100644 --- a/algorithm/roditty_zwick.h +++ b/algorithm/roditty_zwick.h @@ -1,8 +1,6 @@ #ifndef RODITTY_ZWICK_H_ #define RODITTY_ZWICK_H_ -using namespace graph; - namespace algo { template @@ -10,13 +8,14 @@ class RodittyZwick { public: ~RodittyZwick(); - // + // This method is implemented and executed by all roditty and zwick + // algorithms, it constructs the data structures used in other operations virtual void init() =0; - // + // Answer if vertex v is reachable from vertex u virtual bool query(const T& u, const T& v) =0; - // + // Remove edge e(u,v) and maintain the transitive closure matrix virtual void remove(const T& u, const T& v) =0; }; diff --git a/algorithm/tarjan.h b/algorithm/tarjan.h index 80fbc83..fd18387 100644 --- a/algorithm/tarjan.h +++ b/algorithm/tarjan.h @@ -1,7 +1,6 @@ #ifndef TARJAN_H_ #define TARJAN_H_ -#include "graph/digraph.h" #include "graph/scc.h" #include @@ -16,10 +15,8 @@ class Tarjan { public: Tarjan(Digraph G) : G(G) {} - // - std::vector> findSCC(); + std::vector> execute(); - // void strongConnect(const T& v); private: // Necessary info about vertices when running Tarjan's algorithm @@ -68,7 +65,7 @@ void Tarjan::strongConnect(const T& v) { } template -std::vector> Tarjan::findSCC() { +std::vector> Tarjan::execute() { for (const auto& v : G.vertices) { if (p[v].index == -1) { strongConnect(v); diff --git a/graph/scc.h b/graph/scc.h index f3b4e87..e2b835b 100644 --- a/graph/scc.h +++ b/graph/scc.h @@ -21,7 +21,6 @@ private: // Each SCC has a representative vertex that helps // answer strong connectivity queries in O(1) time T proxy; - }; }; // namespace graph diff --git a/graph/transitive_closure.h b/graph/transitive_closure.h deleted file mode 100644 index c363f89..0000000 --- a/graph/transitive_closure.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef TRANSITIVE_CLOSURE_H_ -#define TRANSITIVE_CLOSURE_H_ - -#include "digraph.h" - -namespace graph { - -// Transitive closure matrix class to answer reachability queries -template -class TransitiveClosure { -public: - TransitiveClosure() = default; -}; - -} // namespace graph - - -#endif \ No newline at end of file