Fix includes and add some comments

This commit is contained in:
stefiosif
2022-07-12 14:42:29 +03:00
parent e7ad824116
commit 601f80c8d4
7 changed files with 31 additions and 64 deletions

View File

@@ -1,11 +1,10 @@
#ifndef 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/tarjan.h"
#include "algorithm/breadth_first_search.h"
#include "tree/breadth_first_tree.h"
using namespace graph;
@@ -16,16 +15,12 @@ class DecrementalSCC : public RodittyZwick<T> {
public:
DecrementalSCC(Digraph<T> G) : G(G) {}
//
void init();
//
void findSCC();
//
bool query(const T& u, const T& v);
//
void remove(const T& u, const T& v);
private:
Digraph<T> G;
@@ -49,13 +44,13 @@ void DecrementalSCC<T>::init() {
template<typename T>
void DecrementalSCC<T>::findSCC() {
auto SCCs = Tarjan<T>(G).findSCC();
auto SCCs = Tarjan<T>(G).execute();
for (auto& C : SCCs) {
const auto& w = C.representative();
// 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());
// 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)
connection[w].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());
// If a SCC is broken, compute all SCCs again

View File

@@ -1,11 +1,14 @@
#ifndef 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/tarjan.h"
#include "algorithm/breadth_first_search.h"
#include "tree/breadth_first_tree.h"
#include <forward_list>
using namespace graph;
namespace algo {
@@ -14,14 +17,21 @@ class DecrementalTC : public RodittyZwick<T> {
public:
DecrementalTC(Digraph<T> G) : G(G) {}
//
void init();
//
bool query(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;
};

View File

@@ -1,31 +1,16 @@
#ifndef 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"
using namespace graph;
namespace algo {
template<typename T>
class DynamicReachability : public RodittyZwick {
~DynamicReachability();
//
virtual void init() =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;
// Insert edge e(u,v) and maintain the transitive closure matrix
virtual void insert(const T& u, const T& v) =0;
};
template<typename T>

View File

@@ -1,8 +1,6 @@
#ifndef RODITTY_ZWICK_H_
#define RODITTY_ZWICK_H_
using namespace graph;
namespace algo {
template<typename T>
@@ -10,13 +8,14 @@ class RodittyZwick {
public:
~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;
//
// Answer if vertex v is reachable from vertex u
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;
};

View File

@@ -1,7 +1,6 @@
#ifndef TARJAN_H_
#define TARJAN_H_
#include "graph/digraph.h"
#include "graph/scc.h"
#include <stack>
@@ -16,10 +15,8 @@ class Tarjan {
public:
Tarjan(Digraph<T> G) : G(G) {}
//
std::vector<SCC<T>> findSCC();
std::vector<SCC<T>> execute();
//
void strongConnect(const T& v);
private:
// Necessary info about vertices when running Tarjan's algorithm
@@ -68,7 +65,7 @@ void Tarjan<T>::strongConnect(const T& v) {
}
template<typename T>
std::vector<SCC<T>> Tarjan<T>::findSCC() {
std::vector<SCC<T>> Tarjan<T>::execute() {
for (const auto& v : G.vertices) {
if (p[v].index == -1) {
strongConnect(v);