chiark / gitweb /
best interpolation so far
[moebius2.git] / energy.c
index bba938d45ae7fc2e4e15cc7e4cbee7f0d7998cdf..dd9206f4b7a5cb80c3178cfc9f35ae603982158f 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -19,6 +19,8 @@ void energy_init(void) {
 /*---------- main energy computation and subroutines ----------*/
 
 double compute_energy(const struct Vertices *vs) {
 /*---------- main energy computation and subroutines ----------*/
 
 double compute_energy(const struct Vertices *vs) {
+  static int bests_unprinted;
+  
   double energy;
   int printing;
 
   double energy;
   int printing;
 
@@ -28,13 +30,12 @@ double compute_energy(const struct Vertices *vs) {
 
   printing= printing_check(pr_cost,0);
 
 
   printing= printing_check(pr_cost,0);
 
-  if (printing) printf("cost > energy |");
+  if (printing) printf("%15lld c>e |", evaluations);
 
 
-  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));
-  COST(1e8, noncircular_rim_cost(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(  1e8,   noncircular_rim_cost(vs->a));
 
   if (printing) printf("| total %# e |", energy);
 
 
   if (printing) printf("| total %# e |", energy);
 
@@ -42,12 +43,18 @@ double compute_energy(const struct Vertices *vs) {
     FILE *best_f;
     int r;
 
     FILE *best_f;
     int r;
 
-    if (printing) printf(" BEST");
+    if (printing) {
+      printf(" BEST");
+      if (bests_unprinted) printf(" [%4d]",bests_unprinted);
+      bests_unprinted= 0;
+    } else {
+      bests_unprinted++;
+    }
 
 
-    best_f= fopen(output_file_tmp,"wb");  if (!best_f) diee("fopen new out");
+    best_f= fopen(best_file_tmp,"wb");  if (!best_f) diee("fopen new out");
     r= fwrite(vs->a,sizeof(vs->a),1,best_f); if (r!=1) diee("fwrite");
     if (fclose(best_f)) diee("fclose new best");
     r= fwrite(vs->a,sizeof(vs->a),1,best_f); if (r!=1) diee("fwrite");
     if (fclose(best_f)) diee("fclose new best");
-    if (rename(output_file_tmp,output_file)) diee("rename install new best");
+    if (rename(best_file_tmp,best_file)) diee("rename install new best");
 
     best_energy= energy;
   }
 
     best_energy= energy;
   }
@@ -56,12 +63,13 @@ double compute_energy(const struct Vertices *vs) {
     flushoutput();
   }
 
     flushoutput();
   }
 
+  evaluations++;
   return energy;
 }
 
 static void addcost(double *energy, double tweight, double tcost, int pr) {
   double tenergy= tweight * tcost;
   return energy;
 }
 
 static void addcost(double *energy, double tweight, double tcost, int pr) {
   double tenergy= tweight * tcost;
-  if (pr) printf(" %# e x %# e > %# e* |", tcost, tweight, tenergy);
+  if (pr) printf(" %# e x %g > %# e* |", tcost, tweight, tenergy);
   *energy += tenergy;
 }
 
   *energy += tenergy;
 }