X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=main.c;h=cbc78857a6bf17a1b7ed95270aba783e66b1fb80;hb=d02a0a9b6bb301033c3eb01a51095c6c00fb601b;hp=86b5d7329b49aae0bd85b1ac527d9534c58e9d4a;hpb=733c8e9b1d47696122b3787a695a55bfe969a063;p=matchsticks-search.git diff --git a/main.c b/main.c index 86b5d73..cbc7885 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,8 @@ typedef uint32_t AdjWord; #define PRADJ "08"PRIx32 static int n, m; +static AdjWord *adjmatrix_counters; +static AdjWord *adjmatrix_offsets; static AdjWord *adjmatrix; static AdjWord adjall; @@ -20,13 +22,21 @@ static double best; static glp_prob *best_prob; static AdjWord *best_adjmatrix; +static unsigned printcounter; + static AdjWord *xalloc_adjmatrix(void) { return xmalloc(sizeof(*adjmatrix)*n); } static void prep(void) { + int i; adjall = ~((~(AdjWord)0) << m); adjmatrix = xalloc_adjmatrix(); + adjmatrix_counters = xalloc_adjmatrix(); + adjmatrix_offsets = xalloc_adjmatrix(); + glp_term_out(GLP_OFF); + for (i=0; i= 0 */ glp_set_col_bnds(prob, X_minimum, GLP_LO, 0, 0); + glp_set_col_name(prob, X_minimum, "minimum"); /* objective is maximising x_minimum */ glp_set_obj_dir(prob, GLP_MAX); @@ -127,6 +146,11 @@ static void optimise(void) { /* x_morefrag_i_j >= 0 */ int X_morefrag_i_j = glp_add_cols(prob, 1); glp_set_col_bnds(prob, X_morefrag_i_j, GLP_LO, 0, 0); + if (doprint) { + char buf[255]; + snprintf(buf,sizeof(buf),"mf %d,%d",i,j); + glp_set_col_name(prob, X_morefrag_i_j, buf); + } /* x_total_i += x_morefrag_i_j */ /* x_total_j += x_morefrag_i_j */ @@ -144,14 +168,14 @@ static void optimise(void) { matrix_entries); int r = glp_simplex(prob, NULL); - printf(" simplex=%d", r); + PRINTF(" glp=%d", r); #define OKERR(e) \ - case e: printf(" " #e "\n"); goto out; + case e: PRINTF(" " #e ); goto out; #define BADERR(e) \ - case e: printf(" " #e " CRASHING\n"); exit(-1); + case e: HAVE_PRINTED; printf(" " #e " CRASHING\n"); exit(-1); #define DEFAULT \ - default: printf(" ! CRASHING\n"); exit(-1); + default: HAVE_PRINTED; printf(" ! CRASHING\n"); exit(-1); switch (r) { OKERR(GLP_ESING); @@ -165,12 +189,14 @@ static void optimise(void) { BADERR(GLP_EOBJUL); BADERR(GLP_EITLIM); BADERR(GLP_ETMLIM); + BADERR(GLP_EINSTAB); + BADERR(GLP_ENOCVG); case 0: break; DEFAULT; } r = glp_get_status(prob); - printf(" status=%d", r); + PRINTF(" status=%d", r); switch (r) { OKERR(GLP_NOFEAS); @@ -183,11 +209,11 @@ static void optimise(void) { } double got = glp_get_obj_val(prob); - printf(" %g", got); - if (got <= best) { - printf("\n"); + PRINTF(" %g", got); + if (got <= best) goto out; - } + + HAVE_PRINTED; best = got; @@ -198,29 +224,38 @@ static void optimise(void) { best_adjmatrix = xalloc_adjmatrix(); memcpy(best_adjmatrix, adjmatrix, sizeof(*adjmatrix)*n); - printf(" <--\n"); + printf(" BEST \n"); return; + } out: - glp_delete_prob(prob); + if (prob) + glp_delete_prob(prob); + if (doprint) { printf(" \r"); fflush(stdout); } } static void iterate_recurse(int i, AdjWord min) { if (i >= n) { - optimise(); + int ii; + for (ii=0; ii