long GenModelCplex::Solve() { if(!bcreated) throw string("Solve() not available : Problem not created yet"); CplexData* d = static_cast<CplexData*>(solverdata); int status = 0; if(boolParam.count("qp") > 0 && boolParam["qp"]) status = CPXqpopt(d->env, d->lp); else if(boolParam.count("mip") > 0 && boolParam["mip"]) status = CPXmipopt(d->env, d->lp); else if(strParam.count("algo") > 0 && strParam["algo"] == "interior") status = CPXbaropt(d->env, d->lp); else if(strParam.count("algo") > 0 && strParam["algo"] == "dual") status = CPXdualopt(d->env, d->lp); else if(strParam.count("algo") > 0 && strParam["algo"] == "primal") status = CPXprimopt(d->env, d->lp); else if(strParam.count("algo") > 0 && strParam["algo"] == "concurrent") { //printf("choosing concurrent algo\n"); CPXsetintparam (d->env, CPX_PARAM_LPMETHOD, CPX_ALG_CONCURRENT); status = CPXlpopt(d->env, d->lp); } else if(strParam.count("algo") > 0 && strParam["algo"] == "sifting") { CPXsetintparam (d->env, CPX_PARAM_LPMETHOD, CPX_ALG_SIFTING); status = CPXlpopt(d->env, d->lp); } else status = CPXlpopt(d->env, d->lp); return 0; }
int CSolver:: Optimize(int Algorthim) { m_cbData.bMip = false; CPXsetlpcallbackfunc(m_env, lpcallback, &m_cbData); switch(Algorthim) { case SIMPLEX: m_status = CPXprimopt(m_env,m_lp); break; case DUAL_SIMPLEX: m_status = CPXdualopt(m_env,m_lp); break; case BARRIER: m_status = CPXbaropt(m_env,m_lp); break; default: Message("Undefined Algorthim specified in call to Optimize -- will use simplex!"); m_status = CPXoptimize(m_env,m_lp); }; char buff[100]; if (m_status) { CPXgeterrorstring(m_env, m_status, m_error ); sprintf(buff,"Error: %d",m_status); Message( buff ); Message( m_error ); return -1; } CPXsetlpcallbackfunc(m_env,NULL, NULL); CreateSolArrays(); // get solution and place into arrays m_status = CPXsolution(m_env, m_lp, &m_lpstat, &m_obj, m_x, m_pi, m_slack, m_dj); if (m_status) { CPXgeterrorstring(m_env, m_status, m_error ); Message("Getting solution IP_FAILED."); Message( m_error ); return -1; } // save the basis to arrays m_status = CPXgetbase(m_env, m_lp, m_pCstat, m_pRstat); if ( m_status ) { CPXgeterrorstring(m_env, m_status, m_error); Message("Getting basis failed!"); Message(m_error); return -1; } return m_status; }
static int CPXPUBLIC usersolve (CPXCENVptr env, void *cbdata, int wherefrom, void *cbhandle, int *useraction_p) { int status = 0; int nodecount; CPXLPptr nodelp; *useraction_p = CPX_CALLBACK_DEFAULT; /* Get pointer to LP subproblem */ status = CPXgetcallbacknodelp (env, cbdata, wherefrom, &nodelp); if ( status ) goto TERMINATE; /* Find out what node is being processed */ status = CPXgetcallbackinfo (env, cbdata, wherefrom, CPX_CALLBACK_INFO_NODE_COUNT, &nodecount); if ( status ) goto TERMINATE; /* Solve initial node with primal, others with dual */ if ( nodecount < 1 ) status = CPXprimopt (env, nodelp); else status = CPXdualopt (env, nodelp); /* If the solve was OK, set return to say optimization has been done in callback, otherwise return the CPLEX error code */ if ( !status ) *useraction_p = CPX_CALLBACK_SET; TERMINATE: return (status); } /* END usersolve */
void load_decomp_lp(LPdata *lp_data) { int i, cpx_status, itlim; lp_data->matcnt = (int *) calloc(lp_data->maxn, sizeof(int)); for (i=lp_data->n-1; i>=0; i--) lp_data->matcnt[i] = lp_data->matbeg[i+1] - lp_data->matbeg[i]; /*no scaling*/ cpx_status = CPXsetintparam(lp_data->cpxenv, CPX_PARAM_SCAIND, -1); /* essentially disable basis snapshots */ cpx_status = CPXsetintparam(lp_data->cpxenv, CPX_PARAM_BASINTERVAL, 2100000000); CPX_check_error("load_lp - CPXsetintparam"); lp_data->lp = CPXloadlp(lp_data->cpxenv, (char *) "Decomp_prob", lp_data->n, lp_data->m, 1, lp_data->obj, lp_data->rhs, lp_data->sense, lp_data->matbeg, lp_data->matcnt, lp_data->matind, lp_data->matval, lp_data->lb, lp_data->ub, lp_data->rngval, lp_data->maxn+lp_data->maxm, lp_data->maxm, lp_data->maxnz+lp_data->maxm); cpx_status = CPXgetintparam(lp_data->cpxenv, CPX_PARAM_ITLIM, &itlim); CPX_check_error("load_lp - CPXgetintparam"); cpx_status = CPXsetintparam(lp_data->cpxenv, CPX_PARAM_ITLIM, 0); CPX_check_error("load_lp - CPXsetintparam"); cpx_status = CPXdualopt(lp_data->cpxenv, lp_data->lp); CPX_check_error("load_lp - CPXdualopt"); cpx_status = CPXsetintparam(lp_data->cpxenv, CPX_PARAM_ITLIM, itlim); CPX_check_error("load_lp - CPXsetintparam"); /*Not sure if I need to do this anymore*/ #if 0 lp_data->lpbas.cstat = (int *) malloc(lp_data->maxn * ISIZE); lp_data->lpbas.rstat = (int *) malloc(lp_data->maxm * ISIZE); #endif }