From 95e7d56c1ea57ca07dadfa49770644b395e3c65c Mon Sep 17 00:00:00 2001 From: stefiosif Date: Sun, 25 Sep 2022 17:27:21 +0300 Subject: [PATCH] Refactor file names to better understand inheritance of the skeleton of RZ algorithms --- ...tty_zwick.h => decremental_reachability.h} | 17 ++-- algorithm/dynamic_reachability.h | 18 ++++ algorithm/dynamic_roditty_zwick.h | 23 ----- benchmark/decremental_bench.cc | 34 -------- benchmark/decremental_reachability_bench.cc | 8 ++ benchmark/dynamic_reachability_bench.cc | 8 ++ ...st.cc => decremental_reachability_test.cc} | 2 +- test/dynamic_reachability_test.cc | 84 +++++++++++++++++++ 8 files changed, 127 insertions(+), 67 deletions(-) rename algorithm/{roditty_zwick.h => decremental_reachability.h} (70%) create mode 100644 algorithm/dynamic_reachability.h delete mode 100644 algorithm/dynamic_roditty_zwick.h delete mode 100644 benchmark/decremental_bench.cc create mode 100644 benchmark/decremental_reachability_bench.cc create mode 100644 benchmark/dynamic_reachability_bench.cc rename test/{roditty_zwick_test.cc => decremental_reachability_test.cc} (98%) create mode 100644 test/dynamic_reachability_test.cc diff --git a/algorithm/roditty_zwick.h b/algorithm/decremental_reachability.h similarity index 70% rename from algorithm/roditty_zwick.h rename to algorithm/decremental_reachability.h index 1181649..8853b2f 100644 --- a/algorithm/roditty_zwick.h +++ b/algorithm/decremental_reachability.h @@ -1,12 +1,14 @@ -#ifndef RODITTY_ZWICK_H_ -#define RODITTY_ZWICK_H_ +#ifndef DECREMENTAL_REACHABILITY_H_ +#define DECREMENTAL_REACHABILITY_H_ + +#include "graph/digraph.h" namespace algo { template -class RodittyZwick { +class DecrementalReachability { public: - ~RodittyZwick(); + virtual ~DecrementalReachability() {}; // This method is implemented and executed by all roditty and zwick // algorithms, it constructs the data structures used in other operations @@ -17,13 +19,10 @@ public: // Remove edge e(u,v) and maintain the transitive closure matrix virtual void remove(const T& u, const T& v) =0; +protected: + Digraph G; }; -template -RodittyZwick::~RodittyZwick() { - -} - }; // namespace algo #endif diff --git a/algorithm/dynamic_reachability.h b/algorithm/dynamic_reachability.h new file mode 100644 index 0000000..0d44799 --- /dev/null +++ b/algorithm/dynamic_reachability.h @@ -0,0 +1,18 @@ +#ifndef DYNAMIC_REACHABILITY_H_ +#define DYNAMIC_REACHABILITY_H_ + +#include "algorithm/decremental_reachability.h" + +namespace algo { + +template +class DynamicReachability : public DecrementalReachability { + + // Insert edge e(u,v) and maintain the transitive closure matrix + virtual void insert(const T& u, const T& v) =0; +}; + + +} // namespace algo + +#endif \ No newline at end of file diff --git a/algorithm/dynamic_roditty_zwick.h b/algorithm/dynamic_roditty_zwick.h deleted file mode 100644 index f97b998..0000000 --- a/algorithm/dynamic_roditty_zwick.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef DYNAMIC_RODITTY_ZWICK_H_ -#ifndef DYNAMIC_RODITTY_ZWICK_H_ - -#include "algorithm/roditty_zwick.h" - -namespace algo { - -template -class DynamicRodittyZwick : public RodittyZwick { - ~DynamicRodittyZwick(); - - // Insert edge e(u,v) and maintain the transitive closure matrix - virtual void insert(const T& u, const T& v) =0; -}; - -template -inline DynamicRodittyZwick::~DynamicRodittyZwick() { - -} - -} // namespace algo - -#endif \ No newline at end of file diff --git a/benchmark/decremental_bench.cc b/benchmark/decremental_bench.cc deleted file mode 100644 index b43f352..0000000 --- a/benchmark/decremental_bench.cc +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include - -#include "algorithm/decremental_scc.h" -#include "algorithm/italiano.h" -#include "algorithm/frigioni.h" -#include "algorithm/tarjan.h" - -#include - -using namespace graph; - -TEST_SUITE("Decremental algorithms") { - - TEST_CASE("Decremental maintenance of SCCs 1") { - std::ifstream infile("resources/dag.txt"); - std::uint16_t u, v; - Digraph G; - - while (infile >> u >> v) - G.insert(u, v); - - auto SCCs = algo::Tarjan(G.adjMatrix).execute(); - - // Testing whether an scc is a 1-vertex scc which after the normalization - // has no edges, in this case we know tgat there exist no 2-vertex sccs - for (auto& scc : SCCs) { - CHECK_EQ(std::all_of(scc.adjMatrix.begin(), scc.adjMatrix.end(), - [](const auto& p) { - return p.second.size() == 0; - }), true); - } - } -} \ No newline at end of file diff --git a/benchmark/decremental_reachability_bench.cc b/benchmark/decremental_reachability_bench.cc new file mode 100644 index 0000000..3d272c2 --- /dev/null +++ b/benchmark/decremental_reachability_bench.cc @@ -0,0 +1,8 @@ +#include +#include + +using namespace graph; + +TEST_SUITE("Decremental Reachability Bench") { + +} \ No newline at end of file diff --git a/benchmark/dynamic_reachability_bench.cc b/benchmark/dynamic_reachability_bench.cc new file mode 100644 index 0000000..c02332d --- /dev/null +++ b/benchmark/dynamic_reachability_bench.cc @@ -0,0 +1,8 @@ +#include +#include + +using namespace graph; + +TEST_SUITE("Dynamic Reachability Bench") { + +} \ No newline at end of file diff --git a/test/roditty_zwick_test.cc b/test/decremental_reachability_test.cc similarity index 98% rename from test/roditty_zwick_test.cc rename to test/decremental_reachability_test.cc index b41179f..8926180 100644 --- a/test/roditty_zwick_test.cc +++ b/test/decremental_reachability_test.cc @@ -6,7 +6,7 @@ using namespace graph; -TEST_SUITE("Decremental Algorithm") { +TEST_SUITE("Decremental Reachability Test") { TEST_CASE("DecrementalSCC") { // 1 --> 2 --> 3 --> 1 diff --git a/test/dynamic_reachability_test.cc b/test/dynamic_reachability_test.cc new file mode 100644 index 0000000..ab92b6a --- /dev/null +++ b/test/dynamic_reachability_test.cc @@ -0,0 +1,84 @@ +#include + +#include "algorithm/henzinger_king.h" +#include "algorithm/king.h" + +using namespace graph; + +TEST_SUITE("Dynamic Reachability Test") { + + TEST_CASE("HenzingerKing") { + Digraph G; + G.insert(1, 2); + + algo::HenzingerKing henzingerKing(G); + henzingerKing.init(); + + SUBCASE("HenzingerKing::query") { + + } + + SUBCASE("HenzingerKing::remove") { + + } + + SUBCASE("HenzingerKing::insert") { + + } + } + + TEST_CASE("King") { + // 1 --> 2 --> 4 --> 6 --> 8 --> 9 + // 4 --> 5 --> 7 --> 8 + // 7 --> 9 + // 1 --> 3 --> 9 + // 3 --> 5 --> 6 + Digraph G; + G.insert(1, 2); + G.insert(1, 3); + G.insert(2, 4); + G.insert(3, 5); + G.insert(3, 9); + G.insert(4, 5); + G.insert(4, 6); + G.insert(5, 6); + G.insert(5, 7); + G.insert(6, 8); + G.insert(7, 8); + G.insert(7, 9); + G.insert(8, 9); + + REQUIRE_EQ(G.adjMatrix.size(), 9); + + algo::King king(G); + king.init(); + + SUBCASE("King::query") { + CHECK_EQ(king.query(1, 9), true); + CHECK_EQ(king.query(2, 8), true); + CHECK_EQ(king.query(3, 7), true); + CHECK_EQ(king.query(4, 3), false); + CHECK_EQ(king.query(5, 4), false); + CHECK_EQ(king.query(6, 1), false); + } + + SUBCASE("King::remove") { + king.remove(4, 6); + + CHECK_EQ(king.query(3, 6), true); + CHECK_EQ(king.query(4, 6), true); + + king.remove(5, 6); + + CHECK_EQ(king.query(1, 9), true); + CHECK_EQ(king.query(1, 6), false); + } + + SUBCASE("King::insert") { + king.insert(3, 10); + + CHECK_EQ(king.query(1, 10), true); + CHECK_EQ(king.query(2, 10), false); + } + } +} \ No newline at end of file