mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-23 21:07:17 +00:00
applied the scan/fts/etc changes to RogueViz
This commit is contained in:
parent
556c234997
commit
15f87d151a
@ -17,7 +17,7 @@ cwpath invertpath(cwpath p) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
cwpath gens[4];
|
array<cwpath, 4> gens;
|
||||||
|
|
||||||
cellwalker bttargets[4];
|
cellwalker bttargets[4];
|
||||||
|
|
||||||
@ -234,8 +234,8 @@ void bantar() {
|
|||||||
bool tres = test_uniq(cwt, -1, 15, NULL);
|
bool tres = test_uniq(cwt, -1, 15, NULL);
|
||||||
auto q = quality(bc);
|
auto q = quality(bc);
|
||||||
if(tres) {
|
if(tres) {
|
||||||
printf("g0: "); for(int w: gens[0]) printf("%d ", w); printf("g1: "); for(int w: gens[1]) printf("%d ", w); printf("\n");
|
DEBB(DF_LOG, ("gens = ", gens));
|
||||||
printf("testing quality %lf/%lf [%d,%d], result = %d\n", get<0>(q), get<2>(q), celldist(bc.first), celldist(bc.second), tres);
|
DEBB(DF_LOG, ("testing quality ", q, " ", make_pair(celldist(bc.first), celldist(bc.second)), ", result = ", tres));
|
||||||
lnotry--; if(lnotry <= 0) goto picked;
|
lnotry--; if(lnotry <= 0) goto picked;
|
||||||
}
|
}
|
||||||
// if(tres) goto picked;
|
// if(tres) goto picked;
|
||||||
|
@ -48,30 +48,27 @@ int readArgs() {
|
|||||||
else if(argis("-cvlbuild")) {
|
else if(argis("-cvlbuild")) {
|
||||||
PHASEFROM(3);
|
PHASEFROM(3);
|
||||||
start_game();
|
start_game();
|
||||||
shift(); FILE *f = fopen(argcs(), "rt");
|
shift();
|
||||||
if(!f) { shift(); printf("failed to open file\n"); return 0; }
|
fhstream f(argcs(), "rt");
|
||||||
|
if(!f.f) { shift(); printf("failed to open file\n"); return 0; }
|
||||||
int id;
|
int id;
|
||||||
lineinfo l0;
|
lineinfo l0;
|
||||||
ignore(fscanf(f, "%d%d%d", &id, &l0.plus_matrices, &l0.minus_matrices));
|
scan(f, id, l0.plus_matrices, l0.minus_matrices);
|
||||||
l0.locs.push_back(location{View, viewctr});
|
l0.locs.push_back(location{View, viewctr});
|
||||||
for(int i=1; i<l0.plus_matrices; i++)
|
for(int i=1; i<l0.plus_matrices; i++)
|
||||||
l0.locs.push_back(loc_multiply(l0.locs.back(), xpush(1)));
|
l0.locs.push_back(loc_multiply(l0.locs.back(), xpush(1)));
|
||||||
lines[id] = std::move(l0);
|
lines[id] = std::move(l0);
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
ignore(fscanf(f, "%d", &id));
|
scan(f, id);
|
||||||
println(hlog, "id=", id, ".");
|
println(hlog, "id=", id, ".");
|
||||||
if(id < 0) break;
|
if(id < 0) break;
|
||||||
auto& l1 = lines[id];
|
auto& l1 = lines[id];
|
||||||
int step;
|
int step;
|
||||||
ignore(fscanf(f, "%d%d", &id, &step));
|
scan(f, id, step);
|
||||||
transmatrix T;
|
transmatrix T;
|
||||||
double d;
|
for(int a=0; a<9; a++) scan(f, T[0][a]);
|
||||||
for(int a=0; a<9; a++) {
|
scan(f, l1.plus_matrices, l1.minus_matrices);
|
||||||
ignore(fscanf(f, "%lf", &d));
|
|
||||||
T[0][a] = d;
|
|
||||||
}
|
|
||||||
ignore(fscanf(f, "%d%d", &l1.plus_matrices, &l1.minus_matrices));
|
|
||||||
auto old = lines[id].locs[step];
|
auto old = lines[id].locs[step];
|
||||||
println(hlog, "FROM ", old.lView, old.lviewctr, " id=", id, " step=", step);
|
println(hlog, "FROM ", old.lView, old.lviewctr, " id=", id, " step=", step);
|
||||||
l1.locs.push_back(loc_multiply(old, T));
|
l1.locs.push_back(loc_multiply(old, T));
|
||||||
|
@ -77,26 +77,26 @@ bool noshow = false;
|
|||||||
vector<int> samples_to_show;
|
vector<int> samples_to_show;
|
||||||
|
|
||||||
void loadsamples(const string& fname) {
|
void loadsamples(const string& fname) {
|
||||||
FILE *f = fopen(fname.c_str(), "rt");
|
fhstream f(fname, "rt");
|
||||||
if(!f) {
|
if(!f.f) {
|
||||||
fprintf(stderr, "Could not load samples: %s\n", fname.c_str());
|
fprintf(stderr, "Could not load samples: %s\n", fname.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(fscanf(f, "%d", &columns) != 1) {
|
if(!scan(f, columns)) {
|
||||||
printf("Bad format: %s\n", fname.c_str());
|
printf("Bad format: %s\n", fname.c_str());
|
||||||
fclose(f); return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Loading samples: %s\n", fname.c_str());
|
printf("Loading samples: %s\n", fname.c_str());
|
||||||
while(true) {
|
while(true) {
|
||||||
sample s;
|
sample s;
|
||||||
bool shown = false;
|
bool shown = false;
|
||||||
alloc(s.val);
|
alloc(s.val);
|
||||||
if(feof(f)) break;
|
if(feof(f.f)) break;
|
||||||
for(int i=0; i<columns; i++)
|
for(int i=0; i<columns; i++)
|
||||||
if(fscanf(f, "%lf", &s.val[i]) != 1) { goto bigbreak; }
|
if(!scan(f, s.val[i])) { goto bigbreak; }
|
||||||
fgetc(f);
|
fgetc(f.f);
|
||||||
while(true) {
|
while(true) {
|
||||||
int c = fgetc(f);
|
int c = fgetc(f.f);
|
||||||
if(c == -1 || c == 10 || c == 13) break;
|
if(c == -1 || c == 10 || c == 13) break;
|
||||||
if(c == '!' && s.name == "") shown = true;
|
if(c == '!' && s.name == "") shown = true;
|
||||||
else if(c != 32 && c != 9) s.name += c;
|
else if(c != 32 && c != 9) s.name += c;
|
||||||
@ -106,7 +106,6 @@ void loadsamples(const string& fname) {
|
|||||||
samples_to_show.push_back(isize(data)-1);
|
samples_to_show.push_back(isize(data)-1);
|
||||||
}
|
}
|
||||||
bigbreak:
|
bigbreak:
|
||||||
fclose(f);
|
|
||||||
samples = isize(data);
|
samples = isize(data);
|
||||||
normalize();
|
normalize();
|
||||||
colnames.resize(columns);
|
colnames.resize(columns);
|
||||||
@ -703,16 +702,16 @@ void sominit(int initto, bool load_compressed) {
|
|||||||
if(inited < 2 && initto >= 2) {
|
if(inited < 2 && initto >= 2) {
|
||||||
inited = 2;
|
inited = 2;
|
||||||
|
|
||||||
printf("Initializing SOM (2)\n");
|
DEBB(DF_LOG, ("Initializing SOM (2)"));
|
||||||
|
|
||||||
if(gaussian) {
|
if(gaussian) {
|
||||||
printf("dist = %lf\n", mydistance(net[0].where, net[1].where));
|
DEBB(DF_LOG, ("dist = ", fts(mydistance(net[0].where, net[1].where))));
|
||||||
cell *c1 = net[cells/2].where;
|
cell *c1 = net[cells/2].where;
|
||||||
vector<double> mapdist;
|
vector<double> mapdist;
|
||||||
for(neuron &n2: net) mapdist.push_back(mydistance(c1,n2.where));
|
for(neuron &n2: net) mapdist.push_back(mydistance(c1,n2.where));
|
||||||
sort(mapdist.begin(), mapdist.end());
|
sort(mapdist.begin(), mapdist.end());
|
||||||
maxdist = mapdist[isize(mapdist)*5/6] * distmul;
|
maxdist = mapdist[isize(mapdist)*5/6] * distmul;
|
||||||
printf("maxdist = %lf\n", maxdist);
|
DEBB(DF_LOG, ("maxdist = ", fts(maxdist)));
|
||||||
}
|
}
|
||||||
|
|
||||||
dispersion_count = 0;
|
dispersion_count = 0;
|
||||||
@ -722,7 +721,7 @@ void sominit(int initto, bool load_compressed) {
|
|||||||
cell *c = net[i].where;
|
cell *c = net[i].where;
|
||||||
auto cid = get_cellcrawler_id(c);
|
auto cid = get_cellcrawler_id(c);
|
||||||
if(!scc.count(cid.first)) {
|
if(!scc.count(cid.first)) {
|
||||||
printf("Building cellcrawler id = %x\n", cid.first);
|
DEBB(DF_LOG, ("Building cellcrawler id = ", itsh(cid.first)));
|
||||||
buildcellcrawler(c, scc[cid.first], cid.second);
|
buildcellcrawler(c, scc[cid.first], cid.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -903,12 +902,12 @@ void ksave(const string& fname) {
|
|||||||
void kload(const string& fname) {
|
void kload(const string& fname) {
|
||||||
sominit(1);
|
sominit(1);
|
||||||
int xcells;
|
int xcells;
|
||||||
FILE *f = fopen(fname.c_str(), "rt");
|
fhstream f(fname.c_str(), "rt");
|
||||||
if(!f) {
|
if(!f.f) {
|
||||||
fprintf(stderr, "Could not load the network: %s\n", fname.c_str());
|
fprintf(stderr, "Could not load the network: %s\n", fname.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(fscanf(f, "%d%d\n", &xcells, &t) != 2) {
|
if(!scan(f, xcells, t)) {
|
||||||
fprintf(stderr, "Bad network format: %s\n", fname.c_str());
|
fprintf(stderr, "Bad network format: %s\n", fname.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -918,9 +917,8 @@ void kload(const string& fname) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
for(neuron& n: net) {
|
for(neuron& n: net) {
|
||||||
for(int k=0; k<columns; k++) if(fscanf(f, "%lf", &n.net[k]) != 1) return;
|
for(int k=0; k<columns; k++) if(!scan(f, n.net[k])) return;
|
||||||
}
|
}
|
||||||
fclose(f);
|
|
||||||
analyze();
|
analyze();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ void make_staircase() {
|
|||||||
// vid.stereo_mode = current_display->sODS;
|
// vid.stereo_mode = current_display->sODS;
|
||||||
rug::no_fog = true;
|
rug::no_fog = true;
|
||||||
|
|
||||||
printf("scurvature = %lf progress = %lf strafe=%lf,%lf\n", scurvature, progress, strafex, strafey);
|
println(hlog, "scurvature = ", scurvature, " progress = ", progress, " strafe=", strafex, ",", strafey);
|
||||||
rug::renderonce = true;
|
rug::renderonce = true;
|
||||||
rug::rug_perspective = true;
|
rug::rug_perspective = true;
|
||||||
if(scurvature > -1e-6 && scurvature < 1e-6) {
|
if(scurvature > -1e-6 && scurvature < 1e-6) {
|
||||||
|
87
rogueviz.cpp
87
rogueviz.cpp
@ -357,14 +357,8 @@ namespace collatz {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string readLabel_s(FILE *f) {
|
int readLabel(fhstream& f) {
|
||||||
char xlabel[10000];
|
string s = scan<string>(f);
|
||||||
if(fscanf(f, "%9500s", xlabel) <= 0) return "";
|
|
||||||
return xlabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
int readLabel(FILE *f) {
|
|
||||||
string s = readLabel_s(f);
|
|
||||||
if(s == "") return -1;
|
if(s == "") return -1;
|
||||||
return getid(s);
|
return getid(s);
|
||||||
}
|
}
|
||||||
@ -388,24 +382,27 @@ namespace anygraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst() {}
|
||||||
|
|
||||||
void read(string fn, bool subdiv, bool doRebase, bool doStore) {
|
void read(string fn, bool subdiv, bool doRebase, bool doStore) {
|
||||||
init(); kind = kAnyGraph;
|
init(); kind = kAnyGraph;
|
||||||
any = add_edgetype("embedded edges");
|
any = add_edgetype("embedded edges");
|
||||||
fname = fn;
|
fname = fn;
|
||||||
FILE *f = fopen((fn + "-coordinates.txt").c_str(), "rt");
|
fhstream f(fn + "-coordinates.txt", "rt");
|
||||||
if(!f) {
|
if(!f.f) {
|
||||||
printf("Missing file: %s-coordinates.txt\n", fname.c_str());
|
printf("Missing file: %s-coordinates.txt\n", fname.c_str());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("Reading coordinates...\n");
|
printf("Reading coordinates...\n");
|
||||||
char buf[100];
|
string ignore;
|
||||||
int err;
|
if(!scan(f, ignore, ignore, ignore, ignore, N, anygraph::R, anygraph::alpha, anygraph::T)) {
|
||||||
err = fscanf(f, "%s%s%s%s%d%lf%lf%lf", buf, buf, buf, buf, &N,
|
printf("Error: incorrect format of the first line\n"); exit(1);
|
||||||
&anygraph::R, &anygraph::alpha, &anygraph::T);
|
}
|
||||||
if(err < 8) { printf("Error: incorrect format of the first line\n"); exit(1); }
|
|
||||||
vdata.reserve(N);
|
vdata.reserve(N);
|
||||||
while(true) {
|
while(true) {
|
||||||
string s = readLabel_s(f);
|
string s = scan<string>(f);
|
||||||
|
println(hlog, "s: ", s.c_str());
|
||||||
|
if(s == "D11.11") tst();
|
||||||
if(s == "" || s == "#ROGUEVIZ_ENDOFDATA") break;
|
if(s == "" || s == "#ROGUEVIZ_ENDOFDATA") break;
|
||||||
int id = getid(s);
|
int id = getid(s);
|
||||||
vertexdata& vd(vdata[id]);
|
vertexdata& vd(vdata[id]);
|
||||||
@ -413,30 +410,27 @@ namespace anygraph {
|
|||||||
vd.cp = colorpair(dftcolor);
|
vd.cp = colorpair(dftcolor);
|
||||||
|
|
||||||
double r, alpha;
|
double r, alpha;
|
||||||
int err = fscanf(f, "%lf%lf", &r, &alpha);
|
if(!scan(f, r, alpha)) { printf("Error: incorrect format of r/alpha\n"); exit(1); }
|
||||||
coords.push_back(make_pair(r, alpha));
|
coords.push_back(make_pair(r, alpha));
|
||||||
if(err < 2) { printf("Error: incorrect format of r/alpha\n"); exit(1); }
|
|
||||||
|
|
||||||
transmatrix h = spin(alpha * degree) * xpush(r);
|
transmatrix h = spin(alpha * degree) * xpush(r);
|
||||||
|
|
||||||
createViz(id, currentmap->gamestart(), h);
|
createViz(id, currentmap->gamestart(), h);
|
||||||
}
|
}
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
f = fopen((fn + "-links.txt").c_str(), "rt");
|
fhstream g(fn + "-links.txt", "rt");
|
||||||
if(!f) {
|
if(!g.f) {
|
||||||
printf("Missing file: %s-links.txt\n", fname.c_str());
|
println(hlog, "Missing file: ", fname, "-links.txt");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
printf("Reading links...\n");
|
println(hlog, "Reading links...");
|
||||||
int qlink = 0;
|
int qlink = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
int i = readLabel(f), j = readLabel(f);
|
int i = readLabel(g), j = readLabel(g);
|
||||||
if(i == -1 || j == -1) break;
|
if(i == -1 || j == -1) break;
|
||||||
addedge(i, j, 1, subdiv, any);
|
addedge(i, j, 1, subdiv, any);
|
||||||
qlink++;
|
qlink++;
|
||||||
}
|
}
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
if(doRebase) {
|
if(doRebase) {
|
||||||
printf("Rebasing...\n");
|
printf("Rebasing...\n");
|
||||||
@ -847,14 +841,14 @@ namespace sag {
|
|||||||
numiter++;
|
numiter++;
|
||||||
sag::saiter();
|
sag::saiter();
|
||||||
}
|
}
|
||||||
printf("it %8d temp %6.4" PLDF" [1/e at %13.6" PLDF"] cost = %lf ",
|
DEBB(DF_LOG, (format("it %8d temp %6.4f [1/e at %13.6f] cost = %f ",
|
||||||
numiter, sag::temperature, (ld) exp(sag::temperature),
|
numiter, double(sag::temperature), (double) exp(sag::temperature),
|
||||||
sag::cost);
|
double(sag::cost))));
|
||||||
|
|
||||||
sort(chgs.begin(), chgs.end());
|
sort(chgs.begin(), chgs.end());
|
||||||
int cc = chgs.size() - 1;
|
int cc = chgs.size() - 1;
|
||||||
printf("%9.4lf .. %9.4lf .. %9.4lf .. %9.4lf .. %9.4lf\n",
|
DEBB(DF_LOG, (format("%9.4f .. %9.4f .. %9.4f .. %9.4f .. %9.4f\n",
|
||||||
chgs[0], chgs[cc/4], chgs[cc/2], chgs[cc*3/4], chgs[cc]);
|
double(chgs[0]), double(chgs[cc/4]), double(chgs[cc/2]), double(chgs[cc*3/4]), double(chgs[cc]))));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,12 +871,12 @@ namespace sag {
|
|||||||
if(t < 50) ipturn *= 2;
|
if(t < 50) ipturn *= 2;
|
||||||
else if(t > 200) ipturn /= 2;
|
else if(t > 200) ipturn /= 2;
|
||||||
else ipturn = ipturn * 100 / t;
|
else ipturn = ipturn * 100 / t;
|
||||||
printf("it %8d temp %6.4" PLDF" [2:%8.6" PLDF",10:%8.6" PLDF",50:%8.6" PLDF"] cost = %lf\n",
|
DEBB(DF_LOG, ("it %8d temp %6.4f [2:%8.6f,10:%8.6f,50:%8.6f] cost = %f\n",
|
||||||
numiter, sag::temperature,
|
numiter, double(sag::temperature),
|
||||||
exp(-2 * exp(-sag::temperature)),
|
(double) exp(-2 * exp(-sag::temperature)),
|
||||||
exp(-10 * exp(-sag::temperature)),
|
(double) exp(-10 * exp(-sag::temperature)),
|
||||||
exp(-50 * exp(-sag::temperature)),
|
(double) exp(-50 * exp(-sag::temperature)),
|
||||||
sag::cost);
|
(double) sag::cost));
|
||||||
}
|
}
|
||||||
|
|
||||||
void savesnake(const string& fname) {
|
void savesnake(const string& fname) {
|
||||||
@ -924,34 +918,33 @@ namespace sag {
|
|||||||
loglik += p * log(p) + q * log(q) - pq * log(pq);
|
loglik += p * log(p) + q * log(q) - pq * log(pq);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("loglikelihood = %lf\n", (double) loglik);
|
println(hlog, "loglikelihood = ", fts(loglik));
|
||||||
}
|
}
|
||||||
|
|
||||||
void readsag(const char *fname) {
|
void readsag(const char *fname) {
|
||||||
maxweight = 0;
|
maxweight = 0;
|
||||||
sag_edge = add_edgetype("SAG edge");
|
sag_edge = add_edgetype("SAG edge");
|
||||||
FILE *f = fopen(fname, "rt");
|
fhstream f(fname, "rt");
|
||||||
if(!f) { printf("Failed to open SAG file: %s\n", fname); exit(1); }
|
if(!f.f) { printf("Failed to open SAG file: %s\n", fname); exit(1); }
|
||||||
// while(fgetc(f) != 10 && fgetc(f) != 13 && !feof(f)) ;
|
// while(fgetc(f) != 10 && fgetc(f) != 13 && !feof(f)) ;
|
||||||
while(!feof(f)) {
|
while(!feof(f.f)) {
|
||||||
string l1, l2;
|
string l1, l2;
|
||||||
while(true) {
|
while(true) {
|
||||||
int c = fgetc(f);
|
int c = fgetc(f.f);
|
||||||
if(c == EOF) { fclose(f); return; }
|
if(c == EOF) return;
|
||||||
else if(c == ';') break;
|
else if(c == ';') break;
|
||||||
else if(c == 10 || c == 13 || c == 32 || c == 9) ;
|
else if(c == 10 || c == 13 || c == 32 || c == 9) ;
|
||||||
else l1 += c;
|
else l1 += c;
|
||||||
}
|
}
|
||||||
while(true) {
|
while(true) {
|
||||||
int c = fgetc(f);
|
int c = fgetc(f.f);
|
||||||
if(c == EOF) { fclose(f); return; }
|
if(c == EOF) return;
|
||||||
else if(c == ';') break;
|
else if(c == ';') break;
|
||||||
else if(c == 10 || c == 13 || c == 32 || c == 9) ;
|
else if(c == 10 || c == 13 || c == 32 || c == 9) ;
|
||||||
else l2 += c;
|
else l2 += c;
|
||||||
}
|
}
|
||||||
double wei;
|
ld wei;
|
||||||
int err = fscanf(f, "%lf", &wei);
|
if(!scan(f, wei)) continue;
|
||||||
if(err < 1) continue;
|
|
||||||
edgeinfo ei(sag_edge);
|
edgeinfo ei(sag_edge);
|
||||||
ei.i = getid(l1);
|
ei.i = getid(l1);
|
||||||
ei.j = getid(l2);
|
ei.j = getid(l2);
|
||||||
|
Loading…
Reference in New Issue
Block a user