📄 cplex.c
字号:
xassert(ub == ub); xassert(begin == begin); xassert(end == end); printf("CPXgetub: not implemented yet\n"); exit(EXIT_FAILURE); return -1;}int CPXgetweight(CPXENV *env, CPXLP *lp, int rcnt, const int rmatbeg[], const int rmatind[], const double rmatval[], double weight[], int dpriind){ xassert(env == env); xassert(lp == lp); xassert(rcnt == rcnt); xassert(rmatbeg == rmatbeg); xassert(rmatind == rmatind); xassert(rmatval == rmatval); xassert(weight == weight); xassert(dpriind == dpriind); printf("CPXgetweight: not implemented yet\n"); exit(EXIT_FAILURE); return -1;}int CPXgetx(CPXENV *env, CPXLP *lp, double x[], int begin, int end){ int j, n, errcode; errcode = checklp(env, lp); if (errcode) goto done; n = glp_get_num_cols(lp->prob); if (!(0 <= begin && begin <= end && end < n)) { errcode = error(env, CPXERR_INDEX_RANGE); goto done; } if (!lp->stat) { errcode = error(env, CPXERR_NO_SOLN); goto done; } errcode = 0; if (lp->meth == CPX_ALG_PRIMAL || lp->meth == CPX_ALG_DUAL) { if (x != NULL) { for (j = begin; j <= end; j++) x[j-begin] = glp_get_col_prim(lp->prob, j+1); } } else xassert(lp != lp);done: return errcode;}int CPXinfodblparam(CPXENV *env, int whichparam, double *defvalue, double *minvalue, double *maxvalue){ int k, errcode; errcode = checkenv(env); if (errcode) goto done; k = finddblparam(whichparam); if (k < 0) { errcode = error(env, CPXERR_BAD_PARAM_NUM); goto done; } errcode = 0; if (defvalue != NULL) *defvalue = dblparam[k].defv; if (minvalue != NULL) *minvalue = dblparam[k].minv; if (maxvalue != NULL) *maxvalue = dblparam[k].maxv;done: return errcode;}int CPXinfointparam(CPXENV *env, int whichparam, int *defvalue, int *minvalue, int *maxvalue){ int k, errcode; errcode = checkenv(env); if (errcode) goto done; k = findintparam(whichparam); if (k < 0) { errcode = error(env, CPXERR_BAD_PARAM_NUM); goto done; } errcode = 0; if (defvalue != NULL) *defvalue = intparam[k].defv; if (minvalue != NULL) *minvalue = intparam[k].minv; if (maxvalue != NULL) *maxvalue = intparam[k].maxv;done: return errcode;}int CPXmdleave(const CPXENV *env, CPXLP *lp, const int goodlist[], int goodlen, double downratio[], double upratio[]){ int k; xassert(env == env); xassert(lp == lp); xassert(goodlist == goodlist); xassert(goodlen >= 0); xassert(downratio != NULL); xassert(upratio != NULL); /* not implemented yet */ for (k = 0; k < goodlen; k++) downratio[k] = upratio[k] = 0.0; return 0;}int CPXnewrows(CPXENV *env, CPXLP *lp, int rcnt, const double rhs[], const char sense[], const double rngval[], char *rowname[]){ int i, m, type, errcode; double lbnd, ubnd; errcode = checklp(env, lp); if (errcode) goto done; if (rcnt < 0) { errcode = error(env, CPXERR_BAD_ARGUMENT); goto done; } for (i = 0; i < rcnt; 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; } } } errcode = 0; invalidate(lp); m = glp_get_num_rows(lp->prob); if (rcnt > 0) glp_add_rows(lp->prob, rcnt); enlargerflag(lp); for (i = 0; i < rcnt; i++) { if (rowname != NULL) glp_set_row_name(lp->prob, m+i+1, rowname[i]); lbnd = ubnd = (rhs == NULL ? 0.0 : rhs[i]); if (sense == NULL || sense[i] == 'E') { lp->rflag[m+i] = RF_NOT_RANGED; type = GLP_FX; } else if (sense[i] == 'L') { 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') { if (rngval == NULL || rngval[i] == 0.0) { lp->rflag[m+i] = RF_RANGED_POS; type = GLP_FX; } else if (rngval[i] > 0.0) { lp->rflag[m+i] = RF_RANGED_POS; type = GLP_DB; ubnd += rngval[i]; } else /* rngval[i] < 0.0 */ { lp->rflag[m+i] = RF_RANGED_NEG; type = GLP_DB; lbnd += rngval[i]; } } else xassert(sense != sense); glp_set_row_bnds(lp->prob, m+i+1, type, lbnd, ubnd); }done: return errcode;}CPXENV *CPXopenCPLEX(int *status){ CPXENV *env; int k, card; env = glp_malloc(sizeof(CPXENV)); env->list = NULL; card = sizeof(intparam) / sizeof(struct intparam); env->intparam = glp_calloc(card, sizeof(int)); for (k = 0; k < card; k++) env->intparam[k] = intparam[k].defv; card = sizeof(dblparam) / sizeof(struct dblparam); env->dblparam = glp_calloc(card, sizeof(double)); for (k = 0; k < card; k++) env->dblparam[k] = dblparam[k].defv; if (status != NULL) *status = 0; return env;}int CPXpivotin(CPXENV *env, CPXLP *lp, const int rlist[], int rlen){ int i, m, errcode; errcode = checklp(env, lp); if (errcode) goto done; if (rlen < 0) { errcode = error(env, CPXERR_BAD_ARGUMENT); goto done; } if (rlen > 0 && rlist == NULL) { errcode = error(env, CPXERR_NULL_POINTER); goto done; } m = glp_get_num_rows(lp->prob); for (i = 0; i < rlen; i++) { if (!(0 <= rlist[i] && rlist[i] < m)) { errcode = error(env, CPXERR_ROW_INDEX_RANGE, i); goto done; } } errcode = 0; for (i = 0; i < rlen; i++) { if (glp_get_row_type(lp->prob, rlist[i]+1) != GLP_FX) { if (glp_get_row_stat(lp->prob, rlist[i]+1) != GLP_BS) { /* not implemented yet */ break; } } }done: return errcode;}int CPXpivotout(CPXENV *env, CPXLP *lp, const int clist[], int clen){ int j, n, errcode; errcode = checklp(env, lp); if (errcode) goto done; if (clen < 0) { errcode = error(env, CPXERR_BAD_ARGUMENT); goto done; } if (clen > 0 && clist == NULL) { errcode = error(env, CPXERR_NULL_POINTER); goto done; } n = glp_get_num_cols(lp->prob); for (j = 0; j < clen; j++) { if (!(0 <= clist[j] && clist[j] < n)) { errcode = error(env, CPXERR_COL_INDEX_RANGE, j); goto done; } if (glp_get_col_type(lp->prob, clist[j]+1) != GLP_FX) { errcode = error(env, CPXERR_NOT_FIXED); goto done; } } errcode = 0; for (j = 0; j < clen; j++) { if (glp_get_col_stat(lp->prob, clist[j]+1) == GLP_BS) { /* not implemented yet */ break; } }done: return errcode;}int CPXprimopt(CPXENV *env, CPXLP *lp);int CPXsavwrite(CPXENV *env, CPXLP *lp, const char *filename){ xassert(env == env); xassert(lp == lp); xassert(filename == filename); printf("CPXsavwrite: not implemented yet\n"); exit(EXIT_FAILURE); return -1;}int CPXsetdblparam(CPXENV *env, int whichparam, double newvalue){ int k, errcode; errcode = checkenv(env); if (errcode) goto done; k = finddblparam(whichparam); if (k < 0) { errcode = error(env, CPXERR_BAD_PARAM_NUM); goto done; } if (newvalue < dblparam[k].minv) { errcode = error(env, CPXERR_PARAM_TOO_SMALL); goto done; } if (newvalue > dblparam[k].maxv) { errcode = error(env, CPXERR_PARAM_TOO_BIG); goto done; } errcode = 0; env->dblparam[k] = newvalue;done: return errcode;}int CPXsetintparam(CPXENV *env, int whichparam, int newvalue){ int k, errcode; errcode = checkenv(env); if (errcode) goto done; k = findintparam(whichparam); if (k < 0) { errcode = error(env, CPXERR_BAD_PARAM_NUM); goto done; } if (newvalue < intparam[k].minv) { errcode = error(env, CPXERR_PARAM_TOO_SMALL); goto done; } if (newvalue > intparam[k].maxv) { errcode = error(env, CPXERR_PARAM_TOO_BIG); goto done; } errcode = 0; env->intparam[k] = newvalue;done: return errcode;}int CPXsolninfo(CPXENV *env, CPXLP *lp, int *solnmethod, int *solntype, int *pfeasind, int *dfeasind){ int type, pfeas, dfeas, errcode; errcode = checklp(env, lp); if (errcode) goto done; errcode = 0; if (!lp->stat) type = CPX_NO_SOLN, pfeas = dfeas = 0; else if (lp->meth == CPX_ALG_PRIMAL || lp->meth == CPX_ALG_DUAL) { type = CPX_BASIC_SOLN; pfeas = (glp_get_prim_stat(lp->prob) == GLP_FEAS); dfeas = (glp_get_dual_stat(lp->prob) == GLP_FEAS); } else xassert(lp != lp); if (solnmethod != NULL) *solnmethod = lp->meth; if (solntype != NULL) *solntype = type; if (pfeasind != NULL) *pfeasind = pfeas; if (dfeasind != NULL) *dfeasind = dfeas;done: return errcode;}int CPXstrongbranch(CPXENV *env, CPXLP *lp, const int goodlist[], int goodlen, double downpen[], double uppen[], int itlim){ int k; xassert(env == env); xassert(lp == lp); xassert(goodlist == goodlist); xassert(goodlen >= 0); xassert(downpen != NULL); xassert(uppen != NULL); xassert(itlim == itlim); /* not implemented yet */ for (k = 0; k < goodlen; k++) downpen[k] = uppen[k] = 0.0; return 0;}/**********************************************************************/static int solvelp(CPXENV *env, CPXLP *lp, int meth){ glp_smcp parm; int errcode; errcode = checklp(env, lp); if (errcode) goto done; errcode = 0; invalidate(lp); glp_init_smcp(&parm); switch (meth) { case CPX_ALG_PRIMAL: parm.meth = GLP_PRIMAL; break; case CPX_ALG_DUAL: parm.meth = GLP_DUAL; break; default: xassert(meth != meth); } switch (getintparam(env, CPX_PARAM_SIMDISPLAY)) { case 0: parm.msg_lev = GLP_MSG_OFF; break; case 1: parm.msg_lev = GLP_MSG_ALL; break; case 2: parm.msg_lev = GLP_MSG_ALL; parm.out_frq = 1; break; default: xassert(env != env); } xassert(getdblparam == getdblparam); switch (getintparam(env, CPX_PARAM_ADVIND)) { case 0: glp_term_out(GLP_OFF); glp_adv_basis(lp->prob, 0); glp_term_out(GLP_ON); break; case 1: case 2: break; default: xassert(env != env); } if (!glp_bf_exists(lp->prob)) { if (glp_factorize(lp->prob) != 0) { glp_term_out(GLP_OFF); glp_adv_basis(lp->prob, 0); glp_term_out(GLP_ON); if (glp_factorize(lp->prob) != 0) glp_std_basis(lp->prob); } } xassert(glp_simplex(lp->prob, &parm) == 0); switch (glp_get_status(lp->prob)) { case GLP_OPT: lp->stat = CPX_STAT_OPTIMAL; lp->meth = meth; break; case GLP_NOFEAS: lp->stat = CPX_STAT_INFEASIBLE; lp->meth = meth; break; case GLP_UNBND: lp->stat = CPX_STAT_UNBOUNDED; lp->meth = meth; break; default: xassert(lp != lp); }done: return errcode;}int CPXprimopt(CPXENV *env, CPXLP *lp){ int errcode; errcode = solvelp(env, lp, CPX_ALG_PRIMAL); return errcode;}int CPXdualopt(CPXENV *env, CPXLP *lp){ int errcode; errcode = solvelp(env, lp, CPX_ALG_DUAL); return errcode;}/* eof */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -