chiark / gitweb /
experiment with other scalings for shortest path
[moebius2.git] / bgl.cpp
diff --git a/bgl.cpp b/bgl.cpp
index 325617eca59b114fff476833f347eeb3cc718e90..5d1e0ad2540d63f8248e2ce28813dc5a8b082a00 100644 (file)
--- a/bgl.cpp
+++ b/bgl.cpp
@@ -47,8 +47,6 @@ extern "C" {
 #define VMASK (YMASK|XMASK)
 #define ESHIFT (YBITS+XBITS)
 
-class Graph { }; // this is a dummy as our graph has no actual representation
-
 using namespace boost;
 
 /*
@@ -105,6 +103,8 @@ class OutEdgeIterator :
 typedef counting_iterator<int> VertexIterator;
 
 namespace boost {
+  class Graph { }; // this is a dummy as our graph has no actual representation
+
   // We make Graph a model of various BGL Graph concepts.
   // This mainly means that graph_traits<Graph> has lots of stuff.
 
@@ -115,6 +115,7 @@ namespace boost {
     public virtual vertex_list_graph_tag,
     public virtual edge_list_graph_tag { };
 
+  template<>
   struct graph_traits<Graph> {
     // Concept Graph:
     typedef int vertex_descriptor; /* vertex number, -1 => none */
@@ -152,7 +153,8 @@ namespace boost {
   }
 
   // Concept VertexListGraph:
-  inline std::pair<VertexIterator,VertexIterator> vertices(const Graph&) {
+  inline
+  std::pair<VertexIterator,VertexIterator> vertices(const Graph&) {
     return std::make_pair(VertexIterator(0), VertexIterator(N));
   }
   inline unsigned num_vertices(const Graph&) { return N; }
@@ -188,7 +190,7 @@ double graph_layout_cost(const Vertices v, const double vertex_areas[N]) {
    */
   static const double d2_epsilon= 1e-6;
   
-  double edge_weights[N*V6], vertex_distances[N], total_cost=0;
+  double edge_weights[V6<<ESHIFT], vertex_distances[N], total_cost=0;
   int v1,v2,e,f;
 
   FOR_VERTEX(v1)
@@ -198,21 +200,22 @@ double graph_layout_cost(const Vertices v, const double vertex_areas[N]) {
       edge_weights[f]= hypotD(v[v1], v[v2]);
 
   FOR_VERTEX(v1) {
-    double a1= vertex_areas[v1];
+    //double a1= vertex_areas[v1];
     single_source_shortest_paths(v1, edge_weights, vertex_distances);
     FOR_VERTEX(v2) {
       if (v1 == v2) continue;
-      double a2= vertex_areas[v2];
+      //double a2= vertex_areas[v2];
       double d2= hypotD2plus(v[v1],v[v2], d2_epsilon);
       double s= vertex_distances[v2];
       double s2= s*s + d2_epsilon;
       double sd2= s2 / d2;
-      double cost_contrib= a1*a2 * (sd2 - 1) / (d2*d2);
-      if (cost_contrib < -1e-4) {
-       printf("layout %03x..%03x (a=%g,%g) s=%g s2=%g d2=%g sd2=%g"
-              " cost+=%g\n", v1,v2, a1,a2, s,s2,d2,sd2, cost_contrib);
-       abort();
-      }
+      //double cost_contrib= a1*a2 * (sd2 - 1) / (d2*d2);
+      double cost_contrib= sd2;
+      //if (cost_contrib < -1e-4) {
+      //       printf("layout %03x..%03x (a=%g,%g) s=%g s2=%g d2=%g sd2=%g"
+      //              " cost+=%g\n", v1,v2, a1,a2, s,s2,d2,sd2, cost_contrib);
+      //       abort();
+      //      }
       total_cost += cost_contrib;
     }
   }