static KKTObject* LPX_kktint(LPXObject *self) { KKTObject *kkt = KKT_New(); if (!kkt) return NULL; lpx_check_int(LP, &(kkt->kkt)); return kkt; }
void pyglpk_int_check(glp_prob *lp, pyglpk_kkt_t *kkt) { #if GLPK_VERSION(4, 49) /* check primal equality constraints */ glp_check_kkt(lp, GLP_MIP, GLP_KKT_PE, &(kkt->pe_ae_max), &(kkt->pe_ae_row), &(kkt->pe_re_max), &(kkt->pe_re_row)); kkt->pe_quality = quality(kkt->pe_re_max); /* check primal bound constraints */ glp_check_kkt(lp, GLP_MIP, GLP_KKT_PB, &(kkt->pb_ae_max), &(kkt->pb_ae_ind), &(kkt->pb_re_max), &(kkt->pb_re_ind)); kkt->pb_quality = quality(kkt->pb_re_max); #else lpx_check_int(lp, kkt); #endif }
int lpx_print_mip(LPX *lp, const char *fname) { XFILE *fp; int what, round; #if 0 if (lpx_get_class(lp) != LPX_MIP) fault("lpx_print_mip: error -- not a MIP problem"); #endif xprintf( "lpx_print_mip: writing MIP problem solution to `%s'...\n", fname); fp = xfopen(fname, "w"); if (fp == NULL) { xprintf("lpx_print_mip: can't create `%s' - %s\n", fname, strerror(errno)); goto fail; } /* problem name */ { const char *name; name = lpx_get_prob_name(lp); if (name == NULL) name = ""; xfprintf(fp, "%-12s%s\n", "Problem:", name); } /* number of rows (auxiliary variables) */ { int nr; nr = lpx_get_num_rows(lp); xfprintf(fp, "%-12s%d\n", "Rows:", nr); } /* number of columns (structural variables) */ { int nc, nc_int, nc_bin; nc = lpx_get_num_cols(lp); nc_int = lpx_get_num_int(lp); nc_bin = lpx_get_num_bin(lp); xfprintf(fp, "%-12s%d (%d integer, %d binary)\n", "Columns:", nc, nc_int, nc_bin); } /* number of non-zeros (constraint coefficients) */ { int nz; nz = lpx_get_num_nz(lp); xfprintf(fp, "%-12s%d\n", "Non-zeros:", nz); } /* solution status */ { int status; status = lpx_mip_status(lp); xfprintf(fp, "%-12s%s\n", "Status:", status == LPX_I_UNDEF ? "INTEGER UNDEFINED" : status == LPX_I_OPT ? "INTEGER OPTIMAL" : status == LPX_I_FEAS ? "INTEGER NON-OPTIMAL" : status == LPX_I_NOFEAS ? "INTEGER EMPTY" : "???"); } /* objective function */ { char *name; int dir; double mip_obj; name = (void *)lpx_get_obj_name(lp); dir = lpx_get_obj_dir(lp); mip_obj = lpx_mip_obj_val(lp); xfprintf(fp, "%-12s%s%s%.10g %s\n", "Objective:", name == NULL ? "" : name, name == NULL ? "" : " = ", mip_obj, dir == LPX_MIN ? "(MINimum)" : dir == LPX_MAX ? "(MAXimum)" : "(" "???" ")"); } /* main sheet */ for (what = 1; what <= 2; what++) { int mn, ij; xfprintf(fp, "\n"); xfprintf(fp, " No. %-12s Activity Lower bound Upp" "er bound\n", what == 1 ? " Row name" : "Column name"); xfprintf(fp, "------ ------------ ------------- -----------" "-- -------------\n"); mn = (what == 1 ? lpx_get_num_rows(lp) : lpx_get_num_cols(lp)); for (ij = 1; ij <= mn; ij++) { const char *name; int kind, typx; double lb, ub, vx; if (what == 1) { name = lpx_get_row_name(lp, ij); if (name == NULL) name = ""; kind = LPX_CV; lpx_get_row_bnds(lp, ij, &typx, &lb, &ub); round = lpx_get_int_parm(lp, LPX_K_ROUND); lpx_set_int_parm(lp, LPX_K_ROUND, 1); vx = lpx_mip_row_val(lp, ij); lpx_set_int_parm(lp, LPX_K_ROUND, round); } else { name = lpx_get_col_name(lp, ij); if (name == NULL) name = ""; kind = lpx_get_col_kind(lp, ij); lpx_get_col_bnds(lp, ij, &typx, &lb, &ub); round = lpx_get_int_parm(lp, LPX_K_ROUND); lpx_set_int_parm(lp, LPX_K_ROUND, 1); vx = lpx_mip_col_val(lp, ij); lpx_set_int_parm(lp, LPX_K_ROUND, round); } /* row/column ordinal number */ xfprintf(fp, "%6d ", ij); /* row column/name */ if (strlen(name) <= 12) xfprintf(fp, "%-12s ", name); else xfprintf(fp, "%s\n%20s", name, ""); /* row/column kind */ xfprintf(fp, "%s ", kind == LPX_CV ? " " : kind == LPX_IV ? "*" : "?"); /* row/column primal activity */ xfprintf(fp, "%13.6g", vx); /* row/column lower and upper bounds */ switch (typx) { case LPX_FR: break; case LPX_LO: xfprintf(fp, " %13.6g", lb); break; case LPX_UP: xfprintf(fp, " %13s %13.6g", "", ub); break; case LPX_DB: xfprintf(fp, " %13.6g %13.6g", lb, ub); break; case LPX_FX: xfprintf(fp, " %13.6g %13s", lb, "="); break; default: xassert(typx != typx); } /* end of line */ xfprintf(fp, "\n"); } } xfprintf(fp, "\n"); #if 1 if (lpx_mip_status(lp) != LPX_I_UNDEF) { int m = lpx_get_num_rows(lp); LPXKKT kkt; xfprintf(fp, "Integer feasibility conditions:\n\n"); lpx_check_int(lp, &kkt); xfprintf(fp, "INT.PE: max.abs.err. = %.2e on row %d\n", kkt.pe_ae_max, kkt.pe_ae_row); xfprintf(fp, " max.rel.err. = %.2e on row %d\n", kkt.pe_re_max, kkt.pe_re_row); switch (kkt.pe_quality) { case 'H': xfprintf(fp, " High quality\n"); break; case 'M': xfprintf(fp, " Medium quality\n"); break; case 'L': xfprintf(fp, " Low quality\n"); break; default: xfprintf(fp, " SOLUTION IS WRONG\n"); break; } xfprintf(fp, "\n"); xfprintf(fp, "INT.PB: max.abs.err. = %.2e on %s %d\n", kkt.pb_ae_max, kkt.pb_ae_ind <= m ? "row" : "column", kkt.pb_ae_ind <= m ? kkt.pb_ae_ind : kkt.pb_ae_ind - m); xfprintf(fp, " max.rel.err. = %.2e on %s %d\n", kkt.pb_re_max, kkt.pb_re_ind <= m ? "row" : "column", kkt.pb_re_ind <= m ? kkt.pb_re_ind : kkt.pb_re_ind - m); switch (kkt.pb_quality) { case 'H': xfprintf(fp, " High quality\n"); break; case 'M': xfprintf(fp, " Medium quality\n"); break; case 'L': xfprintf(fp, " Low quality\n"); break; default: xfprintf(fp, " SOLUTION IS INFEASIBLE\n"); break; } xfprintf(fp, "\n"); } #endif xfprintf(fp, "End of output\n"); xfflush(fp); if (xferror(fp)) { xprintf("lpx_print_mip: can't write to `%s' - %s\n", fname, strerror(errno)); goto fail; } xfclose(fp); return 0; fail: if (fp != NULL) xfclose(fp); return 1; }