Add dynamic reachability benchmark for dags and general graphs
This commit is contained in:
@@ -1,8 +1,97 @@
|
||||
#include <src/include/nanobench.h>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include "algorithm/king.h"
|
||||
#include "algorithm/henzinger_king.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
#include <fstream>
|
||||
|
||||
using namespace graph;
|
||||
|
||||
TEST_SUITE("Dynamic Reachability Bench") {
|
||||
ankerl::nanobench::Bench dynBench;
|
||||
|
||||
TEST_CASE("King") {
|
||||
std::ifstream fgeneral{ "resources/dag.txt" };
|
||||
std::vector<std::pair<int, int>> dagGraph;
|
||||
int fu, fv;
|
||||
|
||||
while (fgeneral >> fu >> fv)
|
||||
dagGraph.push_back({ fu, fv });
|
||||
|
||||
graph::Digraph<int> G;
|
||||
for (const auto& [u, v] : dagGraph)
|
||||
G.insert(u, v);
|
||||
|
||||
algo::King<int>* k = new algo::King(G);
|
||||
k->init();
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 mt(rd());
|
||||
std::ranges::shuffle(dagGraph, mt);
|
||||
std::vector<std::pair<int, int>> delEdges(dagGraph.begin(),
|
||||
dagGraph.begin() + 20);
|
||||
|
||||
dynBench.epochs(1).run("K::remove", [&] {
|
||||
k->remove(delEdges); }
|
||||
);
|
||||
|
||||
std::uniform_int_distribution<> dist(1, 200);
|
||||
|
||||
dynBench.epochs(1).run("K::query", [&] {
|
||||
for (int i = 0; i < 50; ++i)
|
||||
k->query(dist(mt), dist(mt)); }
|
||||
);
|
||||
|
||||
std::vector<int> insEdges;
|
||||
for (int i = 0; i < 50; ++i)
|
||||
insEdges.push_back(dist(mt));
|
||||
|
||||
dynBench.epochs(1).run("K::insert", [&] {
|
||||
k->insert(50, insEdges); }
|
||||
);
|
||||
}
|
||||
|
||||
TEST_CASE("HenzingerKing") {
|
||||
std::ifstream fgeneral{ "resources/general.txt" };
|
||||
std::vector<std::pair<int, int>> generalGraph;
|
||||
int fu, fv;
|
||||
|
||||
while (fgeneral >> fu >> fv)
|
||||
generalGraph.push_back({ fu, fv });
|
||||
|
||||
graph::Digraph<int> G;
|
||||
for (const auto& [u, v] : generalGraph)
|
||||
G.insert(u, v);
|
||||
|
||||
algo::HenzingerKing<int>* hk = new algo::HenzingerKing(G);
|
||||
hk->init();
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 mt(rd());
|
||||
std::ranges::shuffle(generalGraph, mt);
|
||||
std::vector<std::pair<int, int>> delEdges(generalGraph.begin(),
|
||||
generalGraph.begin() + 20);
|
||||
|
||||
dynBench.epochs(1).run("HK::remove", [&] {
|
||||
hk->remove(delEdges); }
|
||||
);
|
||||
|
||||
std::uniform_int_distribution<> dist(1, 200);
|
||||
|
||||
dynBench.epochs(1).run("HK::query", [&] {
|
||||
for (int i = 0; i < 50; ++i)
|
||||
hk->query(dist(mt), dist(mt)); }
|
||||
);
|
||||
|
||||
std::vector<int> insEdges;
|
||||
for (int i = 0; i < 50; ++i)
|
||||
insEdges.push_back(dist(mt));
|
||||
|
||||
dynBench.epochs(1).run("HK::insert", [&] {
|
||||
hk->insert(50, insEdges); }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user