1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2026-01-01 18:09:04 +00:00

embeddings:: -esaveas command

This commit is contained in:
Zeno Rogue
2025-12-05 00:25:38 +01:00
parent f22f720a95
commit 5d26eb5608
3 changed files with 28 additions and 11 deletions

View File

@@ -150,14 +150,6 @@ int dhrgArgs() {
shift(); ground_truth_test(args());
}
else if(argis("-esaveas")) {
shift(); save_embedding(args());
}
else if(argis("-esave")) {
save_embedding(rogueviz::fname + "-dhrg.txt");
}
else if(argis("-eload")) {
PHASE(3); shift(); dhrg_init(); load_embedded(args());
next_timestamp++;

View File

@@ -84,12 +84,18 @@ void enable_embedding(std::shared_ptr<embedding> pe) {
reenable_embedding();
}
void esave(string fname) {
fhstream f(arg::args(), "wt");
if(!f.f) file_error(fname);
current->save(f);
}
void store_gamedata(struct hr::gamedata* gd) { gd->store(current); }
int a = arg::add3("-edgelist", [] { arg::shift(); read_edgelist(arg::args()); })
+ addHook(hooks_gamedata, 230, store_gamedata)
+ arg::add3("-write-edges", [] { arg::shift(); write_edgelist(arg::args()); });
+ arg::add3("-write-edges", [] { arg::shift(); write_edgelist(arg::args()); })
+ arg::add3("-esaveas", [] { arg::shift(); esave(arg::args()); });
}

View File

@@ -32,12 +32,31 @@ namespace embeddings {
return acosh(v);
}
void save(fhstream& f) override {
println(f, "n R alpha t");
println(f, isize(vdata), " ", cont_logistic.R, " ", graph_alpha, " ", cont_logistic.T);
int i = 0;
for(auto& co: coords)
println(f, vdata[i++].name, format(" %.20lf %.20lf", co.r, co.theta / degree));
}
};
/** read polar coordinates, in the format returned by the BFKL embdder. */
void read_polar(const string& fn) {
if(fn == "-") {
auto pe = std::make_shared<polar_embedding> ();
int N = isize(vdata);
pe->coords.resize(N);
for(int i=0; i<N; i++) {
auto h = current->as_hyperpoint(i);
pe->coords[i] = { hdist0(h), atan2(h) };
}
return enable_embedding(pe);
}
fhstream f(fn, "rt");
if(!f.f) return file_error(fn);
@@ -67,7 +86,7 @@ namespace embeddings {
pe->coords[id] = polar_point{.r = r, .theta = theta * degree};
}
enable_embedding(std::move(pe));
enable_embedding(pe);
}
int a_polar =