Fix includes and add some comments
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
#ifndef DECREMENTAL_SCC_H_
|
#ifndef DECREMENTAL_SCC_H_
|
||||||
#define DECREMENTAL_SCC_H_
|
#define DECREMENTAL_SCC_H_
|
||||||
|
|
||||||
#include "graph/digraph.h"
|
|
||||||
#include "graph/scc.h"
|
|
||||||
#include "algorithm/tarjan.h"
|
|
||||||
#include "algorithm/bfs.h"
|
|
||||||
#include "algorithm/roditty_zwick.h"
|
#include "algorithm/roditty_zwick.h"
|
||||||
|
#include "algorithm/tarjan.h"
|
||||||
|
#include "algorithm/breadth_first_search.h"
|
||||||
|
#include "tree/breadth_first_tree.h"
|
||||||
|
|
||||||
using namespace graph;
|
using namespace graph;
|
||||||
|
|
||||||
@@ -16,16 +15,12 @@ class DecrementalSCC : public RodittyZwick<T> {
|
|||||||
public:
|
public:
|
||||||
DecrementalSCC(Digraph<T> G) : G(G) {}
|
DecrementalSCC(Digraph<T> G) : G(G) {}
|
||||||
|
|
||||||
//
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
//
|
|
||||||
void findSCC();
|
void findSCC();
|
||||||
|
|
||||||
//
|
|
||||||
bool query(const T& u, const T& v);
|
bool query(const T& u, const T& v);
|
||||||
|
|
||||||
//
|
|
||||||
void remove(const T& u, const T& v);
|
void remove(const T& u, const T& v);
|
||||||
private:
|
private:
|
||||||
Digraph<T> G;
|
Digraph<T> G;
|
||||||
@@ -49,13 +44,13 @@ void DecrementalSCC<T>::init() {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void DecrementalSCC<T>::findSCC() {
|
void DecrementalSCC<T>::findSCC() {
|
||||||
auto SCCs = Tarjan<T>(G).findSCC();
|
auto SCCs = Tarjan<T>(G).execute();
|
||||||
|
|
||||||
for (auto& C : SCCs) {
|
for (auto& C : SCCs) {
|
||||||
const auto& w = C.representative();
|
const auto& w = C.representative();
|
||||||
|
|
||||||
// Create shortest-paths out-tree/in-tree
|
// Create shortest-paths out-tree/in-tree
|
||||||
auto outTree = Digraph<T>(BFS<T>(C).run(w));
|
auto outTree = Digraph<T>(BreadthFirstSearch<T>(C).execute(w));
|
||||||
SPT[w] = std::make_pair(outTree, outTree.reverse());
|
SPT[w] = std::make_pair(outTree, outTree.reverse());
|
||||||
|
|
||||||
// Update A with current SCCs vertices
|
// Update A with current SCCs vertices
|
||||||
@@ -89,7 +84,7 @@ void DecrementalSCC<T>::remove(const T& u, const T& v) {
|
|||||||
// Update In(w) and Out(w)
|
// Update In(w) and Out(w)
|
||||||
connection[w].adjMatrix[u].erase(v);
|
connection[w].adjMatrix[u].erase(v);
|
||||||
G.adjMatrix[u].erase(v);
|
G.adjMatrix[u].erase(v);
|
||||||
auto inTree = Digraph<T>(BFS<T>(connection[w]).run(w));
|
auto inTree = Digraph<T>(BreadthFirstSearch<T>(connection[w]).execute(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 a SCC is broken, compute all SCCs again
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
#ifndef DECREMENTAL_TC_H_
|
#ifndef DECREMENTAL_TC_H_
|
||||||
#define DECREMENTAL_TC_H_
|
#define DECREMENTAL_TC_H_
|
||||||
|
|
||||||
#include "graph/digraph.h"
|
|
||||||
#include "graph/scc.h"
|
|
||||||
#include "algorithm/tarjan.h"
|
|
||||||
#include "algorithm/bfs.h"
|
|
||||||
#include "algorithm/roditty_zwick.h"
|
#include "algorithm/roditty_zwick.h"
|
||||||
|
#include "algorithm/tarjan.h"
|
||||||
|
#include "algorithm/breadth_first_search.h"
|
||||||
|
#include "tree/breadth_first_tree.h"
|
||||||
|
|
||||||
|
#include <forward_list>
|
||||||
|
|
||||||
|
using namespace graph;
|
||||||
|
|
||||||
namespace algo {
|
namespace algo {
|
||||||
|
|
||||||
@@ -14,14 +17,21 @@ class DecrementalTC : public RodittyZwick<T> {
|
|||||||
public:
|
public:
|
||||||
DecrementalTC(Digraph<T> G) : G(G) {}
|
DecrementalTC(Digraph<T> G) : G(G) {}
|
||||||
|
|
||||||
//
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
//
|
|
||||||
bool query(const T& u, const T& v);
|
bool query(const T& u, const T& v);
|
||||||
|
|
||||||
//
|
|
||||||
void remove(const T& u, const T& v);
|
void remove(const T& u, const T& v);
|
||||||
|
private:
|
||||||
|
// Every vertex u has a pointer C(u) to the component containing it
|
||||||
|
std::map<T, T> vc;
|
||||||
|
|
||||||
|
// For every component C, the algorithm maintains three linked lists
|
||||||
|
// Ein(C), Eout(C), and Eint(C) of the incoming, outgoing, and the internal
|
||||||
|
// edges of the component C
|
||||||
|
std::forward_list<T> Ein;
|
||||||
|
std::forward_list<T> Eout;
|
||||||
|
std::forward_list<T> Eint;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,16 @@
|
|||||||
#ifndef DYNAMIC_REACHABILITY_
|
#ifndef DYNAMIC_REACHABILITY_
|
||||||
#define DYNAMIC_REACHABILITY_
|
#define DYNAMIC_REACHABILITY_
|
||||||
|
|
||||||
#include "graph/digraph.h"
|
|
||||||
#include "graph/scc.h"
|
|
||||||
#include "algorithm/tarjan.h"
|
|
||||||
#include "algorithm/bfs.h"
|
|
||||||
#include "algorithm/roditty_zwick.h"
|
#include "algorithm/roditty_zwick.h"
|
||||||
|
|
||||||
using namespace graph;
|
|
||||||
|
|
||||||
namespace algo {
|
namespace algo {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class DynamicReachability : public RodittyZwick {
|
class DynamicReachability : public RodittyZwick {
|
||||||
~DynamicReachability();
|
~DynamicReachability();
|
||||||
|
|
||||||
//
|
// Insert edge e(u,v) and maintain the transitive closure matrix
|
||||||
virtual void init() =0;
|
virtual void insert(const T& u, const T& v) =0;
|
||||||
|
|
||||||
//
|
|
||||||
virtual bool query(const T& u, const T& v) =0;
|
|
||||||
|
|
||||||
//
|
|
||||||
virtual void remove(const T& u, const T& v) =0;
|
|
||||||
|
|
||||||
//
|
|
||||||
virtual void insert() =0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#ifndef RODITTY_ZWICK_H_
|
#ifndef RODITTY_ZWICK_H_
|
||||||
#define RODITTY_ZWICK_H_
|
#define RODITTY_ZWICK_H_
|
||||||
|
|
||||||
using namespace graph;
|
|
||||||
|
|
||||||
namespace algo {
|
namespace algo {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -10,13 +8,14 @@ class RodittyZwick {
|
|||||||
public:
|
public:
|
||||||
~RodittyZwick();
|
~RodittyZwick();
|
||||||
|
|
||||||
//
|
// This method is implemented and executed by all roditty and zwick
|
||||||
|
// algorithms, it constructs the data structures used in other operations
|
||||||
virtual void init() =0;
|
virtual void init() =0;
|
||||||
|
|
||||||
//
|
// Answer if vertex v is reachable from vertex u
|
||||||
virtual bool query(const T& u, const T& v) =0;
|
virtual bool query(const T& u, const T& v) =0;
|
||||||
|
|
||||||
//
|
// Remove edge e(u,v) and maintain the transitive closure matrix
|
||||||
virtual void remove(const T& u, const T& v) =0;
|
virtual void remove(const T& u, const T& v) =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef TARJAN_H_
|
#ifndef TARJAN_H_
|
||||||
#define TARJAN_H_
|
#define TARJAN_H_
|
||||||
|
|
||||||
#include "graph/digraph.h"
|
|
||||||
#include "graph/scc.h"
|
#include "graph/scc.h"
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
@@ -16,10 +15,8 @@ class Tarjan {
|
|||||||
public:
|
public:
|
||||||
Tarjan(Digraph<T> G) : G(G) {}
|
Tarjan(Digraph<T> G) : G(G) {}
|
||||||
|
|
||||||
//
|
std::vector<SCC<T>> execute();
|
||||||
std::vector<SCC<T>> findSCC();
|
|
||||||
|
|
||||||
//
|
|
||||||
void strongConnect(const T& v);
|
void strongConnect(const T& v);
|
||||||
private:
|
private:
|
||||||
// Necessary info about vertices when running Tarjan's algorithm
|
// Necessary info about vertices when running Tarjan's algorithm
|
||||||
@@ -68,7 +65,7 @@ void Tarjan<T>::strongConnect(const T& v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::vector<SCC<T>> Tarjan<T>::findSCC() {
|
std::vector<SCC<T>> Tarjan<T>::execute() {
|
||||||
for (const auto& v : G.vertices) {
|
for (const auto& v : G.vertices) {
|
||||||
if (p[v].index == -1) {
|
if (p[v].index == -1) {
|
||||||
strongConnect(v);
|
strongConnect(v);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ private:
|
|||||||
// Each SCC has a representative vertex that helps
|
// Each SCC has a representative vertex that helps
|
||||||
// answer strong connectivity queries in O(1) time
|
// answer strong connectivity queries in O(1) time
|
||||||
T proxy;
|
T proxy;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace graph
|
}; // namespace graph
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef TRANSITIVE_CLOSURE_H_
|
|
||||||
#define TRANSITIVE_CLOSURE_H_
|
|
||||||
|
|
||||||
#include "digraph.h"
|
|
||||||
|
|
||||||
namespace graph {
|
|
||||||
|
|
||||||
// Transitive closure matrix class to answer reachability queries
|
|
||||||
template<typename T>
|
|
||||||
class TransitiveClosure {
|
|
||||||
public:
|
|
||||||
TransitiveClosure() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace graph
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user