chiark / gitweb /
option for starting best value
[matchsticks-search.git] / main.c
diff --git a/main.c b/main.c
index c5a49918869d9c8c1b07d865353cb856ece2c61f..2c8edfedf37d53a34ac0e23c700c70c5be25b869 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,6 +8,10 @@
  * The arguments must be ordered so that n > m:
  *   n is the number of (more, shorter) input matches of length m
  *   m is the number of (fewer, longer) output matches of length n
+ *
+ * Options:
+ *  -j<jobs>     run in parallel on <jobs> cores
+ *  -b<best>     search only for better than <best>
  */
 
 /*
@@ -138,9 +142,13 @@ static void set_best(double new_best) {
    *   <=>       frags <   |  n / best  |
    *                        _          _
    *   <=>       frags <=  |  n / best  | - 1
+   *
+   * But best values from glpk are slightly approximate, so we
+   * subtract a fudge factor from our target.
    */
-  n_max_frags = ceil(n / best) - 1;
-  m_max_frags = ceil(m / best) - 1;
+  double near_best = best * 0.98 - 0.02;
+  n_max_frags = ceil(n / near_best) - 1;
+  m_max_frags = ceil(m / near_best) - 1;
 }
 
 /*----- multicore support -----*/
@@ -712,6 +720,7 @@ int main(int argc, char **argv) {
   while ((opt = getopt(argc,argv,"j:")) >= 0) {
     switch (opt) {
     case 'j': ncpus = atoi(optarg); break;
+    case 'b': set_best(atof(optarg)); break;
     case '+': assert(!"bad option");
     default: abort();
     }