void glp_std_basis(glp_prob *lp) { int i, j; /* make all auxiliary variables basic */ for (i = 1; i <= lp->m; i++) glp_set_row_stat(lp, i, GLP_BS); /* make all structural variables non-basic */ for (j = 1; j <= lp->n; j++) { GLPCOL *col = lp->col[j]; if (col->type == GLP_DB && fabs(col->lb) > fabs(col->ub)) glp_set_col_stat(lp, j, GLP_NU); else glp_set_col_stat(lp, j, GLP_NL); } return; }
int glp_read_sol(glp_prob *lp, const char *fname) { glp_data *data; jmp_buf jump; int i, j, k, ret = 0; xprintf("Reading basic solution from '%s'...\n", fname); data = glp_sdf_open_file(fname); if (data == NULL) { ret = 1; goto done; } if (setjmp(jump)) { ret = 1; goto done; } glp_sdf_set_jump(data, jump); /* number of rows, number of columns */ k = glp_sdf_read_int(data); if (k != lp->m) glp_sdf_error(data, "wrong number of rows\n"); k = glp_sdf_read_int(data); if (k != lp->n) glp_sdf_error(data, "wrong number of columns\n"); /* primal status, dual status, objective value */ k = glp_sdf_read_int(data); if (!(k == GLP_UNDEF || k == GLP_FEAS || k == GLP_INFEAS || k == GLP_NOFEAS)) glp_sdf_error(data, "invalid primal status\n"); lp->pbs_stat = k; k = glp_sdf_read_int(data); if (!(k == GLP_UNDEF || k == GLP_FEAS || k == GLP_INFEAS || k == GLP_NOFEAS)) glp_sdf_error(data, "invalid dual status\n"); lp->dbs_stat = k; lp->obj_val = glp_sdf_read_num(data); /* rows (auxiliary variables) */ for (i = 1; i <= lp->m; i++) { GLPROW *row = lp->row[i]; /* status, primal value, dual value */ k = glp_sdf_read_int(data); if (!(k == GLP_BS || k == GLP_NL || k == GLP_NU || k == GLP_NF || k == GLP_NS)) glp_sdf_error(data, "invalid row status\n"); glp_set_row_stat(lp, i, k); row->prim = glp_sdf_read_num(data); row->dual = glp_sdf_read_num(data); } /* columns (structural variables) */ for (j = 1; j <= lp->n; j++) { GLPCOL *col = lp->col[j]; /* status, primal value, dual value */ k = glp_sdf_read_int(data); if (!(k == GLP_BS || k == GLP_NL || k == GLP_NU || k == GLP_NF || k == GLP_NS)) glp_sdf_error(data, "invalid column status\n"); glp_set_col_stat(lp, j, k); col->prim = glp_sdf_read_num(data); col->dual = glp_sdf_read_num(data); } xprintf("%d lines were read\n", glp_sdf_line(data)); done: if (ret) lp->pbs_stat = lp->dbs_stat = GLP_UNDEF; if (data != NULL) glp_sdf_close_file(data); return ret; }
void glp_adv_basis(glp_prob *P, int flags) { int i, j, k, m, n, min_mn, size, *rn, *cn; char *flag; if (flags != 0) xerror("glp_adv_basis: flags = %d; invalid flags\n", flags); m = P->m; /* number of rows */ n = P->n; /* number of columns */ if (m == 0 || n == 0) { /* trivial case */ glp_std_basis(P); goto done; } xprintf("Constructing initial basis...\n"); /* allocate working arrays */ min_mn = (m < n ? m : n); rn = talloc(1+min_mn, int); cn = talloc(1+min_mn, int); flag = talloc(1+m, char); /* make the basis empty */ for (i = 1; i <= m; i++) { flag[i] = 0; glp_set_row_stat(P, i, GLP_NS); } for (j = 1; j <= n; j++) glp_set_col_stat(P, j, GLP_NS); /* find maximal triangular part of the constraint matrix; to prevent including non-fixed rows and fixed columns in the triangular part, such rows and columns are temporarily made empty by the routine mat */ #if 1 /* FIXME: tolerance */ size = triang(m, n, mat, P, 0.001, rn, cn); #endif xassert(0 <= size && size <= min_mn); /* include in the basis non-fixed structural variables, whose columns constitute the triangular part */ for (k = 1; k <= size; k++) { i = rn[k]; xassert(1 <= i && i <= m); flag[i] = 1; j = cn[k]; xassert(1 <= j && j <= n); glp_set_col_stat(P, j, GLP_BS); } /* include in the basis appropriate auxiliary variables, whose unity columns preserve triangular form of the basis matrix */ for (i = 1; i <= m; i++) { if (flag[i] == 0) { glp_set_row_stat(P, i, GLP_BS); if (P->row[i]->type != GLP_FX) size++; } } /* size of triangular part = (number of rows) - (number of basic fixed auxiliary variables) */ xprintf("Size of triangular part is %d\n", size); /* deallocate working arrays */ tfree(rn); tfree(cn); tfree(flag); done: return; }
void lpx_set_row_stat(LPX *lp, int i, int stat) { /* set (change) row status */ glp_set_row_stat(lp, i, stat - LPX_BS + GLP_BS); return; }