X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=matchsticks-search.git;a=blobdiff_plain;f=main.c;h=11bdf0fba64e7605e11e54511142be5d20bbf689;hp=69f56d1a30e8bba421e9e7a7231019a45f08b09d;hb=5d8f0782034b510b146a1b93d8f0c8f303eeb811;hpb=41013cb05383473c8ffdcf9afc89dde04760a847 diff --git a/main.c b/main.c index 69f56d1..11bdf0f 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, m_over_best; +static int n_max_frags, m_max_frags; static int *weight; static unsigned printcounter; @@ -119,8 +119,18 @@ static void progress_eol(void) { static void set_best(double new_best) { best = new_best; - n_over_best = floor(n / best); - m_over_best = floor(m / best); + /* + * When computing n_max_frags, we want to set a value that will skip + * anything that won't provide strictly better solutions. So we + * want + * frags < n / best + * _ _ + * <=> frags < | n / best | + * _ _ + * <=> frags <= | n / best | - 1 + */ + n_max_frags = ceil(n / best) - 1; + m_max_frags = ceil(m / best) - 1; } /*----- multicore support -----*/ @@ -356,8 +366,8 @@ static void prep(void) { glp_term_out(GLP_OFF); setlinebuf(stderr); weight = calloc(sizeof(*weight), m); assert(weight); - n_over_best = INT_MAX; - m_over_best = INT_MAX; + n_max_frags = INT_MAX; + m_max_frags = INT_MAX; } #if 0 @@ -379,7 +389,7 @@ static int count_set_adj_bits(AdjWord w) { static int totalfrags; static bool maxhamweight_ok(void) { - return maxhamweight <= m_over_best; + return maxhamweight <= m_max_frags; } static bool preconsider_ok(int nwords, bool doprint) { @@ -391,7 +401,7 @@ static bool preconsider_ok(int nwords, bool doprint) { for (i=0, totalfrags=0; i m_over_best) { + if (frags > m_max_frags) { PRINTF(" too fine"); goto out; } @@ -628,7 +638,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]);