From: Ian Jackson Date: Fri, 7 Mar 2014 14:52:13 +0000 (+0000) Subject: wip lp X-Git-Tag: v1~21 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=matchsticks-search.git;a=commitdiff_plain;h=34b443b35453ef92904c2ec6d22a998d6078d028 wip lp --- diff --git a/main.c b/main.c index 6465f9b..e246752 100644 --- a/main.c +++ b/main.c @@ -20,18 +20,24 @@ static void prep(void) { adjmatrix = xmalloc(sizeof(*adjmatrix)*n); } +static AdjWord one_adj_bit(int bitnum) { + return (AdjWord)1 << j; +} + static int count_set_adj_bits(AdjWord w) { int j, total; for (j=0, total=0; j minimum (lower bound 0) * - * The objective function is simply to maximise x_minimum + * The objective function is simply + * maximise x_minimum + * + * We use X_ and Y_ to refer to GLPK's (1-based) column and row indices. + * ME_ refers to entries in the list of constraint matrix elements + * which we build up as we go. */ + glp_prob *prob = glp_create_prob(); + + int Y_totals_i = glp_add_rows(prob, i); + int Y_totals_j = glp_add_rows(prob, j); + int X_minimum = glp_add_cols(prob, 1); + int rows = glp_get_num_rows(prob); + int cols = glp_get_num_rows(cols); + + int next_matrix_entry = 1; /* wtf GLPK! */ + int matrix_entries_size = next_matrix_entry + i + j + totalfrags*2; + double matrix_entries[matrix_entries_size]; + int matrix_entries_XY[2][matrix_entries_size]; + +#define ADD_MATRIX_ENTRY(Y,X) ({ \ + assert(matrix_entries_size < next_matrix_entry); \ + matrix_entries_XY[0][next_matrix_entry] = X; \ + matrix_entries_XY[1][next_matrix_entry] = Y; \ + matrix_entries[next_matrix_entry] = 0; \ + next_matrix_entry++; \ + }) + + int ME_totals_i__minimum = next_matrix_entry; + for (i=0; i= 0 */ + glp_set_col_bounds(prob, X_minimum, GLP_LB, 0, 0); + + /* objective is maximising x_minimum */ + glp_set_obj_dir(prob, GLP_MAX); + glp_set_obj_coef(prob, X_minimum, 1); + + for (i=0; i= 0 */ + int X_morefrag_i_j = glp_add_cols(prob, 1); + glp_set_col_bnds(prob, X_morefrag_i_j, GLP_LO, 0, 0); + + /* x_total_i += x_morefrag_i_j */ + /* x_total_j += x_morefrag_i_j */ + int ME_totals_i__mf_i_j = ADD_MATRIX_ENTRY(Y_totals_i+i, X_morefrag_i_j); + int ME_totals_j__mf_i_j = ADD_MATRIX_ENTRY(Y_totals_j+j, X_morefrag_i_j); + matrix_entries[ME_totals_i__mf_i_j] = 1; + matrix_entries[ME_totals_j__mf_i_j] = 1; + } + } + + assert(next_matrix_entry == matrix_entries_size); + + for (row=1; row<=rows; row++) { + glp_load_matrix(prob, next_matrix_entry, + matrix_entries_XY[1], matrix_entries_XY[0], + matrix_entries); + printf("nyi\n"); }