📄 cplex.c
字号:
{ lp->rflag[m+i] = RF_NOT_RANGED; type = GLP_UP; } else if (sense[i] == 'G') { lp->rflag[m+i] = RF_NOT_RANGED; type = GLP_LO; } else if (sense[i] == 'R') { lp->rflag[m+i] = RF_RANGED_POS; type = GLP_FX; } else xassert(sense != sense); glp_set_row_bnds(lp->prob, m+i+1, type, temp, temp); beg = rmatbeg[i]; end = (i < rcnt-1 ? rmatbeg[i+1] : nzcnt); for (k = beg; k < end; k++) lp->iwork[k-beg] = rmatind[k]+1; glp_set_mat_row(lp->prob, m+i+1, end-beg, lp->iwork-1, rmatval+beg-1); for (k = beg; k < end; k++) lp->iwork[k-beg] = 0; } for (j = 0; j < ccnt; j++) { if (colname != NULL) glp_set_col_name(lp->prob, n+j+1, colname[j]); glp_set_col_bnds(lp->prob, n+j+1, GLP_LO, 0.0, 0.0); }done: return errcode;}int CPXbaropt(CPXENV *env, CPXLP *lp){ xassert(env == env); xassert(lp == lp); printf("CPXbaropt: not implemented yet\n"); exit(EXIT_FAILURE); return -1;}int CPXbinvrow(CPXENV *env, CPXLP *lp, int i, double y[]){ xassert(env == env); xassert(lp == lp); xassert(i == i); xassert(y == y); printf("CPXbinvrow: not implemented yet\n"); exit(EXIT_FAILURE); return -1;}int CPXchgbds(CPXENV *env, CPXLP *lp, int cnt, const int indices[], const char lu[], const double bd[]){ int j, n, type, errcode; double lbnd, ubnd; errcode = checklp(env, lp); if (errcode) goto done; if (cnt < 0) { errcode = error(env, CPXERR_BAD_ARGUMENT); goto done; } if (cnt > 0) { if (indices == NULL || lu == NULL || bd == NULL) { errcode = error(env, CPXERR_NULL_POINTER); goto done; } } n = glp_get_num_cols(lp->prob); for (j = 0; j < cnt; j++) { if (!(0 <= indices[j] && indices[j] < n)) { errcode = error(env, CPXERR_COL_INDEX_RANGE, j); goto done; } if (!(lu[j] == 'L' || lu[j] == 'U' || lu[j] == 'B')) { errcode = error(env, CPXERR_BAD_LUB, j); goto done; } } errcode = 0; invalidate(lp); for (j = 0; j < cnt; j++) { type = glp_get_col_type(lp->prob, indices[j]+1); lbnd = glp_get_col_lb(lp->prob, indices[j]+1); ubnd = glp_get_col_ub(lp->prob, indices[j]+1); if (type == GLP_FR || type == GLP_UP) lbnd = -CPX_INFBOUND; if (type == GLP_FR || type == GLP_LO) ubnd = +CPX_INFBOUND; if (lu[j] == 'L') lbnd = bd[j]; else if (lu[j] == 'U') ubnd = bd[j]; else if (lu[j] == 'B') lbnd = ubnd = bd[j]; else xassert(lu != lu); if (lbnd <= -CPX_INFBOUND && ubnd >= +CPX_INFBOUND) type = GLP_FR; else if (ubnd >= +CPX_INFBOUND) type = GLP_LO; else if (lbnd <= -CPX_INFBOUND) type = GLP_UP; else if (lbnd != ubnd) type = GLP_DB; else type = GLP_FX; glp_set_col_bnds(lp->prob, indices[j]+1, type, lbnd, ubnd); }done: return errcode;}int CPXchgsense(CPXENV *env, CPXLP *lp, int cnt, const int indices[], const char sense[]){ int i, m, type, errcode; double rhs; errcode = checklp(env, lp); if (errcode) goto done; if (cnt < 0) { errcode = error(env, CPXERR_BAD_ARGUMENT); goto done; } if (cnt > 0 && (indices == NULL || sense == NULL)) { errcode = error(env, CPXERR_NULL_POINTER); goto done; } m = glp_get_num_rows(lp->prob); for (i = 0; i < cnt; i++) { if (!(0 <= indices[i] && indices[i] < m)) { errcode = error(env, CPXERR_ROW_INDEX_RANGE, i); goto done; } if (!(sense[i] == 'L' || sense[i] == 'E' || sense[i] == 'G' || sense[i] == 'R')) { errcode = error(env, CPXERR_BAD_SENSE, i); goto done; } } errcode = 0; invalidate(lp); for (i = 0; i < cnt; i++) { type = glp_get_row_type(lp->prob, indices[i]+1); if (lp->rflag[indices[i]] == RF_NOT_RANGED) { if (type == GLP_LO || type == GLP_FX) rhs = glp_get_row_lb(lp->prob, indices[i]+1); else if (type == GLP_UP) rhs = glp_get_row_ub(lp->prob, indices[i]+1); else xassert(type != type); } else if (lp->rflag[indices[i]] == RF_RANGED_POS) { xassert(type == GLP_DB || type == GLP_FX); rhs = glp_get_row_lb(lp->prob, indices[i]+1); } else if (lp->rflag[indices[i]] == RF_RANGED_NEG) { xassert(type == GLP_DB); rhs = glp_get_row_ub(lp->prob, indices[i]+1); } else xassert(lp != lp); if (sense[i] == 'L') { lp->rflag[indices[i]] = RF_NOT_RANGED; type = GLP_UP; } else if (sense[i] == 'E') { lp->rflag[indices[i]] = RF_NOT_RANGED; type = GLP_FX; } else if (sense[i] == 'G') { lp->rflag[indices[i]] = RF_NOT_RANGED; type = GLP_LO; } else if (sense[i] == 'R') { lp->rflag[indices[i]] = RF_RANGED_POS; type = GLP_FX; } else xassert(sense != sense); glp_set_row_bnds(lp->prob, indices[i]+1, type, rhs, rhs); }done: return errcode;}int CPXcloseCPLEX(CPXENV **_env){ CPXENV *env; CPXLP *lp; int errcode; if (_env == NULL) { errcode = CPXERR_NULL_POINTER; goto done; } env = *_env; errcode = checkenv(env); if (errcode) goto done; while (env->list != NULL) { lp = env->list; errcode = CPXfreeprob(env, &lp); xassert(!errcode); } glp_free(env->intparam); glp_free(env->dblparam); glp_free(env); *_env = NULL; errcode = 0;done: return errcode;}int CPXcopybase(CPXENV *env, CPXLP *lp, const int cstat[], const int rstat[]){ int i, j, m, n, stat, errcode; errcode = checklp(env, lp); if (errcode) goto done; m = glp_get_num_rows(lp->prob); n = glp_get_num_cols(lp->prob); if (m > 0 && rstat == NULL || n > 0 && cstat == NULL) { errcode = error(env, CPXERR_NULL_POINTER); goto done; } for (i = 0; i < m; i++) { if (!(rstat[i] == CPX_AT_LOWER || rstat[i] == CPX_BASIC || rstat[i] == CPX_AT_UPPER)) { errcode = error(env, CPXERR_BAD_STATUS, i); goto done; } } for (j = 0; j < n; j++) { if (!(cstat[j] == CPX_AT_LOWER || cstat[j] == CPX_BASIC || cstat[j] == CPX_AT_UPPER || cstat[j] == CPX_FREE_SUPER)) { errcode = error(env, CPXERR_BAD_STATUS, j); goto done; } } errcode = 0; invalidate(lp); for (i = 0; i < m; i++) { if (rstat[i] == CPX_AT_LOWER) stat = GLP_NL; else if (rstat[i] == CPX_BASIC) stat = GLP_BS; else if (rstat[i] == CPX_AT_UPPER) stat = GLP_NU; else xassert(rstat != rstat); glp_set_row_stat(lp->prob, i+1, stat); } for (j = 0; j < n; j++) { if (cstat[j] == CPX_AT_LOWER) stat = GLP_NL; else if (cstat[j] == CPX_BASIC) stat = GLP_BS; else if (cstat[j] == CPX_AT_UPPER) stat = GLP_NU; else if (cstat[j] == CPX_FREE_SUPER) stat = GLP_NF; else xassert(cstat != cstat); glp_set_col_stat(lp->prob, j+1, stat); }done: return errcode;}int CPXcopybasednorms(CPXENV *env, CPXLP *lp, const int cstat[], const int rstat[], const double dnorm[]){ int errcode; errcode = CPXcopybase(env, lp, cstat, rstat); xassert(dnorm == dnorm); return errcode;}int CPXcopylp(CPXENV *env, CPXLP *lp, int numcols, int numrows, int objsen, const double obj[], const double rhs[], const char sense[], const int matbeg[], const int matcnt[], const int matind[], const double matval[], const double lb[], const double ub[], const double rngval[]){ int errcode; errcode = CPXcopylpwnames(env, lp, numcols, numrows, objsen, obj, rhs, sense, matbeg, matcnt, matind, matval, lb, ub, rngval, NULL, NULL); return errcode;}int CPXcopylpwnames(CPXENV *env, CPXLP *lp, int numcols, int numrows, int objsen, const double obj[], const double rhs[], const char sense[], const int matbeg[], const int matcnt[], const int matind[], const double matval[], const double lb[], const double ub[], const double rngval[], char *colname[], char *rowname[]){ int i, j, k, beg, end, type, errcode; double lbnd, ubnd; char name[255+1]; errcode = checklp(env, lp); if (errcode) goto done; if (numcols < 0 || numrows < 0) { errcode = error(env, CPXERR_BAD_ARGUMENT); goto done; } if (!(objsen == CPX_MIN || objsen == CPX_MAX)) { errcode = error(env, CPXERR_BAD_ARGUMENT); goto done; } if (numcols > 0) { if (matbeg == NULL || matcnt == NULL || matind == NULL || matval == NULL) { errcode = error(env, CPXERR_NULL_POINTER); goto done; } } for (i = 0; i < numrows; i++) { if (sense != NULL) { if (!(sense[i] == 'L' || sense[i] == 'E' || sense[i] == 'G' || sense[i] == 'R')) { errcode = error(env, CPXERR_BAD_SENSE, i); goto done; } } if (rowname != NULL) { if (rowname[i] == NULL) { errcode = error(env, CPXERR_NULL_NAME, i); goto done; } } } enlargeiwork(lp, numrows); for (j = 0; j < numcols; j++) { beg = matbeg[j]; if (j > 0 && !(matbeg[j-1] <= beg)) { errcode = error(env, CPXERR_ARRAY_NOT_ASCENDING, j); goto done; } if (beg < 0) { errcode = error(env, CPXERR_INDEX_RANGE); goto done; } end = beg + matcnt[j]; if (!(beg <= end) || j < numcols-1 && !(end <= matbeg[j+1])) { errcode = error(env, CPXERR_COUNT_RANGE, j); goto done; } for (k = beg; k < end; k++) { if (!(0 <= matind[k] && matind[k] < numrows)) { errcode = error(env, CPXERR_ROW_INDEX_RANGE, k); goto done; } } errcode = 0; for (k = beg; k < end; k++) { if (lp->iwork[matind[k]]) { errcode = error(env, CPXERR_DUP_ENTRY); break; } lp->iwork[matind[k]] = 1; } for (k = beg; k < end; k++) lp->iwork[matind[k]] = 0; if (errcode) goto done; if (colname != NULL) { if (colname[j] != NULL) { errcode = error(env, CPXERR_NULL_NAME, j); goto done; } } } errcode = 0; invalidate(lp); if (glp_get_prob_name(lp->prob) == NULL) name[0] = '\0'; else strcpy(name, glp_get_prob_name(lp->prob)); glp_erase_prob(lp->prob); glp_set_prob_name(lp->prob, name); if (objsen == CPX_MIN) glp_set_obj_dir(lp->prob, GLP_MIN); else if (objsen == CPX_MAX) glp_set_obj_dir(lp->prob, GLP_MAX); else xassert(objsen != objsen); if (numrows > 0) glp_add_rows(lp->prob, numrows); enlargerflag(lp); for (i = 0; i < numrows; i++) { if (rowname != NULL) glp_set_row_name(lp->prob, i+1, rowname[i]); lbnd = ubnd = (rhs == NULL ? 0.0 : rhs[i]); if (sense == NULL || sense[i] == 'E') { lp->rflag[i] = RF_NOT_RANGED; type = GLP_FX; } else if (sense[i] == 'L') { lp->rflag[i] = RF_NOT_RANGED; type = GLP_UP; } else if (sense[i] == 'G') { lp->rflag[i] = RF_NOT_RANGED; type = GLP_LO; } else if (sense[i] == 'R') { if (rngval == NULL || rngval[i] == 0.0) { lp->rflag[i] = RF_RANGED_POS; type = GLP_FX; } else if (rngval[i] > 0.0) { lp->rflag[i] = RF_RANGED_POS; type = GLP_DB; ubnd += rngval[i]; } else /* rngval[i] < 0.0 */ { lp->rflag[i] = RF_RANGED_NEG; type = GLP_DB; lbnd += rngval[i]; } } else xassert(sense != sense); glp_set_row_bnds(lp->prob, i+1, type, lbnd, ubnd); } if (numcols > 0) glp_add_cols(lp->prob, numcols); for (j = 0; j < numcols; j++) { if (colname != NULL) glp_set_col_name(lp->prob, j+1, colname[j]); lbnd = (lb == NULL ? 0.0 : lb[j]); ubnd = (ub == NULL ? +CPX_INFBOUND : ub[j]); if (lbnd <= -CPX_INFBOUND && ubnd >= +CPX_INFBOUND) type = GLP_FR; else if (ubnd >= +CPX_INFBOUND) type = GLP_LO; else if (lbnd <= -CPX_INFBOUND) type = GLP_UP; else if (lbnd != ubnd) type = GLP_DB; else type = GLP_FX; glp_set_col_bnds(lp->prob, j+1, type, lbnd, ubnd); if (obj != NULL) glp_set_obj_coef(lp->prob, j+1, obj[j]); beg = matbeg[j]; end = beg + matcnt[j]; for (k = beg; k < end; k++) lp->iwork[k-beg] = matind[k]+1; glp_set_mat_col(lp->prob, j+1, end-beg, lp->iwork-1, matval+beg-1); for (k = beg; k < end; k++) lp->iwork[k-beg] = 0; }done: return errcode;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -