From 58a4b8719e43b27e6ae5493c9bfe32741d71c235 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 18 Jan 2008 22:12:53 +0000 Subject: [PATCH] better machinery; before make view interpolate-compatible --- .bzrignore | 1 + Makefile | 9 +++++++-- energy.c | 19 ++++++++++++++----- interpolate.c | 27 ++++++++++++++++++-------- minimise.c | 52 ++++++++++++++++++++++++++++++++++++++------------- minimise.h | 5 +++-- 6 files changed, 83 insertions(+), 30 deletions(-) diff --git a/.bzrignore b/.bzrignore index 2f356c2..93c99e1 100644 --- a/.bzrignore +++ b/.bzrignore @@ -9,3 +9,4 @@ core vgcore.* prime.data *.cfm +*.CFM diff --git a/Makefile b/Makefile index 42ebbd5..a2409fc 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,8 @@ o= >$@.new && mv -f $@.new $@ all: $(TARGETS) +compute: best.CFM + minimise: energy.o graph.o common.o mgraph.o minimise.o half.o $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBGSL) @@ -38,6 +40,9 @@ lumpy.cfm: oldmoebius-converter prime.data ../moebius/ins-new ../moebius/a.out ring.cfm: oldmoebius-converter prime.data /dev/null ../moebius/a.out ./$^ -o$@ +best.CFM: minimise sgtatham.cfm + ./$^ -iwip.cfm -o$@ + view-%: view+%.o mgraph+%.o common.o $(CC) $(CFLAGS) -o $@ $^ $(LIBGSL) -L/usr/X11R6/lib -lX11 @@ -60,10 +65,10 @@ interpolate+%.o: interpolate.c clean: rm -f prime.data $(TARGETS) rm -f *.o *.new *.tmp *.rej *.orig core vgcore.* *~ - rm -f *.d + rm -f *.d *.cfm realclean: clean - rm -f best + rm -f *.CFM %.d: diff --git a/energy.c b/energy.c index bba938d..4789698 100644 --- a/energy.c +++ b/energy.c @@ -19,6 +19,8 @@ void energy_init(void) { /*---------- main energy computation and subroutines ----------*/ double compute_energy(const struct Vertices *vs) { + static int bests_unprinted; + double energy; int printing; @@ -28,7 +30,7 @@ double compute_energy(const struct Vertices *vs) { printing= printing_check(pr_cost,0); - if (printing) printf("cost > energy |"); + if (printing) printf("%15lld c>e |", evaluations); COST(3e2, line_bending_cost(vs->a)); COST(1e3, edge_length_variation_cost(vs->a)); @@ -42,12 +44,18 @@ double compute_energy(const struct Vertices *vs) { FILE *best_f; int r; - if (printing) printf(" BEST"); + if (printing) { + printf(" BEST"); + if (bests_unprinted) printf(" [%4d]",bests_unprinted); + bests_unprinted= 0; + } else { + bests_unprinted++; + } - best_f= fopen(output_file_tmp,"wb"); if (!best_f) diee("fopen new out"); + best_f= fopen(best_file_tmp,"wb"); if (!best_f) diee("fopen new out"); r= fwrite(vs->a,sizeof(vs->a),1,best_f); if (r!=1) diee("fwrite"); if (fclose(best_f)) diee("fclose new best"); - if (rename(output_file_tmp,output_file)) diee("rename install new best"); + if (rename(best_file_tmp,best_file)) diee("rename install new best"); best_energy= energy; } @@ -56,12 +64,13 @@ double compute_energy(const struct Vertices *vs) { flushoutput(); } + evaluations++; return energy; } static void addcost(double *energy, double tweight, double tcost, int pr) { double tenergy= tweight * tcost; - if (pr) printf(" %# e x %# e > %# e* |", tcost, tweight, tenergy); + if (pr) printf(" %# e x %g > %# e* |", tcost, tweight, tenergy); *energy += tenergy; } diff --git a/interpolate.c b/interpolate.c index 6f519e4..d9d3910 100644 --- a/interpolate.c +++ b/interpolate.c @@ -16,35 +16,46 @@ static void characterise_input(void) { r= fstat(0,&stab); if (r) diee("fstat input to find length"); - if (!stab.st_size || stab.st_size % sizeof(double) || + if (!stab.st_size || stab.st_size % (sizeof(double)*D3) || stab.st_size > INT_MAX) fail("input file is not reasonable whole number of doubles\n"); - oldsz= stab.st_size / sizeof(double); + oldsz= stab.st_size / (sizeof(double)*D3); for (shift=1; - shift > XBITS+1 && shift > YBITS+1; + shift < XBITS+1 && shift < YBITS+1; shift++) { oldxbits= XBITS-1; oldybits= YBITS-1; oldx= 1<%2d", oy,y); + for (ox=x=0; x0x%02x", ov, v); + if (fread(all.a[v], sizeof(double), D3, stdin) != D3) + diee("\nread input"); } + fputc('\n',stderr); + } } /* We use GSL's interpolation functions. Each xa array is simple diff --git a/minimise.c b/minimise.c index e5bbc87..8f6a261 100644 --- a/minimise.c +++ b/minimise.c @@ -37,14 +37,16 @@ #include "half.h" #include "minimise.h" -const char *input_file, *output_file; -char *output_file_tmp; +const char *input_file, *best_file; +char *best_file_tmp; +long long evaluations; static void printing_init(void); -static gsl_multimin_fminimizer *minimiser; - static const double stop_epsilon= 1e-6; +static gsl_multimin_fminimizer *minimiser; +static const char *final_file; +static char *final_file_tmp; static double minfunc_f(const gsl_vector *x, void *params) { struct Vertices vs; @@ -55,6 +57,11 @@ static double minfunc_f(const gsl_vector *x, void *params) { return compute_energy(&vs); } +static void badusage(void) { + fputs("usage: minimise [-i] -o -o