Split frigioni and italiano algorithms and add query function

This commit is contained in:
stefiosif
2022-08-08 22:20:32 +03:00
parent dd71ab75b6
commit d459fe9df6
3 changed files with 121 additions and 63 deletions

View File

@@ -1,63 +0,0 @@
#ifndef DECREMENTAL_TC_H_
#define DECREMENTAL_TC_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 {
template<typename T>
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:
Digraph<T> G;
// Every vertex u has a pointer C(u) to the component containing it
std::map<T, SCC<T>> C;
// The aggregation of edges each component contains
struct LLE {
std::forward_list<T> Ein;
std::forward_list<T> Eout;
std::forward_list<T> Eint;
};
std::map<SCC<T>, LLE> E;
// Connect each component with a tree of all reachable components
std::map<SCC<T>, std::set<SCC<T>>> TC;
};
template<typename T>
void DecrementalTC<T>::init() {
}
template<typename T>
bool DecrementalTC<T>::query(const T& u, const T& v) {
return false;
}
template<typename T>
void DecrementalTC<T>::remove(const T& u, const T& v) {
}
} // namespace algo
#endif

61
algorithm/frigioni.h Normal file
View File

@@ -0,0 +1,61 @@
#ifndef FRIGIONI_H_
#define FRIGIONI_H_
#include "algorithm/roditty_zwick.h"
#include "algorithm/tarjan.h"
#include "tree/breadth_first_tree.h"
#include <forward_list>
using namespace graph;
using namespace tree;
namespace algo {
template<typename T>
class Frigioni : public RodittyZwick<T> {
public:
Frigioni(Digraph<T> G) : G(G) {}
void init();
bool query(const T& u, const T& v);
void remove(const T& u, const T& v);
private:
Digraph<T> G;
// Connect each vertex with its representative SCC
std::map<T, SCC<T>> TC;
// Reachability trees
std::map<SCC<T>, std::set<SCC<T>>> RT;
// Incoming / Outgoing / Internal edges
struct Edges {
std::forward_list<T> Ein;
std::forward_list<T> Eout;
std::forward_list<T> Eint;
};
std::map<SCC<T>, Edges> E;
};
template<typename T>
void Frigioni<T>::init() {
}
template<typename T>
bool Frigioni<T>::query(const T& u, const T& v) {
return TC[u] == TC[v];
}
template<typename T>
void Frigioni<T>::remove(const T& u, const T& v) {
}
} // namespace algo
#endif

60
algorithm/italiano.h Normal file
View File

@@ -0,0 +1,60 @@
#ifndef ITALIANO_H_
#define ITALIANO_H_
#include "algorithm/roditty_zwick.h"
#include "algorithm/tarjan.h"
#include "tree/breadth_first_tree.h"
#include <forward_list>
using namespace graph;
using namespace tree;
namespace algo {
template<typename T>
class Italiano : public RodittyZwick<T> {
public:
Italiano(Digraph<T> G) : G(G) {}
void init();
bool query(const T& u, const T& v);
void remove(const T& u, const T& v);
private:
Digraph<T> G;
// Connect each vertex with its representative SCC
std::map<T, SCC<T>> TC;
// Reachability trees
std::map<T, std::set<T>> RT;
// Incoming / Outgoing edges
struct Edges {
std::forward_list<T> Ein;
std::forward_list<T> Eout;
};
std::map<SCC<T>, Edges> E;
};
template<typename T>
void Italiano<T>::init() {
}
template<typename T>
bool Italiano<T>::query(const T& u, const T& v) {
return TC[u] == TC[v];
}
template<typename T>
void Italiano<T>::remove(const T& u, const T& v) {
}
} // namespace algo
#endif