chiark / gitweb /
done circumcircle but it doesn't work so well
[moebius2.git] / graph.c
diff --git a/graph.c b/graph.c
index 31e317d363112027ef1eae6b7405c50cab299218..f0ce19db99fe08a1d2a0d82ab2f1746db1bae483 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -35,6 +35,9 @@ static void breadth_first_search(int start, int sqdistances_r[N]) {
     assert(d[v] >= 0);
     sqdistances_r[v]= d[v] * d[v];
   }
+
+//  FOR_VERTEX(v) {
+//    
 }
 
 void graph_layout_prepare() {
@@ -44,13 +47,13 @@ void graph_layout_prepare() {
     breadth_first_search(v1, sqdistances[v1]);
 
   alpha= 2;
-  beta= -log(10)/log(alpha);
+  beta= log(10)/log(alpha);
   beta_prime= (1-beta)/2;
   printf("alpha=%g beta=%g beta'=%g\n", alpha,beta,beta_prime);
 }
 
 
-double graph_layout_cost(const Vertices v, const double vertex_areas[N]) {
+double graph_layout_cost(const Vertices v) {
   /* For each (vi,vj) computes shortest path s_ij = |vi..vj|
    * along edges, and actual distance d_ij = |vi-vj|.
    *
@@ -93,12 +96,12 @@ double graph_layout_cost(const Vertices v, const double vertex_areas[N]) {
 
       double s2= dist2 * meanedgelength2;
 
-      /* energy = (d/s)^(1-beta)     where beta is -log\_{alpha}(10)
+      /* energy = (d/s)^(1-beta)     where beta is log\_{alpha}(10)
        * energy = ((d/s)^2) ^ (1-beta)/2
        *          let beta' = (1-beta)/2
        */
 
-      double cost= pow(d2/s2, beta_prime);
+      double cost= (vertex_mean_edge_lengths[v1]) * pow(d2/s2, beta_prime);
       
       //printf("layout %03x..%03x dist^2=%d s^2=%g d^2=%g "
               //" cost+=%g\n", v1,v2, dist2,
@@ -106,5 +109,5 @@ double graph_layout_cost(const Vertices v, const double vertex_areas[N]) {
       total_cost += cost;
     }
   }
-  return total_cost;
+  return total_cost/meanedgelength;
 }