X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=matchsticks-search.git;a=blobdiff_plain;f=main.c;h=3ee58c59760729eba27ae8b88123caa59d9062b0;hp=3f52a86e9d76bb5cb3efc2dc42ba832b5f2a9ba3;hb=86575cc1251eca190aacac95dcb498d4efb4e7a2;hpb=fb74a77a3986b7692bdcc685453e59279288f743 diff --git a/main.c b/main.c index 3f52a86..3ee58c5 100644 --- a/main.c +++ b/main.c @@ -115,7 +115,7 @@ static double best; static glp_prob *best_prob; static AdjWord *best_adjmatrix; -static int n_max_frags, m_max_frags; +static int n_max_frags=INT_MAX, m_max_frags=INT_MAX; static int *weight; static unsigned printcounter; @@ -147,8 +147,10 @@ static void set_best(double new_best) { * subtract a fudge factor from our target. */ double near_best = best * 0.98 - 0.02; - n_max_frags = ceil(n / near_best) - 1; - m_max_frags = ceil(m / near_best) - 1; + if (near_best > 0) { + n_max_frags = ceil(n / near_best) - 1; + m_max_frags = ceil(m / near_best) - 1; + } } /*----- multicore support -----*/ @@ -390,8 +392,6 @@ static void prep(void) { glp_term_out(GLP_OFF); setlinebuf(stderr); weight = calloc(sizeof(*weight), m); assert(weight); - n_max_frags = INT_MAX; - m_max_frags = INT_MAX; } #if 0 @@ -666,7 +666,7 @@ static void iterate_recurse(int i, AdjWord min) { if (adjmatrix[i] & jbit) weight[j]++; for (int j = 0; j < m; j++) - if (weight[j] >= n_max_frags) + if (weight[j] > n_max_frags) goto takeout; iterate_recurse(i+1, adjmatrix[i]); @@ -715,7 +715,7 @@ static void report(void) { continue; a[x][y] = min + glp_get_col_prim(best_prob, i); } - printf("min fragment %g", min); + printf("min fragment %g [%s]\n", min, VERSION); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (a[i][j]) @@ -726,18 +726,18 @@ static void report(void) { printf("\n"); } } else { - printf(" none better than %9.3f ", best); + printf(" none better than %9.3f [%s]\n", best, VERSION); } - printf(" [%s]\n", VERSION); if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(-1); } } int main(int argc, char **argv) { int opt; + double best_to_set = -1.0; /* means 'don't' */ while ((opt = getopt(argc,argv,"j:b:")) >= 0) { switch (opt) { case 'j': ncpus = atoi(optarg); break; - case 'b': set_best(atof(optarg)); break; + case 'b': best_to_set = atof(optarg); break; case '+': assert(!"bad option"); default: abort(); } @@ -748,6 +748,7 @@ int main(int argc, char **argv) { n = atoi(argv[1]); m = atoi(argv[2]); assert(n > m); + if (best_to_set > 0) set_best(best_to_set); prep();