Fix TC to update correctly, and move all to-hook children on the stack

This commit is contained in:
stefiosif
2022-09-26 12:23:49 +03:00
parent 14a61c92e9
commit cbaf50d401
4 changed files with 21 additions and 13 deletions

View File

@@ -4,6 +4,8 @@
#include "algorithm/decremental_reachability.h" #include "algorithm/decremental_reachability.h"
#include "graph/breadth_first_tree.h" #include "graph/breadth_first_tree.h"
#include <stack>
using namespace graph; using namespace graph;
namespace algo { namespace algo {
@@ -61,6 +63,7 @@ bool Italiano<T>::query(const T& u, const T& v) {
template<typename T> template<typename T>
void Italiano<T>::remove(const T& u, const T& v) { void Italiano<T>::remove(const T& u, const T& v) {
//TRYCATCH if (!this->G.adjMatrix[u].contains(v)) return;
std::map<T, std::stack<T>> H; std::map<T, std::stack<T>> H;
for (const auto& w : this->G.vertices()) { for (const auto& w : this->G.vertices()) {
@@ -72,40 +75,35 @@ void Italiano<T>::remove(const T& u, const T& v) {
for (const auto& c : E[v].out) for (const auto& c : E[v].out)
H[w].push(c); H[w].push(c);
} }
RT[w].adjMatrix[u].erase(v);
} }
} }
E[u].out.erase(v); E[u].out.erase(v);
E[v].inc.erase(u); E[v].inc.erase(u);
this->G.remove(u, v); this->G.remove(u, v);
for (const auto& z : this->G.vertices()) { for (const auto& z : this->G.vertices()) {
RT[z].adjMatrix[u].erase(v);
while (H[z].size() > 0) { while (H[z].size() > 0) {
auto& h = H[z].top(); const auto& h = H[z].top();
bool found = false; bool found = false;
for (const auto& i : E[h].inc) { for (const auto& i : E[h].inc) {
if (RT[z].contains(z, i)) { if (RT[z].contains(z, i)) {
RT[z].adjMatrix[i].insert(h); RT[z].adjMatrix[i].insert(h);
//
found = true; found = true;
break; break;
} }
} }
//
H[z].pop(); H[z].pop();
//
if (!found) { if (!found) {
TC[u][v] = false; TC[z][h] = false;
for (const auto& o : E[h].out) { for (const auto& o : E[h].out) {
if (RT[z].contains(z, o)) {
H[z].push(o); H[z].push(o);
} }
} }
} }
} }
} }
}
} // namespace algo } // namespace algo

View File

@@ -57,7 +57,7 @@ template<typename T>
void King<T>::remove(const T& u, const T& v) { void King<T>::remove(const T& u, const T& v) {
this->G.remove(u, v); this->G.remove(u, v);
for (const auto& w : this->G.vertices()) { for (const auto& w : this->G.vertices()) {
In[w].remove(u, v); In[w].remove(v, u);
Out[w].remove(u, v); Out[w].remove(u, v);
} }
} }

View File

@@ -109,6 +109,11 @@ TEST_SUITE("Decremental Reachability Test") {
CHECK_EQ(italiano.query(1, 9), true); CHECK_EQ(italiano.query(1, 9), true);
CHECK_EQ(italiano.query(1, 6), false); 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);
} }
} }

View File

@@ -72,6 +72,11 @@ TEST_SUITE("Dynamic Reachability Test") {
CHECK_EQ(king.query(1, 9), true); CHECK_EQ(king.query(1, 9), true);
CHECK_EQ(king.query(1, 6), false); 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") { SUBCASE("King::insert") {