From: Simon Tatham Date: Sat, 8 Mar 2014 00:00:29 +0000 (+0000) Subject: Output the actual dissection, as a matrix. X-Git-Tag: v1~2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=541f31d31ac6415a4452e12b7f0e09cf0c0779ec;p=matchsticks-search.git Output the actual dissection, as a matrix. --- diff --git a/main.c b/main.c index 43cfc3e..3a7984d 100644 --- a/main.c +++ b/main.c @@ -355,8 +355,31 @@ int main(int argc, char **argv) { prep(); iterate(); printf("\n"); - if (best_prob) - glp_print_sol(best_prob,"/dev/stdout"); + if (best_prob) { + double min = glp_get_obj_val(best_prob); + double a[n][m]; + int i, j, cols; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + a[i][j] = 0; + cols = glp_get_num_cols(best_prob); + for (i = 1; i <= cols; i++) { + int x, y; + if (2 != sscanf(glp_get_col_name(best_prob, i), "mf %d,%d", &x, &y)) + continue; + a[x][y] = min + glp_get_col_prim(best_prob, i); + } + printf("%d into %d: min fragment %g\n", n, m, min); + for (i = 0; i < n; i++) { + for (j = 0; j < m; j++) { + if (a[i][j]) + printf(" %9.3f", a[i][j]); + else + printf(" "); + } + printf("\n"); + } + } if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(-1); } return 0; }