void REPORT_constraints(lprec *lp, int columns) { int i, n; LPSREAL value; MYBOOL NZonly = (MYBOOL) ((lp->print_sol & AUTOMATIC) > 0); if(lp->outstream == NULL) return; if(columns <= 0) columns = 2; fprintf(lp->outstream, "\nActual values of the constraints:\n"); n = 0; for(i = 1; i <= lp->rows; i++) { value = (double)lp->best_solution[i]; if(NZonly && (fabs(value) < lp->epsprimal)) continue; n = (n+1) % columns; fprintf(lp->outstream, "%-20s %12g", get_row_name(lp, i), value); if(n == 0) fprintf(lp->outstream, "\n"); else fprintf(lp->outstream, " "); } fflush(lp->outstream); }
void REPORT_duals(lprec *lp) { int i; LPSREAL *duals, *dualsfrom, *dualstill, *objfrom, *objtill, *objfromvalue; MYBOOL ret; if(lp->outstream == NULL) return; ret = get_ptr_sensitivity_objex(lp, &objfrom, &objtill, &objfromvalue, NULL); if(ret) { fprintf(lp->outstream, "\nObjective function limits:\n"); fprintf(lp->outstream, " From Till FromValue\n"); for(i = 1; i <= lp->columns; i++) if(!is_splitvar(lp, i)) fprintf(lp->outstream, "%-20s %15.7g %15.7g %15.7g\n", get_col_name(lp, i), (double)objfrom[i - 1], (double)objtill[i - 1], (double)objfromvalue[i - 1]); } ret = get_ptr_sensitivity_rhs(lp, &duals, &dualsfrom, &dualstill); if(ret) { fprintf(lp->outstream, "\nDual values with from - till limits:\n"); fprintf(lp->outstream, " Dual value From Till\n"); for(i = 1; i <= lp->sum; i++) fprintf(lp->outstream, "%-20s %15.7g %15.7g %15.7g\n", (i <= lp->rows) ? get_row_name(lp, i) : get_col_name(lp, i - lp->rows), (double)duals[i - 1], (double)dualsfrom[i - 1], (double)dualstill[i - 1]); fflush(lp->outstream); } }
strvec MtxLP::getRowNames() const{ strvec rv; int nrows = get_num_rows(); for (int i = 1; i <= nrows; i++) rv.push_back(get_row_name(i)); return rv; }
/* Get the name of a constraint row */ char __declspec(dllexport) *WINAPI _get_row_name(lprec *lp, long row) { char *ret; if (lp != NULL) { freebuferror(); ret = get_row_name(lp, row); } else ret = NULL; return(ret); }
/* Printing of sensitivity analysis reports */ void REPORT_extended(lprec *lp) { int i, j; LPSREAL hold; LPSREAL *duals, *dualsfrom, *dualstill, *objfrom, *objtill; MYBOOL ret; ret = get_ptr_sensitivity_obj(lp, &objfrom, &objtill); report(lp, NORMAL, " \n"); report(lp, NORMAL, "Primal objective:\n"); report(lp, NORMAL, " \n"); report(lp, NORMAL, " Column name Value Objective Min Max\n"); report(lp, NORMAL, " --------------------------------------------------------------------------\n"); for(j = 1; j <= lp->columns; j++) { hold = get_mat(lp,0,j); report(lp, NORMAL, " %-25s " MPSVALUEMASK MPSVALUEMASK MPSVALUEMASK MPSVALUEMASK "\n", get_col_name(lp,j), my_precision(hold,lp->epsprimal), my_precision(hold*lp->best_solution[lp->rows+j],lp->epsprimal), my_precision((ret) ? objfrom[j - 1] : 0.0,lp->epsprimal), my_precision((ret) ? objtill[j - 1] : 0.0,lp->epsprimal)); } report(lp, NORMAL, " \n"); ret = get_ptr_sensitivity_rhs(lp, &duals, &dualsfrom, &dualstill); report(lp, NORMAL, "Primal variables:\n"); report(lp, NORMAL, " \n"); report(lp, NORMAL, " Column name Value Slack Min Max\n"); report(lp, NORMAL, " --------------------------------------------------------------------------\n"); for(j = 1; j <= lp->columns; j++) report(lp, NORMAL, " %-25s " MPSVALUEMASK MPSVALUEMASK MPSVALUEMASK MPSVALUEMASK "\n", get_col_name(lp,j), my_precision(lp->best_solution[lp->rows+j],lp->epsprimal), my_precision(my_inflimit(lp, (ret) ? duals[lp->rows+j-1] : 0.0),lp->epsprimal), my_precision((ret) ? dualsfrom[lp->rows+j-1] : 0.0,lp->epsprimal), my_precision((ret) ? dualstill[lp->rows+j-1] : 0.0,lp->epsprimal)); report(lp, NORMAL, " \n"); report(lp, NORMAL, "Dual variables:\n"); report(lp, NORMAL, " \n"); report(lp, NORMAL, " Row name Value Slack Min Max\n"); report(lp, NORMAL, " --------------------------------------------------------------------------\n"); for(i = 1; i <= lp->rows; i++) report(lp, NORMAL, " %-25s " MPSVALUEMASK MPSVALUEMASK MPSVALUEMASK MPSVALUEMASK "\n", get_row_name(lp,i), my_precision((ret) ? duals[i - 1] : 0.0, lp->epsprimal), my_precision(lp->best_solution[i], lp->epsprimal), my_precision((ret) ? dualsfrom[i - 1] : 0.0,lp->epsprimal), my_precision((ret) ? dualstill[i - 1] : 0.0,lp->epsprimal)); report(lp, NORMAL, " \n"); }
static void printminmax(lprec *lp, char *s, REAL *minima, REAL *maxima, int nminima, int nmaxima, int *rowmin, int *rowmax, int *colmin, int *colmax) { int i, nminmax, n; nminmax = nminima; if (nmaxima > nminmax) nminmax = nmaxima; for (i = 0; i < nminmax; i++) { n = 0; if (i < nminima) { n += printf("%s(", s); if (rowmin != NULL) n+= printf("%s", get_row_name(lp, rowmin[i])); if ((rowmin != NULL) && (colmin != NULL)) n += printf(", "); if (colmin != NULL) n += printf("%s", get_col_name(lp, colmin[i])); n += printf(") = %.8f", minima[i]); } if (n < 40) n = 40 - n; else n = 1; printf("%*.*s", n, n, ""); if (i < nmaxima) { n += printf("%s(", s); if (rowmax != NULL) n+= printf("%s", get_row_name(lp, rowmax[i])); if ((rowmax != NULL) && (colmax != NULL)) n += printf(", "); if (colmax != NULL) n += printf("%s", get_col_name(lp, colmax[i])); n += printf(") = %.8f", maxima[i]); } printf("\n"); } }
/* Report the scaling factors used; extremely rarely used */ void REPORT_scales(lprec *lp) { int i, colMax; colMax = lp->columns; if(lp->outstream == NULL) return; if(lp->scaling_used) { fprintf(lp->outstream, "\nScale factors:\n"); for(i = 0; i <= lp->rows + colMax; i++) fprintf(lp->outstream, "%-20s scaled at %g\n", (i <= lp->rows) ? get_row_name(lp, i) : get_col_name(lp, i - lp->rows), (double)lp->scalars[i]); } fflush(lp->outstream); }
stomap* MtxLP::getColSto(string name) const{ stomap* rv = new stomap; int n = ncol(name); if (n == 0) throw runtime_error(name + ": no such row!"); int len = get_num_rows(); int *inds = new int[len + 1]; double *vals = new double[len + 1]; len = get_mat_col(n, inds, vals); for (int i = 1; i <= len; i++){ if (inds[i] <= mtxlen) (*rv)[get_row_name(inds[i])] = vals[i]; } delete inds; delete vals; return rv; }
void REPORT_modelinfo(lprec *lp, MYBOOL doName, char *datainfo) { if(doName) { report(lp, NORMAL, "\nModel name: '%s' - run #%-5d\n", get_lp_name(lp), lp->solvecount); report(lp, NORMAL, "Objective: %simize(%s)\n", my_if(is_maxim(lp), "Max", "Min"), get_row_name(lp, 0)); report(lp, NORMAL, " \n"); } if(datainfo != NULL) report(lp, NORMAL, "%s\n", datainfo); report(lp, NORMAL, "Model size: %7d constraints, %7d variables, %12d non-zeros.\n", lp->rows, lp->columns, get_nonzeros(lp)); if(GUB_count(lp)+SOS_count(lp) > 0) report(lp, NORMAL, "Var-types: %7d integer, %7d semi-cont., %7d SOS.\n", lp->int_vars, lp->sc_vars, lp->sos_vars); report(lp, NORMAL, "Sets: %7d GUB, %7d SOS.\n", GUB_count(lp), SOS_count(lp)); }
/* A more readable lp-format report of the model; antiquated and not updated */ void REPORT_lp(lprec *lp) { int i, j; if(lp->outstream == NULL) return; fprintf(lp->outstream, "Model name: %s\n", get_lp_name(lp)); fprintf(lp->outstream, " "); for(j = 1; j <= lp->columns; j++) fprintf(lp->outstream, "%8s ", get_col_name(lp,j)); fprintf(lp->outstream, "\n%simize ", (is_maxim(lp) ? "Max" : "Min")); for(j = 1; j <= lp->columns; j++) fprintf(lp->outstream, "%8g ", get_mat(lp, 0, j)); fprintf(lp->outstream, "\n"); for(i = 1; i <= lp->rows; i++) { fprintf(lp->outstream, "%-9s ", get_row_name(lp, i)); for(j = 1; j <= lp->columns; j++) fprintf(lp->outstream, "%8g ", get_mat(lp, i, j)); if(is_constr_type(lp, i, GE)) fprintf(lp->outstream, ">= "); else if(is_constr_type(lp, i, LE)) fprintf(lp->outstream, "<= "); else fprintf(lp->outstream, " = "); fprintf(lp->outstream, "%8g", get_rh(lp, i)); if(is_constr_type(lp, i, GE)) { if(get_rh_upper(lp, i) < lp->infinite) fprintf(lp->outstream, " %s = %8g", "upbo", get_rh_upper(lp, i)); } else if(is_constr_type(lp, i, LE)) { if(get_rh_lower(lp, i) > -lp->infinite) fprintf(lp->outstream, " %s = %8g", "lowbo", get_rh_lower(lp, i)); } fprintf(lp->outstream, "\n"); } fprintf(lp->outstream, "Type "); for(i = 1; i <= lp->columns; i++) { if(is_int(lp,i)) fprintf(lp->outstream, " Int "); else fprintf(lp->outstream, " Real "); } fprintf(lp->outstream, "\nupbo "); for(i = 1; i <= lp->columns; i++) if(get_upbo(lp, i) >= lp->infinite) fprintf(lp->outstream, " Inf "); else fprintf(lp->outstream, "%8g ", get_upbo(lp, i)); fprintf(lp->outstream, "\nlowbo "); for(i = 1; i <= lp->columns; i++) if(get_lowbo(lp, i) <= -lp->infinite) fprintf(lp->outstream, " -Inf "); else fprintf(lp->outstream, "%8g ", get_lowbo(lp, i)); fprintf(lp->outstream, "\n"); fflush(lp->outstream); }
MYBOOL __WINAPI write_lpex(lprec *lp, void *userhandle, write_modeldata_func write_modeldata) { int i, j, b, nrows = lp->rows, ncols = lp->columns, nchars, maxlen = LP_MAXLINELEN; MYBOOL ok; REAL a; char *ptr; if(lp->matA->is_roworder) { report(lp, IMPORTANT, "LP_writefile: Cannot write to LP file while in row entry mode.\n"); return(FALSE); } if(!mat_validate(lp->matA)) { report(lp, IMPORTANT, "LP_writefile: Could not validate the data matrix.\n"); return(FALSE); } /* Write name of model */ ptr = get_lp_name(lp); if(ptr != NULL) if(*ptr) write_lpcomment(userhandle, write_modeldata, ptr, FALSE); else ptr = NULL; /* Write the objective function */ write_lpcomment(userhandle, write_modeldata, "Objective function", (MYBOOL) (ptr != NULL)); if(is_maxim(lp)) write_data(userhandle, write_modeldata, "max: "); else write_data(userhandle, write_modeldata, "min: "); write_lprow(lp, 0, userhandle, write_modeldata, maxlen); a = get_rh(lp, 0); if(a != 0) write_data(userhandle, write_modeldata, " %+.12g", a); write_data(userhandle, write_modeldata, ";\n"); /* Write constraints */ if(nrows > 0) write_lpcomment(userhandle, write_modeldata, "Constraints", TRUE); for(j = 1; j <= nrows; j++) { if(((lp->names_used) && (lp->row_name[j] != NULL)) || (write_lprow(lp, j, userhandle, NULL, maxlen) == 1)) ptr = get_row_name(lp, j); else ptr = NULL; if((ptr != NULL) && (*ptr)) write_data(userhandle, write_modeldata, "%s: ", ptr); #ifndef SingleBoundedRowInLP /* Write the ranged part of the constraint, if specified */ if ((lp->orig_upbo[j]) && (lp->orig_upbo[j] < lp->infinite)) { if(my_chsign(is_chsign(lp, j), lp->orig_rhs[j]) == -lp->infinite) write_data(userhandle, write_modeldata, "-Inf %s ", (is_chsign(lp, j)) ? ">=" : "<="); else if(my_chsign(is_chsign(lp, j), lp->orig_rhs[j]) == lp->infinite) write_data(userhandle, write_modeldata, "+Inf %s ", (is_chsign(lp, j)) ? ">=" : "<="); else write_data(userhandle, write_modeldata, "%+.12g %s ", (lp->orig_upbo[j]-lp->orig_rhs[j]) * (is_chsign(lp, j) ? 1.0 : -1.0) / (lp->scaling_used ? lp->scalars[j] : 1.0), (is_chsign(lp, j)) ? ">=" : "<="); } #endif if((!write_lprow(lp, j, userhandle, write_modeldata, maxlen)) && (ncols >= 1)) write_data(userhandle, write_modeldata, "0 %s", get_col_name(lp, 1)); if(lp->orig_upbo[j] == 0) write_data(userhandle, write_modeldata, " ="); else if(is_chsign(lp, j)) write_data(userhandle, write_modeldata, " >="); else write_data(userhandle, write_modeldata, " <="); if(fabs(get_rh(lp, j) + lp->infinite) < 1) write_data(userhandle, write_modeldata, " -Inf;\n"); else if(fabs(get_rh(lp, j) - lp->infinite) < 1) write_data(userhandle, write_modeldata, " +Inf;\n"); else write_data(userhandle, write_modeldata, " %.12g;\n", get_rh(lp, j)); #ifdef SingleBoundedRowInLP /* Write the ranged part of the constraint, if specified */ if ((lp->orig_upbo[j]) && (lp->orig_upbo[j] < lp->infinite)) { if(((lp->names_used) && (lp->row_name[j] != NULL)) || (write_lprow(lp, j, userhandle, NULL, maxlen) == 1)) ptr = get_row_name(lp, j); else ptr = NULL; if((ptr != NULL) && (*ptr)) write_data(userhandle, write_modeldata, "%s: ", ptr); if((!write_lprow(lp, j, userhandle, write_modeldata, maxlen)) && (get_Ncolumns(lp) >= 1)) write_data(userhandle, write_modeldata, "0 %s", get_col_name(lp, 1)); write_data(userhandle, write_modeldata, " %s %g;\n", (is_chsign(lp, j)) ? "<=" : ">=", (lp->orig_upbo[j]-lp->orig_rhs[j]) * (is_chsign(lp, j) ? 1.0 : -1.0) / (lp->scaling_used ? lp->scalars[j] : 1.0)); } #endif } /* Write bounds on variables */ ok = FALSE; for(i = nrows + 1; i <= lp->sum; i++) if(!is_splitvar(lp, i - nrows)) { if(lp->orig_lowbo[i] == lp->orig_upbo[i]) { if(!ok) { write_lpcomment(userhandle, write_modeldata, "Variable bounds", TRUE); ok = TRUE; } write_data(userhandle, write_modeldata, "%s = %.12g;\n", get_col_name(lp, i - nrows), get_upbo(lp, i - nrows)); } else { #ifndef SingleBoundedRowInLP if((lp->orig_lowbo[i] != 0) && (lp->orig_upbo[i] < lp->infinite)) { if(!ok) { write_lpcomment(userhandle, write_modeldata, "Variable bounds", TRUE); ok = TRUE; } if(lp->orig_lowbo[i] == -lp->infinite) write_data(userhandle, write_modeldata, "-Inf"); else write_data(userhandle, write_modeldata, "%.12g", get_lowbo(lp, i - nrows)); write_data(userhandle, write_modeldata, " <= %s <= ", get_col_name(lp, i - nrows)); if(lp->orig_lowbo[i] == lp->infinite) write_data(userhandle, write_modeldata, "+Inf"); else write_data(userhandle, write_modeldata, "%.12g", get_upbo(lp, i - nrows)); write_data(userhandle, write_modeldata, ";\n"); } else #endif { if(lp->orig_lowbo[i] != 0) { if(!ok) { write_lpcomment(userhandle, write_modeldata, "Variable bounds", TRUE); ok = TRUE; } if(lp->orig_lowbo[i] == -lp->infinite) write_data(userhandle, write_modeldata, "%s >= -Inf;\n", get_col_name(lp, i - nrows)); else if(lp->orig_lowbo[i] == lp->infinite) write_data(userhandle, write_modeldata, "%s >= +Inf;\n", get_col_name(lp, i - nrows)); else write_data(userhandle, write_modeldata, "%s >= %.12g;\n", get_col_name(lp, i - nrows), get_lowbo(lp, i - nrows)); } if(lp->orig_upbo[i] != lp->infinite) { if(!ok) { write_lpcomment(userhandle, write_modeldata, "Variable bounds", TRUE); ok = TRUE; } write_data(userhandle, write_modeldata, "%s <= %.12g;\n", get_col_name(lp, i - nrows), get_upbo(lp, i - nrows)); } } } } /* Write optional integer section */ if(lp->int_vars > 0) { write_lpcomment(userhandle, write_modeldata, "Integer definitions", TRUE); i = 1; while((i <= ncols) && !is_int(lp, i)) i++; if(i <= ncols) { nchars = write_data(userhandle, write_modeldata, "int %s", get_col_name(lp, i)); i++; for(; i <= ncols; i++) if((!is_splitvar(lp, i)) && (is_int(lp, i))) { if((maxlen!= 0) && (nchars > maxlen)) { write_data(userhandle, write_modeldata, "%s", "\n"); nchars = 0; } write_data(userhandle, write_modeldata, ",%s", get_col_name(lp, i)); } write_data(userhandle, write_modeldata, ";\n"); } } /* Write optional SEC section */ if(lp->sc_vars > 0) { write_lpcomment(userhandle, write_modeldata, "Semi-continuous variables", TRUE); i = 1; while((i <= ncols) && !is_semicont(lp, i)) i++; if(i <= ncols) { nchars = write_data(userhandle, write_modeldata, "sec %s", get_col_name(lp, i)); i++; for(; i <= ncols; i++) if((!is_splitvar(lp, i)) && (is_semicont(lp, i))) { if((maxlen != 0) && (nchars > maxlen)) { write_data(userhandle, write_modeldata, "%s", "\n"); nchars = 0; } nchars += write_data(userhandle, write_modeldata, ",%s", get_col_name(lp, i)); } write_data(userhandle, write_modeldata, ";\n"); } } /* Write optional SOS section */ if(SOS_count(lp) > 0) { SOSgroup *SOS = lp->SOS; write_lpcomment(userhandle, write_modeldata, "SOS definitions", TRUE); write_data(userhandle, write_modeldata, "SOS\n"); for(b = 0, i = 0; i < SOS->sos_count; b = SOS->sos_list[i]->priority, i++) { nchars = write_data(userhandle, write_modeldata, "%s: ", (SOS->sos_list[i]->name == NULL) || (*SOS->sos_list[i]->name==0) ? "SOS" : SOS->sos_list[i]->name); /* formatnumber12((double) lp->sos_list[i]->priority) */ for(a = 0.0, j = 1; j <= SOS->sos_list[i]->size; a = SOS->sos_list[i]->weights[j], j++) { if((maxlen != 0) && (nchars > maxlen)) { write_data(userhandle, write_modeldata, "%s", "\n"); nchars = 0; } if(SOS->sos_list[i]->weights[j] == ++a) nchars += write_data(userhandle, write_modeldata, "%s%s", (j > 1) ? "," : "", get_col_name(lp, SOS->sos_list[i]->members[j])); else nchars += write_data(userhandle, write_modeldata, "%s%s:%.12g", (j > 1) ? "," : "", get_col_name(lp, SOS->sos_list[i]->members[j]), SOS->sos_list[i]->weights[j]); } if(SOS->sos_list[i]->priority == ++b) nchars += write_data(userhandle, write_modeldata, " <= %d;\n", SOS->sos_list[i]->type); else nchars += write_data(userhandle, write_modeldata, " <= %d:%d;\n", SOS->sos_list[i]->type, SOS->sos_list[i]->priority); } } ok = TRUE; return(ok); }