Update final step of decremental scc algorithm
This commit is contained in:
@@ -19,6 +19,9 @@ public:
|
|||||||
//
|
//
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
//
|
||||||
|
void findSCC();
|
||||||
|
|
||||||
//
|
//
|
||||||
bool query(const T& u, const T& v);
|
bool query(const T& u, const T& v);
|
||||||
|
|
||||||
@@ -41,6 +44,11 @@ private:
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void DecrementalSCC<T>::init() {
|
void DecrementalSCC<T>::init() {
|
||||||
|
findSCC();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void DecrementalSCC<T>::findSCC() {
|
||||||
auto SCCs = Tarjan<T>(G).findSCC();
|
auto SCCs = Tarjan<T>(G).findSCC();
|
||||||
|
|
||||||
for (auto& C : SCCs) {
|
for (auto& C : SCCs) {
|
||||||
@@ -73,16 +81,21 @@ void DecrementalSCC<T>::remove(const T& u, const T& v) {
|
|||||||
|
|
||||||
// If edge e(u, v) is not contained in In(w) and Out(w), do nothing
|
// If edge e(u, v) is not contained in In(w) and Out(w), do nothing
|
||||||
if (!SPT[w].first.vertices.contains(w) &&
|
if (!SPT[w].first.vertices.contains(w) &&
|
||||||
!SPT[w].second.vertices.contains(w))
|
!SPT[w].second.vertices.contains(w)){
|
||||||
|
connection[w].adjMatrix[u].erase(v);
|
||||||
|
G.adjMatrix[u].erase(v);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
// Update In(w) and Out(w)
|
// Update In(w) and Out(w)
|
||||||
|
connection[w].adjMatrix[u].erase(v);
|
||||||
|
G.adjMatrix[u].erase(v);
|
||||||
auto inTree = BFS<T>(connection[w]).run(w);
|
auto inTree = BFS<T>(connection[w]).run(w);
|
||||||
SPT[w] = std::make_pair(inTree, inTree.reverse());
|
SPT[w] = std::make_pair(inTree, inTree.reverse());
|
||||||
|
|
||||||
|
// If a SCC is broken, compute all SCCs again
|
||||||
if (!SPT[w].second.vertices.contains(u) ||
|
if (!SPT[w].second.vertices.contains(u) ||
|
||||||
!SPT[w].first.vertices.contains(v)) {
|
!SPT[w].first.vertices.contains(v)) {
|
||||||
// TODO: Decompose C into C1, C2, ... Ck
|
auto SCCs = Tarjan<T>(G).findSCC();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user