Refactor file names to better understand inheritance of the skeleton of RZ algorithms

This commit is contained in:
stefiosif
2022-09-25 17:27:21 +03:00
parent ffc3ae4ec3
commit 95e7d56c1e
8 changed files with 127 additions and 67 deletions

View File

@@ -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<typename T>
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<T> G;
};
template<typename T>
RodittyZwick<T>::~RodittyZwick() {
}
}; // namespace algo
#endif

View File

@@ -0,0 +1,18 @@
#ifndef DYNAMIC_REACHABILITY_H_
#define DYNAMIC_REACHABILITY_H_
#include "algorithm/decremental_reachability.h"
namespace algo {
template<typename T>
class DynamicReachability : public DecrementalReachability<T> {
// Insert edge e(u,v) and maintain the transitive closure matrix
virtual void insert(const T& u, const T& v) =0;
};
} // namespace algo
#endif

View File

@@ -1,23 +0,0 @@
#ifndef DYNAMIC_RODITTY_ZWICK_H_
#ifndef DYNAMIC_RODITTY_ZWICK_H_
#include "algorithm/roditty_zwick.h"
namespace algo {
template<typename T>
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<typename T>
inline DynamicRodittyZwick<T>::~DynamicRodittyZwick() {
}
} // namespace algo
#endif

View File

@@ -1,34 +0,0 @@
#include <src/include/nanobench.h>
#include <doctest/doctest.h>
#include "algorithm/decremental_scc.h"
#include "algorithm/italiano.h"
#include "algorithm/frigioni.h"
#include "algorithm/tarjan.h"
#include <fstream>
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<std::uint16_t> G;
while (infile >> u >> v)
G.insert(u, v);
auto SCCs = algo::Tarjan<std::uint16_t>(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);
}
}
}

View File

@@ -0,0 +1,8 @@
#include <src/include/nanobench.h>
#include <doctest/doctest.h>
using namespace graph;
TEST_SUITE("Decremental Reachability Bench") {
}

View File

@@ -0,0 +1,8 @@
#include <src/include/nanobench.h>
#include <doctest/doctest.h>
using namespace graph;
TEST_SUITE("Dynamic Reachability Bench") {
}

View File

@@ -6,7 +6,7 @@
using namespace graph;
TEST_SUITE("Decremental Algorithm") {
TEST_SUITE("Decremental Reachability Test") {
TEST_CASE("DecrementalSCC") {
// 1 --> 2 --> 3 --> 1

View File

@@ -0,0 +1,84 @@
#include <doctest/doctest.h>
#include "algorithm/henzinger_king.h"
#include "algorithm/king.h"
using namespace graph;
TEST_SUITE("Dynamic Reachability Test") {
TEST_CASE("HenzingerKing") {
Digraph<std::uint16_t> G;
G.insert(1, 2);
algo::HenzingerKing<std::uint16_t> 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<std::uint16_t> 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<std::uint16_t> 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);
}
}
}