chiark / gitweb /
bugfixes, smaller size
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Mon, 31 Dec 2007 12:27:38 +0000 (12:27 +0000)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Mon, 31 Dec 2007 12:27:38 +0000 (12:27 +0000)
bgl.cpp
energy.c
mgraph.c
mgraph.h

diff --git a/bgl.cpp b/bgl.cpp
index 4b06897df09a4ba5e65a903427ab021ce9261cc9..0d1f355323cb9f064281e0079e709f1e55f61d9d 100644 (file)
--- a/bgl.cpp
+++ b/bgl.cpp
@@ -22,10 +22,11 @@ extern "C" {
 }
 
 /*
- * edge descriptor f =   00 | e | y     | x
- *                            3  YBITS   XBITS
+ * edge descriptor f =   0000 | e | y     | x
+ *                              3  YBITS   XBITS
  *
- * e is 0..5.  The edge is edge e out of vertex (x,y).
+ * e is 0..6.  The edge is edge e out of vertex (x,y), or if
+ * e==6 it's the `at end' value for the out edge iterator.
  *
  * BGL expects an undirected graph's edges to have two descriptors
  * each, one in each direction (otherwise e would be just 0..2).
@@ -93,7 +94,7 @@ class OutEdgeIterator :
   OutEdgeIterator() { }
   OutEdgeIterator(int _f) : f(_f) { }
   OutEdgeIterator(int v, int e) : f(e<<ESHIFT | v) {
-    //printf("constructed v=%x e=%x f=%03x\n",v,e,f);
+    //printf("constructed v=%02x e=%x f=%03x\n",v,e,f);
   }
 
   static int voe_min(int _v) { return (_v & YMASK) ? 2 : 3; }
@@ -136,7 +137,11 @@ namespace boost {
 
   // Concept IncidenceGraph:
   inline int source(int f, const Graph&) { return f&VMASK; }
-  inline int target(int f, const Graph&) { return EDGE_END2(f&VMASK, f>>ESHIFT); }
+  inline int target(int f, const Graph&) {
+    int v2= EDGE_END2(f&VMASK, f>>ESHIFT);
+    //printf("traversed %03x..%02x\n",f,v2);
+    return v2;
+  }
   inline std::pair<OutEdgeIterator,OutEdgeIterator>
   out_edges(int v, const Graph&) {
     return std::make_pair(OutEdgeIterator(v, OutEdgeIterator::voe_min(v)),
@@ -198,9 +203,13 @@ double graph_layout_cost(const Vertices v, const double vertex_areas[N]) {
     FOR_VERTEX(v2) {
       double a2= vertex_areas[v2];
       double d2= hypotD2plus(v[v1],v[v2], d2_epsilon);
-      double sd= vertex_distances[v2] / d2;
+      double s= vertex_distances[v2];
+      double sd= s / d2;
       double sd2= sd*sd;
-      total_cost += a1*a2 * (sd2 - 1) / (d2*d2);
+      double cost_contrib= a1*a2 * (sd2 - 1) / (d2*d2);
+      //printf("layout %03x..%03x (a=%g,%g) s=%g d2=%g cost+=%g\n",
+      //            v1,v2, a1,a2, s,d2, cost_contrib);
+      total_cost += cost_contrib;
     }
   }
   return total_cost;
index 3c76b0cc207383a098ba794e900affba613b5d8a..f6907bcfda9151eea1b8cd7d4666e66f88fba7f7 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -32,7 +32,7 @@ static double compute_energy(const Vertices vertices) {
 
   COST(1000.0, edgewise_vertex_displacement_cost(vertices));
   COST(1.0,    graph_layout_cost(vertices,vertex_areas));
-  COST(1e3,    noncircular_rim_cost(vertices));
+  COST(1e-30,    noncircular_rim_cost(vertices));
   
   printf("| total %# e |", energy);
   if (energy < best_energy) {
@@ -42,9 +42,11 @@ static double compute_energy(const Vertices vertices) {
     printf(" BEST");
     
     best_f= fopen(BEST_F ".new","wb");  if (!best_f) diee("fopen new best");
-    r= fwrite(vertices,sizeof(vertices),1,best_f); if (r!=1) diee("fwrite");
+    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");
+
+    best_energy= energy;
   }
   putchar('\n');
   flushoutput();
@@ -148,11 +150,11 @@ int main(int argc, const char *const *argv) {
   initial_gsl.owner= 0;
   step_size_gsl= initial_gsl;
 
-  initial_gsl.data= (double*)initial;
-  step_size_gsl.data= (double*)step_size;
+  initial_gsl.data= &initial[0][0];
+  step_size_gsl.data= &step_size[0][0];
 
   FOR_VERTEX(v)
-    K step_size[v][k]= 1e-3;
+    K step_size[v][k]= 1e-4;
   FOR_RIM_VERTEX(vx,vy,v)
     step_size[v][3] *= 0.1;
 
index 19bb4ba2afbbafaa803e328e7e93d848a1ca1494..c66ef489230b9d245453d6930359b0e37669d55d 100644 (file)
--- a/mgraph.c
+++ b/mgraph.c
@@ -5,7 +5,7 @@
 #include "mgraph.h"
 
 static const unsigned dx[V6]= {  +1,  +1,   0,  -1,  -1,   0  },
-                      dy[V6]= {   0, +Y1, +Y1,   0, -Y1, -Y1  };
+                      dy[V6]= {   0, -Y1, -Y1,   0, +Y1, +Y1  };
 
 int edge_end2(unsigned v1, int e) {
   /* The topology is equivalent to that of a square lattice with only
index 3995d463ed0bda1160791fa997d2da40fde6ea66..acbe5c4b277b39a2c8b92aff3957c1978aae7f26 100644 (file)
--- a/mgraph.h
+++ b/mgraph.h
@@ -48,9 +48,9 @@
 
 #include "common.h"
 
-#define XBITS 4
+#define XBITS 3
 #define X (1<<XBITS)
-#define YBITS 4
+#define YBITS 3
 #define Y (1<<YBITS)
 
 /* vertex number:   0000 | y     | x