1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2026-05-20 21:12:06 +00:00
Files
hyperrogue/rogueviz/dhrg/dhrg.cpp
T

187 lines
3.9 KiB
C++

// see this paper: https://arxiv.org/abs/2109.11772
#include "dhrg.h"
#include "regular.cpp"
#include "gridmapping.cpp"
#include "mycell.cpp"
#include "segment.cpp"
#include "dynamic.cpp"
#include "loglik.cpp"
#include "paths.cpp"
#include "embedder.cpp"
#include "tests.cpp"
#include "betweenness.cpp"
#include "groundtruth.cpp"
#include "dhrg-rank.cpp"
namespace dhrg {
int M;
vector<struct mycell*> vertices;
void memoryInfo() {
string s = "";
ll totalmemory = 0;
for(int it=0; it<2; it++) {
auto pct = [&] (auto x, auto y) {
if(it == 0) totalmemory += x*y;
else s += " " + its(x) + "x" + its(y) + "B=" + its((x*y*100)/totalmemory) + "%";
};
pct(cellcount, sizeof(cell));
pct(heptacount, sizeof(heptagon));
pct(mycellcount, sizeof(mycell));
pct(segmentcount, sizeof(segment));
}
println(hlog, "Memory info: ", s, " (", int(totalmemory/1048576), " MB)");
fflush(stdout);
}
void debugtally() {
print(hlog, "T"); for(int i=0; i<MAXDIST; i++) if(tally[i]) print(hlog, hr::format(" %4d/%4lld", edgetally[i], tally[i]));
println(hlog, " .. %", loglikopt());
}
int destroy;
void clear() {
// destroytallies();
// todo: correct cleanup!
for(int i=0; i<MAXDIST; i++) tally[i] = 0;
for(int i=0; i<MAXDIST; i++) edgetally[i] = 0;
#ifdef BUILD_ON_HR
mymap.clear();
#else
delete mroot;
mroot = NULL;
#endif
}
// actual octiles of normal are roughly: -1.15 -.674 -.318 0 .318 .674 1.15
void dhrg_init() {
if(!mroot) {
println(hlog, "DHRG version " DHRGVER "\n");
rogueviz::rv_hook(hooks_handleKey, 100, dhrg_animate);
regular_info();
generate_root();
}
}
int next_timestamp;
int ts_rogueviz;
int ts_rbase;
int ts_coords;
int ts_vertices;
bool stored;
int dhrgArgs() {
using namespace arg;
if(argis("-analyze_grid")) {
PHASE(3); shift(); dhrg_init(); do_analyze_grid(argi());
}
else if(argis("-analyze_dists")) {
PHASE(3); dhrg_init(); shift(); do_analyze_dists(argi());
}
else if(argis("-test_paths")) {
PHASE(3); dhrg_init(); shift(); test_paths(argi());
}
else if(argis("-iterate")) {
if(ts_rbase > ts_vertices) {
PHASE(3); dhrg_init(); graph_from_rv();
ts_vertices = ts_rbase;
}
if(!ts_vertices) {
printf("Error: read vertices with -dhrg or -graph\n");
exit(1);
}
shift();
embedder_loop(argi());
next_timestamp++;
ts_vertices = next_timestamp;
}
else if(argis("-dorestart")) {
dorestart = true;
}
else if(argis("-dontrestart")) {
dorestart = false;
}
else if(argis("-lctype")) {
shift(); lc_type = args()[0];
}
else if(argis("-loadtest")) {
dhrg_init(); load_test();
}
else if(argis("-buildtest")) {
shift(); dhrg_init(); build_all(argi());
}
else if(argis("-pbv")) {
compute_betweenness(true);
}
else if(argis("-pb")) {
compute_betweenness(false);
}
else if(argis("-gtt")) {
shift(); ground_truth_test(args());
}
else if(argis("-el-dhrg")) {
PHASE(3); shift(); dhrg_init(); load_embedded(args());
next_timestamp++;
ts_rogueviz = next_timestamp;
ts_vertices = next_timestamp;
}
else if(argis("-discrete-rank")) {
dhrg_ranks();
}
else if(argis("-penalty")) {
shift(); penalty = argf();
}
else return 1;
return 0;
}
void store_gamedata(struct hr::gamedata* gd) {
if(true) {
for(auto& t: tally) gd->store(t);
for(auto& t: edgetally) gd->store(t);
#ifdef BUILD_ON_HR
gd->store(mymap);
#else
gd->store(mroot);
#endif
}
}
auto hook =
addHook(hooks_args, 50, dhrgArgs)
+ addHook(hooks_gamedata, 230, store_gamedata)
+ addHook(hooks_clearmemory, 200, clear);
#if CAP_SDL
#include "visualize.cpp"
#endif
}
#include "legacy.cpp"