chiark / gitweb /
rename things more sensibly; now it can optimise but the edgewise vertex formula...
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Wed, 2 Jan 2008 02:07:02 +0000 (02:07 +0000)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Wed, 2 Jan 2008 02:07:02 +0000 (02:07 +0000)
.bzrignore
Makefile
energy.c
mgraph.h
oldmoebius-converter [moved from approxmodel with 100% similarity]
sgtatham-regenerator [moved from generator with 100% similarity]

index 098b20b..6c387ea 100644 (file)
@@ -1,12 +1,10 @@
 minimise
 primer
-initial
 view
-best
 *.d
 *.tmp
 *.new
 core
 vgcore.*
-lumpy
-prime
+prime.data
+*.cfm
index a4b09dc..4726f04 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 
-TARGETS= minimise primer initial view
+TARGETS= minimise primer view lumpy.cfm sgtatham.cfm
 
 CWARNS=        -Wall -Wwrite-strings -Wpointer-arith -Werror -Wshadow
 CXXWARNS= $(CWARNS) -Wno-shadow -Wno-error
@@ -17,24 +17,24 @@ all:                $(TARGETS)
 minimise:      energy.o bgl.o common.o mgraph.o
                $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBGSL)
 
-prime:         primer
-               ./$^ $o
-
 primer:                primer.o common.o
                $(CC) $(CFLAGS) -o $@ $^ $(LIBGSL)
 
+prime.data:    primer
+               ./$^ $o
+
 view:          view.o common.o mgraph.o
                $(CC) $(CFLAGS) -o $@ $^ $(LIBGSL) -L/usr/X11R6/lib -lX11
 
-sgtatham:      generator prime sgtatham/z.typescript
+sgtatham.cfm:  sgtatham-regenerator prime.data sgtatham/z.typescript
                ./$^ -T -o$@
 
-lumpy:         approxmodel prime ../moebius/ins-new ../moebius/a.out
+lumpy.cfm: oldmoebius-converter prime.data ../moebius/ins-new ../moebius/a.out
                ./$^ -o$@
 
 clean:
-               rm -f *.o $(TARGETS) *.new *.tmp *.rej *.orig core vgcore.*
-               rm -f initial
+               rm -f prime.data $(TARGETS)
+               rm -f *.o *.new *.tmp *.rej *.orig core vgcore.* *~
                rm -f *.d
 
 realclean:     clean
index d673c14..54c73fa 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -9,8 +9,8 @@
 #include <gsl/gsl_errno.h>
 #include <gsl/gsl_multimin.h>
 
-#define BEST_F "best"
-#define INITIAL_F "initial"
+static const char *input_file, *output_file;
+static char *output_file_tmp;
 
 static double edgewise_vertex_displacement_cost(const Vertices vertices);
 static double noncircular_rim_cost(const Vertices vertices);
@@ -41,10 +41,10 @@ static double compute_energy(const Vertices vertices) {
     
     printf(" BEST");
     
-    best_f= fopen(BEST_F ".new","wb");  if (!best_f) diee("fopen new best");
+    best_f= fopen(output_file_tmp,"wb");  if (!best_f) diee("fopen new out");
     r= fwrite(vertices,sizeof(Vertices),1,best_f); if (r!=1) diee("fwrite");
     if (fclose(best_f)) diee("fclose new best");
-    if (rename(BEST_F ".new", BEST_F)) diee("rename install new best");
+    if (rename(output_file_tmp,output_file)) diee("rename install new best");
 
     best_energy= energy;
   }
@@ -129,7 +129,12 @@ int main(int argc, const char *const *argv) {
   gsl_vector initial_gsl, step_size_gsl;
   int r, v, k;
   
-  if (argc>1) { fputs("takes no arguments\n",stderr); exit(8); }
+  if (argc!=3 || argv[1][0]=='-' || strncmp(argv[2],"-o",2))
+    { fputs("usage: minimise <input> -o<output\n",stderr); exit(8); }
+
+  input_file= argv[1];
+  output_file= argv[2]+2;
+  if (asprintf(&output_file_tmp,"%s.new",output_file) <= 0) diee("asprintf");
 
   minimiser= gsl_multimin_fminimizer_alloc
     (gsl_multimin_fminimizer_nmsimplex, DIM);
@@ -139,7 +144,7 @@ int main(int argc, const char *const *argv) {
   multimin_function.n= DIM;
   multimin_function.params= 0;
 
-  initial_f= fopen(INITIAL_F,"rb");  if (!initial_f) diee("fopen initial");
+  initial_f= fopen(input_file,"rb");  if (!initial_f) diee("fopen initial");
   errno= 0; r= fread(initial,sizeof(initial),1,initial_f);
   if (r!=1) diee("fread");
   fclose(initial_f);
@@ -154,7 +159,7 @@ int main(int argc, const char *const *argv) {
   step_size_gsl.data= &step_size[0][0];
 
   FOR_VERTEX(v)
-    K step_size[v][k]= 0.01;
+    K step_size[v][k]= 0.03;
 //int vx,vy;
 //  FOR_RIM_VERTEX(vx,vy,v)
 //    step_size[v][3] *= 0.1;
index e307978..eb4bd12 100644 (file)
--- a/mgraph.h
+++ b/mgraph.h
@@ -62,9 +62,9 @@
 
 #include "common.h"
 
-#define XBITS 6 /*3*/
+#define XBITS 3
 #define X (1<<XBITS)
-#define YBITS 4
+#define YBITS 3
 #define Y ((1<<YBITS) - 1)
 
 /* vertex number:   0000 | y     | x
similarity index 100%
rename from approxmodel
rename to oldmoebius-converter
similarity index 100%
rename from generator
rename to sgtatham-regenerator