This way it works also when both GLPK and CPLEX are enabled.
2 * src/lemon/lp_cplex.cc
3 * - Part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
6 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 * Permission to use, modify and distribute this software is granted
9 * provided that this copyright notice appears in all copies. For
10 * precise terms see the accompanying LICENSE file.
12 * This software is provided "AS IS" with no warranty of any kind,
13 * express or implied, and with no claim as to its suitability for any
21 ///\brief Implementation of the LEMON-CPLEX lp solver interface.
24 LpCplex::LpCplex() : LpSolverBase() {
27 env = CPXopenCPLEXdevelop(&status);
30 // fprintf(stderr,"A CPLEX környezet megnyitása sikertelen.\n");
31 // CPXgeterrorstring(Env, Status, ErrorMsg);
32 // fprintf(stderr,"%s",ErrorMsg);
36 // *** A problema létrehozása ***
37 lp = CPXcreateprob(env, &status, "LP problem");
39 // if (Problem == NULL)
41 // fprintf(stderr,"Az LP létrehozása sikertelen");
48 status = CPXfreeprob(env,&lp);
51 // fprintf(stderr,"A CPLEX feladat törlése sikertelen.\n");
52 // CPXgeterrorstring(Env, Status, ErrorMsg);
53 // fprintf(stderr,"%s",ErrorMsg);
57 status = CPXcloseCPLEX(&env);
60 // fprintf(stderr,"A CPLEX környezet bezárása sikertelen.\n");
61 // CPXgeterrorstring(Env, Status, ErrorMsg);
62 // fprintf(stderr,"%s",ErrorMsg);
68 LpSolverBase &LpCplex::_newLp() {return *(LpSolverBase*)0;}
69 LpSolverBase &LpCplex::_copyLp() {return *(LpSolverBase*)0;}
71 int LpCplex::_addCol()
73 int i = CPXgetnumcols (env, lp);
75 lb[0]=-INF;//-CPX_INFBOUND;
76 ub[0]=INF;//CPX_INFBOUND;
77 status = CPXnewcols (env, lp, 1, NULL, lb, ub, NULL, NULL);
81 int LpCplex::_addRow()
83 //We want a row that is not constrained
85 sense[0]='L';//<= constraint
88 int i = CPXgetnumrows (env, lp);
89 status = CPXnewrows (env, lp, 1, rhs, sense, NULL, NULL);
93 ///\warning Data at index 0 is ignored in the arrays.
94 void LpCplex::_setRowCoeffs(int i,
97 Value const * values )
99 int rowlist[length+1];
101 for (int k=1;k<=length;++k){
104 status = CPXchgcoeflist(env, lp,
107 const_cast<int * >(indices+1),
108 const_cast<Value * >(values+1));
111 void LpCplex::_setColCoeffs(int i,
114 Value const * values)
116 int collist[length+1];
118 for (int k=1;k<=length;++k){
121 status = CPXchgcoeflist(env, lp,
123 const_cast<int * >(indices+1),
125 const_cast<Value * >(values+1));
128 void LpCplex::_setColLowerBound(int i, Value value)
136 status = CPXchgbds (env, lp, 1, indices, lu, bd);
140 void LpCplex::_setColUpperBound(int i, Value value)
148 status = CPXchgbds (env, lp, 1, indices, lu, bd);
151 //This will be easier to implement
152 void LpCplex::_setRowBounds(int i, Value lb, Value ub)
155 if (lb==INF || ub==-INF) {
166 CPXchgsense (env, lp, cnt, indices, sense);
167 CPXchgcoef (env, lp, i, -1, ub);
172 CPXchgsense (env, lp, cnt, indices, sense);
173 CPXchgcoef (env, lp, i, -1, lb);
178 CPXchgsense (env, lp, cnt, indices, sense);
179 CPXchgcoef (env, lp, i, -1, lb);
183 CPXchgsense (env, lp, cnt, indices, sense);
184 CPXchgcoef (env, lp, i, -1, lb);
185 CPXchgcoef (env, lp, i, -2, ub-lb);
191 void LpCplex::_setRowLowerBound(int i, Value value)
193 //Not implemented, obsolete
196 void LpCplex::_setRowUpperBound(int i, Value value)
198 //Not implemented, obsolete
199 // //TODO Ezt kell meg megirni
200 // //type of the problem
202 // status = CPXgetsense (env, lp, sense, i, i);
204 // status = CPXgetrhs (env, lp, rhs, i, i);
206 // switch (sense[0]) {
207 // case 'L'://<= constraint
209 // case 'E'://= constraint
211 // case 'G'://>= constraint
213 // case 'R'://ranged constraint
219 // status = CPXchgcoef (env, lp, i, -2, value_rng);
222 void LpCplex::_setObjCoeff(int i, Value obj_coef)
224 CPXchgcoef (env, lp, -1, i, obj_coef);
227 void LpCplex::_clearObj()
229 for (int i=0;i< CPXgetnumcols (env, lp);++i){
230 CPXchgcoef (env, lp, -1, i, 0);
235 LpCplex::SolveExitStatus LpCplex::_solve()
238 status = CPXlpopt (env, lp);
245 // int i= lpx_simplex(lp);
255 LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
259 // int stat= lpx_get_status(lp);
261 // case LPX_UNDEF://Undefined (no solve has been run yet)
264 // case LPX_NOFEAS://There is no feasible solution (primal, I guess)
265 // case LPX_INFEAS://Infeasible
266 // return INFEASIBLE;
268 // case LPX_UNBND://Unbounded
271 // case LPX_FEAS://Feasible
274 // case LPX_OPT://Feasible
278 // return UNDEFINED; //to avoid gcc warning
283 LpCplex::Value LpCplex::_getPrimal(int i)
286 CPXgetx (env, lp, &x, i, i);
290 LpCplex::Value LpCplex::_getPrimalValue()
299 void LpCplex::_setMax()
301 CPXchgobjsen (env, lp, CPX_MAX);
303 void LpCplex::_setMin()
305 CPXchgobjsen (env, lp, CPX_MIN);