Update decremental algorithms according to project structure changes
This commit is contained in:
@@ -1,32 +1,31 @@
|
||||
#ifndef FRIGIONI_H_
|
||||
#define FRIGIONI_H_
|
||||
|
||||
#include "algorithm/decremental_reachability.h"
|
||||
#include "algorithm/roditty_zwick.h"
|
||||
#include "algorithm/tarjan.h"
|
||||
#include "graph/breadth_first_tree.h"
|
||||
#include "algorithm/decremental_scc.h"
|
||||
|
||||
#include <forward_list>
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
|
||||
using namespace graph;
|
||||
|
||||
namespace algo {
|
||||
|
||||
template<typename T>
|
||||
class Frigioni : public RodittyZwick<T> {
|
||||
class Frigioni : public DecrementalReachability<T> {
|
||||
public:
|
||||
Frigioni(Digraph<T> G) : G(G) {}
|
||||
Frigioni() = default;
|
||||
|
||||
void init();
|
||||
Frigioni(Digraph<T> G) { this->G = G; }
|
||||
|
||||
bool query(const T& u, const T& v);
|
||||
//
|
||||
void init() override;
|
||||
|
||||
void remove(const T& u, const T& v);
|
||||
//
|
||||
bool query(const T& u, const T& v) override;
|
||||
|
||||
//
|
||||
void remove(const T& u, const T& v) override;
|
||||
private:
|
||||
Digraph<T> G;
|
||||
|
||||
// Transitive closure matrix, used to answer reachability queries in O(1)
|
||||
std::map<T, std::map<T, bool>> TC;
|
||||
|
||||
@@ -36,24 +35,29 @@ private:
|
||||
// Each scc's representative vertex reachability tree
|
||||
std::map<T, BreadthFirstTree<T>> RT;
|
||||
|
||||
// Incoming / Outgoing / Internal edges
|
||||
// Incoming / Outgoing / Internal edges of each SCC
|
||||
// Maps each SCC representative with struct Edges
|
||||
struct Edges {
|
||||
std::set<std::pair<T, T>> in;
|
||||
std::set<std::pair<T, T>> inc;
|
||||
std::set<std::pair<T, T>> out;
|
||||
};
|
||||
std::map<T, Edges> E;
|
||||
|
||||
// Decremental maintenance of strongly connected components
|
||||
RodittyZwick<T> decremental;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void Frigioni<T>::init() {
|
||||
auto SCCs = Tarjan<T>(G.adjMatrix).execute();
|
||||
|
||||
auto SCCs = Tarjan<T>(this->G.adjMatrix).execute();
|
||||
decremental = RodittyZwick<T>(this->G);
|
||||
decremental.init();
|
||||
|
||||
for (auto& scc : SCCs) {
|
||||
RT[scc.id] = BreadthFirstTree<T>(G, scc.id);
|
||||
for (const auto& u : G.vertices()) {
|
||||
C[u] = scc;
|
||||
for (const auto& v : G.adjMatrix[u]) {
|
||||
RT[scc.id] = BreadthFirstTree<T>(this->G, scc.id);
|
||||
for (const auto& u : this->G.vertices()) {
|
||||
for (const auto& v : this->G.adjMatrix[u]) {
|
||||
TC[u][v] = false;
|
||||
if (scc.member(u)) {
|
||||
if (scc.member(v))
|
||||
@@ -67,7 +71,7 @@ void Frigioni<T>::init() {
|
||||
}
|
||||
}
|
||||
for (auto& scc : SCCs) {
|
||||
for (const auto& u : G.vertices()) {
|
||||
for (const auto& u : this->G.vertices()) {
|
||||
if (scc.member(u)) {
|
||||
for (const auto& v : RT[scc.id].vertices()) {
|
||||
TC[u][v] = true;
|
||||
|
||||
Reference in New Issue
Block a user