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