chiark / gitweb /
fake plastic imitation weights for XBITS==5
[moebius2.git] / energy.c
index e43ecede21c987bdc638805ccc069d2ab10eff6a..c0090677b40f43c4cb09da43b36412741a06c63d 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -16,15 +16,24 @@ static void addcost(double *energy, double tweight, double tcost, int pr);
 /*---------- main energy computation, weights, etc. ----------*/
 
 typedef double CostComputation(const Vertices vertices, int section);
+typedef void PreComputation(const Vertices vertices, int section);
 
 typedef struct {
   double weight;
   CostComputation *fn;
 } CostContribution;
 
-static const CostContribution costs[]= {
+#define NPRECOMPS ((sizeof(precomps)/sizeof(precomps[0])))
+#define NCOSTS ((sizeof(costs)/sizeof(costs[0])))
 #define COST(weight, compute) { (weight),(compute) },
 
+static PreComputation *const precomps[]= {
+  compute_edge_lengths,
+  compute_vertex_areas
+};
+
+static const CostContribution costs[]= {
+
 #if XBITS==3
 #define STOP_EPSILON 1e-6
     COST(  3e3,   line_bending_cost)
@@ -49,9 +58,22 @@ static const CostContribution costs[]= {
                   #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.3)
     COST(  1e18,   noncircular_rim_cost)
 #endif
-};
 
-#define NCOSTS ((sizeof(costs)/sizeof(costs[0])))
+#if XBITS==5
+#define STOP_EPSILON 1e-6
+    COST(  3e5,   line_bending_cost)
+    COST( 10e2,   edge_length_variation_cost)
+    COST( 9.0e1,  rim_proximity_cost) // 5e1 is too much
+                                     // 2.5e1 is too little
+    // 0.2e1 grows compared to previous ?
+    // 0.6e0 shrinks compared to previous ?
+
+    COST(  1e12,   edge_angle_cost)
+                  #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.3)
+    COST(  1e18,   noncircular_rim_cost)
+#endif
+
+};
 
 const double edge_angle_cost_circcircrat= EDGE_ANGLE_COST_CIRCCIRCRAT;
 
@@ -59,24 +81,24 @@ void energy_init(void) {
   stop_epsilon= STOP_EPSILON;
 }
 
+/*---------- energy computation machinery ----------*/
+
 void compute_energy_separately(const struct Vertices *vs,
                         int section, void *energies_v, void *totals_v) {
   double *energies= energies_v;
   int ci;
-    
-  compute_edge_lengths(vs->a, section);
-  compute_vertex_areas(vs->a, section);
-
+  
+  for (ci=0; ci<NPRECOMPS; ci++) {
+    costs[ci].fn(vs->a, section);
+    inparallel_barrier();
+  }
   for (ci=0; ci<NCOSTS; ci++)
     energies[ci]= costs[ci].fn(vs->a, section);
 }
 
-/*---------- energy computation machinery ----------*/
-
 void compute_energy_combine(const struct Vertices *vertices,
                         int section, void *energies_v, void *totals_v) {
   int ci;
-  
   double *energies= energies_v;
   double *totals= totals_v;
 
@@ -94,6 +116,9 @@ double compute_energy(const struct Vertices *vs) {
 
   if (printing) printf("%15lld c>e |", evaluations);
 
+  for (ci=0; ci<NCOSTS; ci++)
+    totals[ci]= 0;
+
   inparallel(vs,
             compute_energy_separately,
             compute_energy_combine,
@@ -101,7 +126,6 @@ double compute_energy(const struct Vertices *vs) {
             totals);
 
   energy= 0;
-
   for (ci=0; ci<NCOSTS; ci++)
     addcost(&energy, costs[ci].weight, totals[ci], printing);