chiark / gitweb /
revert normalisation stuff
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Wed, 16 Jan 2008 18:11:37 +0000 (18:11 +0000)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Wed, 16 Jan 2008 18:11:37 +0000 (18:11 +0000)
energy.c
minimise.h

index 1d0360fcc030dafdf62ae7e33c59271f5173bacd..bba938d45ae7fc2e4e15cc7e4cbee7f0d7998cdf 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -13,10 +13,7 @@ static double best_energy= DBL_MAX;
 static void addcost(double *energy, double tweight, double tcost, int pr);
 #define COST(weight, compute) addcost(&energy, (weight), (compute), printing)
 
-double density;
-
 void energy_init(void) {
-  density= sqrt(N);
 }
 
 /*---------- main energy computation and subroutines ----------*/
@@ -33,7 +30,7 @@ double compute_energy(const struct Vertices *vs) {
 
   if (printing) printf("cost > energy |");
 
-  COST(2.25e3, line_bending_adjcost(vs->a));
+  COST(3e2, line_bending_cost(vs->a));
   COST(1e3, edge_length_variation_cost(vs->a));
   COST(0.2e3, rim_proximity_cost(vs->a));
 //  COST(1e2, graph_layout_cost(vs->a));
@@ -141,63 +138,9 @@ void compute_vertex_areas(const Vertices vertices) {
    *                     r
    *      cost    = delta
    *          Q,e
-   *
-   * Normalisation:
-   *
-   *    We want the minimum energy to remain unchanged with changes in
-   *    triangle densitiy, when the vertices lie evenly spaced on
-   *    circles, and we do this by normalising the force ie the
-   *    derivative of the energy with respect to linear motions of the
-   *    vertices.
-   *
-   *    We consider only the force on Q due to PQR, wlog.  (Forces on
-   *    P qnd R due to PQR are equal and opposite so normalising
-   *    forces on Q will normalise them too.)
-   *
-   *    Force on Q is in the plnae PQR and normal to PR, so we can
-   *    consider it only linearly in that dimension.  WLOG let that be
-   *    the x dimension.  So with f' representing df'/dx_Q:
-   *
-   *                  ,         d
-   *      F    =  cost      =  --
-   *       Q,e         Q,e           err looks like we can only do
-   *                                 this if we make some kind of
-   *                                 assumption about delta or
-   *                                 something   give up
-   *
-   *
-   *    Interposing M and N so that we have P-M-Q-N-R
-   *    generates half as much delta for each vertex.  So
-   *
+   */
 
-   In that case the force on Q
-   *    due to PQR
-   *
-   *Normalising for equal linear
-   *    forces:
-   *
-   *                                      d
-   *      linear force on Q due to e  =  -------  cost
-   *                                     d coord       Q,e
-   *                                            Q
-   *
-   *       (we will consider only one e and one coord and hope
-   *        that doesn't lead us astray.)
-   *
-   *
-   *           ,       -r
-   *       cost    =  D   . cost
-   *           Q,e              Q,e
-   *
-   *                           where D is the linear density.
-   *
-   *                ,              -r
-   *     Sigma  cost      =   N . D  .  Sigma  cost
-   *      Q,e       Q,e                  Q,e       Q,e
-   *
-   * */
-
-double line_bending_adjcost(const Vertices vertices) {
+double line_bending_cost(const Vertices vertices) {
   static const double axb_epsilon= 1e-6;
   static const double exponent_r= 3;
 
@@ -221,7 +164,7 @@ double line_bending_adjcost(const Vertices vertices) {
 
     total_cost += cost;
   }
-  return total_cost / (N / density);
+  return total_cost;
 }
 
 /*---------- edge length variation ----------*/
@@ -230,18 +173,19 @@ double line_bending_adjcost(const Vertices vertices) {
    * Definition:
    *
    *    See the diagram above.
-   *
-   *       cost    =
+   *                                r
+   *       cost    = ( |PQ| - |QR| )
    *           Q,e
+   */
 
 double edge_length_variation_cost(const Vertices vertices) {
-  double diff, cost= 0;
+  double diff, cost= 0, exponent_r= 2;
   int q, e,r, eback;
 
   FOR_EDGE(q,e,r) {
     eback= edge_reverse(q,e);
     diff= edge_lengths[q][e] - edge_lengths[q][eback];
-    cost += diff*diff;
+    cost += pow(diff,exponent_r);
   }
   return cost;
 }
index b0d285d9b1ac16f7c4e09468cd3d5072483eaae5..2374c92dbeb20c5a0f27783848d8ecf4cb4f3161 100644 (file)
@@ -17,9 +17,7 @@ void compute_vertex_areas(const Vertices vertices);
 void compute_edge_lengths(const Vertices vertices);
 extern double vertex_areas[N], vertex_mean_edge_lengths[N], edge_lengths[N][V6];
 
-extern double density;
-
-double line_bending_adjcost(const Vertices vertices);
+double line_bending_cost(const Vertices vertices);
 double noncircular_rim_cost(const Vertices vertices);
 double edge_length_variation_cost(const Vertices vertices);
 double rim_proximity_cost(const Vertices vertices);