-/**
- * clean the problem instance
- */
-static void free_pi(problem_instance_t *pi) {
- DBG((dbg, LEVEL_1, "Free instance...\n"));
- del_matrix(pi->Q);
- del_matrix(pi->A);
- del_matrix(pi->B);
- del_matrix(pi->E);
- del_matrix(pi->c);
- del_set(pi->num2pos);
- del_pset(pi->removed);
- obstack_free(&pi->ob, NULL);
- free(pi);
-}
-
-#ifdef DUMP_MATRICES
-/**
- * Dump the raw matrices of the problem to a file for debugging.
- */
-static void pi_dump_matrices(problem_instance_t *pi) {
- int i;
- FILE *out = ffopen(pi->co->name, "matrix", "wt");
-
- DBG((dbg, LEVEL_1, "Dumping raw...\n"));
- fprintf(out, "\n\nx-names =\n");
- for (i=0; i<pi->x_dim; ++i)
- fprintf(out, "%5d %2d\n", pi->x[i].n, pi->x[i].c);
-
- fprintf(out, "\n\n-Q =\n");
- matrix_dump(pi->Q, out, -1);
-
- fprintf(out, "\n\nA =\n");
- matrix_dump(pi->A, out, 1);
-
- fprintf(out, "\n\nB =\n");
- matrix_dump(pi->B, out, 1);
-
- fclose(out);
-}
-#endif
-
-#ifdef DUMP_Q2ILP
-/**
- * Dumps an mps file representing the problem using a linearization of the
- * quadratic programming problem.
- */
-static void pi_dump_q2ilp(problem_instance_t *pi) {
- int i, max_abs_Qij;
- const matrix_elem_t *e;
- FILE *out;
- bitset_t *good_row;
- DBG((dbg, LEVEL_1, "Dumping q2ilp...\n"));
-
- max_abs_Qij = pi->maxQij;
- if (-pi->minQij > max_abs_Qij)
- max_abs_Qij = -pi->minQij;
- pi->bigM = pi->A_dim * max_abs_Qij;
- DBG((dbg, LEVEL_2, "BigM = %d\n", pi->bigM));
-
- matrix_optimize(pi->Q);
- good_row = bitset_alloca(pi->x_dim);
- for (i=0; i<pi->x_dim; ++i)
- if (matrix_row_first(pi->Q, i))
- bitset_set(good_row, i);
-
- out = ffopen(pi->co->name, "q2ilp", "wt");
- fprintf(out, "NAME %s\n", pi->co->name);
-
- fprintf(out, "ROWS\n");
- fprintf(out, " N obj\n");
- for (i=0; i<pi->x_dim; ++i)
- if (bitset_is_set(good_row, i))
- fprintf(out, " E cQ%d\n", i);
- for (i=0; i<pi->A_dim; ++i)
- fprintf(out, " E cA%d\n", i);
- for (i=0; i<pi->B_dim; ++i)
- fprintf(out, " L cB%d\n", i);
- for (i=0; i<pi->x_dim; ++i)
- if (bitset_is_set(good_row, i))
- fprintf(out, " L cy%d\n", i);
-
- fprintf(out, "COLUMNS\n");
- /* the x vars come first */
- /* mark them as binaries */
- fprintf(out, " MARKI0\t'MARKER'\t'INTORG'\n");
- for (i=0; i<pi->x_dim; ++i) {
- /* participation in objective */
- if (bitset_is_set(good_row, i))
- fprintf(out, " x%d_%d\tobj\t%d\n", pi->x[i].n, pi->x[i].c, -pi->bigM);
- /* in Q */
- matrix_foreach_in_col(pi->Q, i, e)
- fprintf(out, " x%d_%d\tcQ%d\t%d\n", pi->x[i].n, pi->x[i].c, e->row, e->val);
- /* in A */
- matrix_foreach_in_col(pi->A, i, e)
- fprintf(out, " x%d_%d\tcA%d\t%d\n", pi->x[i].n, pi->x[i].c, e->row, e->val);
- /* in B */
- matrix_foreach_in_col(pi->B, i, e)
- fprintf(out, " x%d_%d\tcB%d\t%d\n", pi->x[i].n, pi->x[i].c, e->row, e->val);
- /* in y */
- if (bitset_is_set(good_row, i))
- fprintf(out, " x%d_%d\tcy%d\t%d\n", pi->x[i].n, pi->x[i].c, i, 2*pi->bigM);
- }
-
- fprintf(out, " MARKI1\t'MARKER'\t'INTEND'\n"); /* end of marking */
-
- /* next the s vars */
- for (i=0; i<pi->x_dim; ++i)
- if (bitset_is_set(good_row, i)) {
- /* participation in objective */
- fprintf(out, " s%d_%d\tobj\t%d\n", pi->x[i].n, pi->x[i].c, 1);
- /* in Q */
- fprintf(out, " s%d_%d\tcQ%d\t%d\n", pi->x[i].n, pi->x[i].c, i, -1);
- }
-
- /* next the y vars */
- for (i=0; i<pi->x_dim; ++i)
- if (bitset_is_set(good_row, i)) {
- /* in Q */
- fprintf(out, " y%d_%d\tcQ%d\t%d\n", pi->x[i].n, pi->x[i].c, i, -1);
- /* in y */
- fprintf(out, " y%d_%d\tcy%d\t%d\n", pi->x[i].n, pi->x[i].c, i, 1);