From cbaf50d4019e66ac9e1ebfc6e4803da7c4a584a8 Mon Sep 17 00:00:00 2001 From: stefiosif Date: Mon, 26 Sep 2022 12:23:49 +0300 Subject: [PATCH] Fix TC to update correctly, and move all to-hook children on the stack --- algorithm/italiano.h | 18 ++++++++---------- algorithm/king.h | 2 +- test/decremental_reachability_test.cc | 7 ++++++- test/dynamic_reachability_test.cc | 7 ++++++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/algorithm/italiano.h b/algorithm/italiano.h index 806ca5d..32e3f40 100644 --- a/algorithm/italiano.h +++ b/algorithm/italiano.h @@ -4,6 +4,8 @@ #include "algorithm/decremental_reachability.h" #include "graph/breadth_first_tree.h" +#include + using namespace graph; namespace algo { @@ -61,6 +63,7 @@ bool Italiano::query(const T& u, const T& v) { template void Italiano::remove(const T& u, const T& v) { + //TRYCATCH if (!this->G.adjMatrix[u].contains(v)) return; std::map> H; for (const auto& w : this->G.vertices()) { @@ -72,35 +75,30 @@ void Italiano::remove(const T& u, const T& v) { for (const auto& c : E[v].out) H[w].push(c); } + RT[w].adjMatrix[u].erase(v); } } - E[u].out.erase(v); E[v].inc.erase(u); this->G.remove(u, v); for (const auto& z : this->G.vertices()) { - RT[z].adjMatrix[u].erase(v); while (H[z].size() > 0) { - auto& h = H[z].top(); + const auto& h = H[z].top(); bool found = false; + for (const auto& i : E[h].inc) { if (RT[z].contains(z, i)) { RT[z].adjMatrix[i].insert(h); - // found = true; break; } } - // H[z].pop(); - // if (!found) { - TC[u][v] = false; + TC[z][h] = false; for (const auto& o : E[h].out) { - if (RT[z].contains(z, o)) { - H[z].push(o); - } + H[z].push(o); } } } diff --git a/algorithm/king.h b/algorithm/king.h index 6993558..d23991b 100644 --- a/algorithm/king.h +++ b/algorithm/king.h @@ -57,7 +57,7 @@ template void King::remove(const T& u, const T& v) { this->G.remove(u, v); for (const auto& w : this->G.vertices()) { - In[w].remove(u, v); + In[w].remove(v, u); Out[w].remove(u, v); } } diff --git a/test/decremental_reachability_test.cc b/test/decremental_reachability_test.cc index 658d561..ca41977 100644 --- a/test/decremental_reachability_test.cc +++ b/test/decremental_reachability_test.cc @@ -109,9 +109,14 @@ TEST_SUITE("Decremental Reachability Test") { CHECK_EQ(italiano.query(1, 9), true); CHECK_EQ(italiano.query(1, 6), false); + + italiano.remove(1, 2); + + CHECK_EQ(italiano.query(1, 5), true); + CHECK_EQ(italiano.query(1, 2), false); } } - + TEST_CASE("Frigioni") { // 1 --> 2 --> 4 --> 6 --> 8 --> 9 --> 5 // 4 --> 5 --> 7 --> 8 diff --git a/test/dynamic_reachability_test.cc b/test/dynamic_reachability_test.cc index ab92b6a..adbebb7 100644 --- a/test/dynamic_reachability_test.cc +++ b/test/dynamic_reachability_test.cc @@ -67,11 +67,16 @@ TEST_SUITE("Dynamic Reachability Test") { 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); + + king.remove(1, 2); + + CHECK_EQ(king.query(1, 5), true); + CHECK_EQ(king.query(1, 2), false); } SUBCASE("King::insert") {