int SOS_infeasible(SOSgroup *group, int sosindex) { int i, n, nn, varnr, failindex, *list; lprec *lp = group->lp; #ifdef Paranoia if((sosindex < 0) || (sosindex > group->sos_count)) { report(lp, IMPORTANT, "SOS_infeasible: Invalid SOS index %d\n", sosindex); return(FALSE); } #endif if(sosindex == 0 && group->sos_count == 1) sosindex = 1; failindex = 0; if(sosindex == 0) { for(i = 1; i <= group->sos_count; i++) { failindex = SOS_infeasible(group, i); if(failindex > 0) break; } } else { list = group->sos_list[sosindex-1]->members; n = list[0]; nn = list[n+1]; /* Find index of next lower-bounded variable */ for(i = 1; i <= n; i++) { varnr = abs(list[i]); if((lp->orig_lowbo[lp->rows + varnr] > 0) && !((lp->sc_vars > 0) && is_semicont(lp, varnr))) break; } /* Find if there is another lower-bounded variable beyond the type window */ i = i+nn; while(i <= n) { varnr = abs(list[i]); if((lp->orig_lowbo[lp->rows + varnr] > 0) && !((lp->sc_vars > 0) && is_semicont(lp, varnr))) break; i++; } if(i <= n) failindex = abs(list[i]); } return(failindex); }
/* check if var is semi-continious */ long __declspec(dllexport) WINAPI _is_semicont(lprec *lp, long column) { long ret; if (lp != NULL) { freebuferror(); ret = is_semicont(lp, column); } else ret = 0; return(ret); }
static void print_statistics(lprec *lp) { REAL *col, *RHSmin, *RHSmax, *OBJmin, *OBJmax, *MATmin, *MATmax; int *nz, ret, m, n, i, j, k, l, nRHSmin = 0, nRHSmax = 0, nOBJmin = 0, nOBJmax = 0, nMATmin = 0, nMATmax = 0, *rowRHSmin, *rowRHSmax, *colOBJmin, *colOBJmax, *rowMATmin, *rowMATmax, *colMATmin, *colMATmax; m = get_Nrows(lp); n = get_Ncolumns(lp); col = (REAL *) malloc((1 + m) * sizeof(*col)); nz = (int *) malloc((1 + m) * sizeof(*RHSmin)); RHSmin = (REAL *) malloc(nstats * sizeof(*RHSmin)); RHSmax = (REAL *) malloc(nstats * sizeof(*RHSmax)); rowRHSmin = (int *) malloc(nstats * sizeof(*RHSmin)); rowRHSmax = (int *) malloc(nstats * sizeof(*RHSmax)); OBJmin = (REAL *) malloc(nstats * sizeof(*OBJmin)); OBJmax = (REAL *) malloc(nstats * sizeof(*OBJmax)); colOBJmin = (int *) malloc(nstats * sizeof(*colOBJmin)); colOBJmax = (int *) malloc(nstats * sizeof(*colOBJmax)); MATmin = (REAL *) malloc(nstats * sizeof(*MATmin)); MATmax = (REAL *) malloc(nstats * sizeof(*MATmax)); rowMATmin = (int *) malloc(nstats * sizeof(*rowMATmin)); rowMATmax = (int *) malloc(nstats * sizeof(*rowMATmax)); colMATmin = (int *) malloc(nstats * sizeof(*colMATmin)); colMATmax = (int *) malloc(nstats * sizeof(*colMATmax)); /* minmax(2.0, MATmin, MATmax, &nMATmin, &nMATmax, 1, rowMATmin, rowMATmax, 8, colMATmin, colMATmax); minmax(1.0, MATmin, MATmax, &nMATmin, &nMATmax, 2, rowMATmin, rowMATmax, 7, colMATmin, colMATmax); minmax(1.5, MATmin, MATmax, &nMATmin, &nMATmax, 3, rowMATmin, rowMATmax, 6, colMATmin, colMATmax); minmax(3.0, MATmin, MATmax, &nMATmin, &nMATmax, 4, rowMATmin, rowMATmax, 5, colMATmin, colMATmax); minmax(4.0, MATmin, MATmax, &nMATmin, &nMATmax, 5, rowMATmin, rowMATmax, 4, colMATmin, colMATmax); minmax(0.1, MATmin, MATmax, &nMATmin, &nMATmax, 6, rowMATmin, rowMATmax, 3, colMATmin, colMATmax); minmax(5.0, MATmin, MATmax, &nMATmin, &nMATmax, 7, rowMATmin, rowMATmax, 2, colMATmin, colMATmax); minmax(1.4, MATmin, MATmax, &nMATmin, &nMATmax, 8, rowMATmin, rowMATmax, 1, colMATmin, colMATmax); printminmax(MATmin, MATmax, nMATmin, nMATmax, rowMATmin, rowMATmax, colMATmin, colMATmax); */ for (i = 1; i <= m; i++) minmax(get_rh(lp, i), RHSmin, RHSmax, &nRHSmin, &nRHSmax, i, rowRHSmin, rowRHSmax, 0, NULL, NULL); for (j = 1; j <= n; j++) { ret = get_columnex(lp, j, col, nz); for (i = 0; i < ret; i++) if (nz[i] == 0) minmax(col[i], OBJmin, OBJmax, &nOBJmin, &nOBJmax, 0, NULL, NULL, j, colOBJmin, colOBJmax); else minmax(col[i], MATmin, MATmax, &nMATmin, &nMATmax, nz[i], rowMATmin, rowMATmax, j, colMATmin, colMATmax); } printf("Constraints: %d\n", get_Nrows(lp)); printf("Variables : %d\n", get_Ncolumns(lp)); for (j = k = l = 0, i = n; i >= 1; i--) { if (is_int(lp, i)) j++; if (is_semicont(lp, i)) k++; if (is_SOS_var(lp, i)) l++; } printf("Integers : %d\n", j); printf("Semi-cont : %d\n", k); printf("SOS : %d\n", l); k = get_nonzeros(lp); printf("Non-zeros : %d\tdensity=%f%%\n", k, ((double) k) / (((double) m) * ((double) n)) * 100.0); printf("\nAbsolute Ranges:\n\n Minima Maxima\n"); printf("\nMatrix Coeficients:\n"); printminmax(lp, "A", MATmin, MATmax, nMATmin, nMATmax, rowMATmin, rowMATmax, colMATmin, colMATmax); printf("\nObj. Vector:\n"); printminmax(lp, "c", OBJmin, OBJmax, nOBJmin, nOBJmax, NULL, NULL, colOBJmin, colOBJmax); printf("\nRHS Vector:\n"); printminmax(lp, "b", RHSmin, RHSmax, nRHSmin, nRHSmax, rowRHSmin, rowRHSmax, NULL, NULL); free(col); free(nz); free(RHSmin); free(RHSmax); free(rowRHSmin); free(rowRHSmax); free(OBJmin); free(OBJmax); free(colOBJmin); free(colOBJmax); free(MATmin); free(MATmax); free(rowMATmin); free(rowMATmax); free(colMATmin); free(colMATmax); }
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); }