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 Combinatorial Optimization Research Group, 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 int LpCplex::_addCol()
26 int i = CPXgetnumcols (env, lp);
28 lb[0]=-INF;//-CPX_INFBOUND;
29 ub[0]=INF;//CPX_INFBOUND;
30 status = CPXnewcols (env, lp, 1, NULL, lb, ub, NULL, NULL);
34 int LpCplex::_addRow()
36 //We want a ranged row
40 int i = CPXgetnumrows (env, lp);
41 status = CPXnewrows (env, lp, 1, NULL, sense, NULL, NULL);
45 ///\warning Data at index 0 is ignored iin the arrays.
46 void LpCplex::_setRowCoeffs(int i,
49 Value const * values )
51 int rowlist[length+1];
53 for (int k=1;k<=length;++k){
56 status = CPXchgcoeflist(env, lp,
59 const_cast<int * >(indices++),
60 const_cast<Value * >(values++));
63 void LpCplex::_setColCoeffs(int i,
68 int collist[length+1];
70 for (int k=1;k<=length;++k){
73 status = CPXchgcoeflist(env, lp,
75 const_cast<int * >(indices++),
77 const_cast<Value * >(values++));
80 void LpCplex::_setColLowerBound(int i, Value value)
88 status = CPXchgbds (env, lp, 1, indices, lu, bd);
92 void LpCplex::_setColUpperBound(int i, Value value)
100 status = CPXchgbds (env, lp, 1, indices, lu, bd);
103 void LpCplex::_setRowLowerBound(int i, Value value)
105 status = CPXchgcoef (env, lp, i, -1, value);
109 void LpCplex::_setRowUpperBound(int i, Value value)
111 //TODO Ezt kell meg megirni
112 //type of the problem
114 status = CPXgetsense (env, lp, sense, i, i);
116 status = CPXgetrhs (env, lp, rhs, i, i);
119 case 'L'://<= constraint
121 case 'E'://= constraint
123 case 'G'://>= constraint
125 case 'R'://ranged constraint
131 status = CPXchgcoef (env, lp, i, -2, value_rng);
134 void LpCplex::_setObjCoeff(int i, Value obj_coef)
136 status = CPXchgcoef (env, lp, -1, i, obj_coef);
139 LpCplex::SolveExitStatus LpCplex::_solve()
142 // int i= lpx_simplex(lp);
152 LpCplex::Value LpCplex::_getPrimal(int i)
157 LpCplex::Value LpCplex::_getPrimalValue()
163 LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
166 // int stat= lpx_get_status(lp);
168 // case LPX_UNDEF://Undefined (no solve has been run yet)
171 // case LPX_NOFEAS://There is no feasible solution (primal, I guess)
172 // case LPX_INFEAS://Infeasible
173 // return INFEASIBLE;
175 // case LPX_UNBND://Unbounded
178 // case LPX_FEAS://Feasible
181 // case LPX_OPT://Feasible
185 // return UNDEFINED; //to avoid gcc warning
191 void LpCplex::_setMax()
193 CPXchgobjsen (env, lp, CPX_MAX);
195 void LpCplex::_setMin()
197 CPXchgobjsen (env, lp, CPX_MIN);