Split graph folder into graph and tree

This commit is contained in:
stefiosif
2022-07-10 15:32:13 +03:00
parent 3fa6935b84
commit b9cd1a1cbd
11 changed files with 176 additions and 25 deletions

View File

@@ -12,10 +12,12 @@ namespace algo {
template<typename T>
class BFS {
public:
BFS(Graph<T> G) : G(G) {}
BFS() = default;
BFS(Digraph<T> G) : G(G) {}
//
Digraph<T> run(const T& root);
std::map<T, std::set<T>> run(const T& root);
// Initialize the lookup table that is used to
// show which vertices have been traversed
@@ -34,7 +36,7 @@ std::map<T, bool> BFS<T>::initExplore() {
}
template<typename T>
Digraph<T> BFS<T>::run(const T& root) {
std::map<T, std::set<T>> BFS<T>::run(const T& root) {
std::map<T, std::set<T>> tree;
std::map<T, bool> graphExplore = initExplore();
std::queue<T> Q;
@@ -54,7 +56,7 @@ Digraph<T> BFS<T>::run(const T& root) {
}
}
return Digraph<T>(tree);
return tree;
}
} // namespace algo

View File

@@ -55,7 +55,7 @@ void DecrementalSCC<T>::findSCC() {
const auto& w = C.representative();
// Create shortest-paths out-tree/in-tree
auto outTree = BFS<T>(C).run(w);
auto outTree = Digraph<T>(BFS<T>(C).run(w));
SPT[w] = std::make_pair(outTree, outTree.reverse());
// Update A with current SCCs vertices
@@ -89,13 +89,13 @@ void DecrementalSCC<T>::remove(const T& u, const T& v) {
// 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 = Digraph<T>(BFS<T>(connection[w]).run(w));
SPT[w] = std::make_pair(inTree, inTree.reverse());
// If a SCC is broken, compute all SCCs again
if (!SPT[w].second.vertices.contains(u) ||
!SPT[w].first.vertices.contains(v)) {
auto SCCs = Tarjan<T>(G).findSCC();
findSCC();
}
}