Make RodittyZwick class abstract
This commit is contained in:
61
algorithm/decremental_maintenance.h
Normal file
61
algorithm/decremental_maintenance.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#ifndef DECREMENTAL_MAINTENANCE_H_
|
||||||
|
#define DECREMENTAL_MAINTENANCE_H_
|
||||||
|
|
||||||
|
#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 DecrementalMaintenance : public RodittyZwick<T> {
|
||||||
|
public:
|
||||||
|
DecrementalMaintenance(Digraph<T> G) : G(G) {}
|
||||||
|
|
||||||
|
//
|
||||||
|
void init();
|
||||||
|
|
||||||
|
//
|
||||||
|
void query();
|
||||||
|
|
||||||
|
//
|
||||||
|
void remove();
|
||||||
|
private:
|
||||||
|
Digraph<T> G;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void DecrementalMaintenance<T>::init() {
|
||||||
|
std::map<T, T> A;
|
||||||
|
Tarjan<T> tarjan(G);
|
||||||
|
|
||||||
|
auto sccs = tarjan.run();
|
||||||
|
|
||||||
|
for (auto& scc : sccs) {
|
||||||
|
const auto& root = scc.representative();
|
||||||
|
BFS<T> bfs(scc);
|
||||||
|
auto spt = bfs.run(root);
|
||||||
|
for (const auto& vertex : scc.vertices) {
|
||||||
|
A[vertex] = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline void DecrementalMaintenance<T>::query()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline void DecrementalMaintenance<T>::remove()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}; // namespace algo
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,52 +1,27 @@
|
|||||||
#ifndef RODITTY_ZWICK_H_
|
#ifndef RODITTY_ZWICK_H_
|
||||||
#define RODITTY_ZWICK_H_
|
#define RODITTY_ZWICK_H_
|
||||||
|
|
||||||
#include "graph/digraph.h"
|
|
||||||
#include "graph/scc.h"
|
|
||||||
#include "algorithm/tarjan.h"
|
|
||||||
#include "algorithm/bfs.h"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace graph;
|
using namespace graph;
|
||||||
|
|
||||||
namespace algo {
|
namespace algo {
|
||||||
|
|
||||||
// A randomized decremental algorithm for maintaining SCCs
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class RodittyZwick {
|
class RodittyZwick {
|
||||||
public:
|
public:
|
||||||
RodittyZwick(Digraph<T> G) : G(G) {}
|
~RodittyZwick();
|
||||||
|
|
||||||
//
|
//
|
||||||
void sccDecrementalMaintenance();
|
virtual void init() =0;
|
||||||
|
|
||||||
//
|
//
|
||||||
void tcDecrementalMaintenance();
|
virtual void query() =0;
|
||||||
private:
|
|
||||||
Digraph<T> G;
|
//
|
||||||
|
virtual void remove() =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void RodittyZwick<T>::sccDecrementalMaintenance() {
|
RodittyZwick<T>::~RodittyZwick() {
|
||||||
std::map<T, T> A;
|
|
||||||
Tarjan<T> tarjan(G);
|
|
||||||
|
|
||||||
auto sccs = tarjan.run();
|
|
||||||
|
|
||||||
for (auto& scc : sccs) {
|
|
||||||
const auto& root = scc.representative();
|
|
||||||
BFS<T> bfs(scc);
|
|
||||||
auto spt = bfs.run(root);
|
|
||||||
for (const auto& vertex : scc.vertices) {
|
|
||||||
A[vertex] = root;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void RodittyZwick<T>::tcDecrementalMaintenance() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "algorithm/tarjan.h"
|
#include "algorithm/tarjan.h"
|
||||||
#include "algorithm/bfs.h"
|
#include "algorithm/bfs.h"
|
||||||
#include "algorithm/roditty_zwick.h"
|
#include "algorithm/roditty_zwick.h"
|
||||||
|
#include "algorithm/decremental_maintenance.h"
|
||||||
|
|
||||||
using namespace graph;
|
using namespace graph;
|
||||||
|
|
||||||
@@ -130,7 +131,7 @@ TEST_SUITE("Algorithm") {
|
|||||||
G.insert(6, 3);
|
G.insert(6, 3);
|
||||||
G.insert(7, 2);
|
G.insert(7, 2);
|
||||||
|
|
||||||
algo::RodittyZwick<std::uint16_t> rz(G);
|
algo::DecrementalMaintenance<std::uint16_t> rz(G);
|
||||||
rz.sccDecrementalMaintenance();
|
rz.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user