chiark / gitweb /
Optimise for per-league too
authorIan Jackson <ian@liberator.(none)>
Sat, 3 Oct 2009 09:18:46 +0000 (10:18 +0100)
committerIan Jackson <ian@liberator.(none)>
Sat, 3 Oct 2009 09:18:46 +0000 (10:18 +0100)
yarrg/rssearch.c

index c51aae0..88ea451 100644 (file)
@@ -32,26 +32,35 @@ static Neighbour *get_neighbours(int isle) {
   return head;
 }
 
-static double bestsofar;
+static double best_absolute, best_perleague;
 
-static void process_route(int nports) {
-  double value= value_route(nports, ports);
-  if (value < bestsofar) return;
+static void process_route(int nports, int totaldist) {
+  double absolute= value_route(nports, ports);
+  double perleague= absolute / totaldist;
+
+  if (absolute < best_absolute && perleague < best_perleague) return;
+
+#define CHK(absperl)                                   \
+  fprintf(stderr,#absperl " %15f", absperl);           \
+  if (absperl < best_##absperl) fputs("   ",stderr);   \
+  else { best_##absperl= absperl; fputs("** ",stderr); }
+
+  CHK(absolute)
+  CHK(perleague)
+
+  fputs(" route",stderr);
 
-  fprintf(stderr,"value %20f route", value);
   int i;
   for (i=0; i<nports; i++)
     fprintf(stderr," %d",ports[i]);
   putc('\n',stderr);
-  
-  bestsofar= value;
 }
 
 static void recurse(int last_isle,
                    int nports, /* excluding last_isle */
                    int totaldist /* including last_isle */) {
   ports[nports++]= last_isle;
-  process_route(nports);
+  process_route(nports, totaldist);
   if (nports >= MAX_ROUTELEN) return;
 
   Neighbour *add;