X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=main.c;h=de880e9c356936fa2e847cce8d166ffa9941f6eb;hb=410a6030c8746d4369842cb0e0e35606c7ea4130;hp=e8915f7c5661dcd93fb75479e22f80ebce7f629a;hpb=966b39b19e31dfe232d74da21c76f2981eae2201;p=matchsticks-search.git diff --git a/main.c b/main.c index e8915f7..de880e9 100644 --- a/main.c +++ b/main.c @@ -101,7 +101,7 @@ static double best; static glp_prob *best_prob; static AdjWord *best_adjmatrix; -static int n_over_best; +static int n_max_frags, m_max_frags; static int *weight; static unsigned printcounter; @@ -119,7 +119,8 @@ static void progress_eol(void) { static void set_best(double new_best) { best = new_best; - n_over_best = floor(n / best); + n_max_frags = floor(n / best); + m_max_frags = floor(m / best); } /*----- multicore support -----*/ @@ -355,7 +356,8 @@ static void prep(void) { glp_term_out(GLP_OFF); setlinebuf(stderr); weight = calloc(sizeof(*weight), m); assert(weight); - n_over_best = INT_MAX; + n_max_frags = INT_MAX; + m_max_frags = INT_MAX; } #if 0 @@ -377,8 +379,7 @@ static int count_set_adj_bits(AdjWord w) { static int totalfrags; static bool maxhamweight_ok(void) { - double maxminsize = (double)m / maxhamweight; - return maxminsize > best; + return maxhamweight <= m_max_frags; } static bool preconsider_ok(int nwords, bool doprint) { @@ -389,14 +390,13 @@ static bool preconsider_ok(int nwords, bool doprint) { bool had_max = 0; for (i=0, totalfrags=0; i= maxhamweight); - totalfrags += frags; PRINTF("%"PRADJ" ", adjmatrix[i]); - double maxminsize = (double)m / frags; - if (maxminsize <= best) { + if (frags > m_max_frags) { PRINTF(" too fine"); goto out; } + had_max += (frags >= maxhamweight); + totalfrags += frags; } if (!had_max) { /* Skip this candidate as its max hamming weight is lower than @@ -628,7 +628,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_over_best) + if (weight[j] >= n_max_frags) goto takeout; iterate_recurse(i+1, adjmatrix[i]);