Changeset 2605:852361980706 in lemon-0.x for lemon/lp_cplex.cc
- Timestamp:
- 04/08/08 18:01:28 (16 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3488
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lp_cplex.cc
r2591 r2605 18 18 19 19 #include <iostream> 20 #include <vector> 20 21 #include<lemon/lp_cplex.h> 21 22 … … 24 25 namespace lemon { 25 26 26 LpCplex::LpCplex() : LpSolverBase(){27 LpCplex::LpCplex() { 27 28 // env = CPXopenCPLEXdevelop(&status); 28 29 env = CPXopenCPLEX(&status); 29 30 lp = CPXcreateprob(env, &status, "LP problem"); 30 31 } 32 33 LpCplex::LpCplex(const LpCplex& cplex) : LpSolverBase() { 34 env = CPXopenCPLEX(&status); 35 lp = CPXcloneprob(env, cplex.lp, &status); 36 rows = cplex.rows; 37 cols = cplex.cols; 38 } 31 39 32 40 LpCplex::~LpCplex() { 33 CPXfreeprob(env,&lp); 34 CPXcloseCPLEX(&env); 35 } 36 37 LpSolverBase &LpCplex::_newLp()41 CPXfreeprob(env,&lp); 42 CPXcloseCPLEX(&env); 43 } 44 45 LpSolverBase* LpCplex::_newLp() 38 46 { 39 47 //The first approach opens a new environment 40 LpCplex* newlp=new LpCplex(); 41 return *newlp; 42 } 43 44 LpSolverBase &LpCplex::_copyLp() { 45 ///\bug FixID data is not copied! 46 //The first approach opens a new environment 47 LpCplex* newlp=new LpCplex(); 48 //The routine CPXcloneprob can be used to create a new CPLEX problem 49 //object and copy all the problem data from an existing problem 50 //object to it. Solution and starting information is not copied. 51 newlp->lp = CPXcloneprob(env, lp, &status); 52 return *newlp; 48 return new LpCplex(); 49 } 50 51 LpSolverBase* LpCplex::_copyLp() { 52 return new LpCplex(*this); 53 53 } 54 54 … … 57 57 int i = CPXgetnumcols(env, lp); 58 58 Value lb[1],ub[1]; 59 lb[0]=-INF; //-CPX_INFBOUND;60 ub[0]=INF; //CPX_INFBOUND;59 lb[0]=-INF; 60 ub[0]=INF; 61 61 status = CPXnewcols(env, lp, 1, NULL, lb, ub, NULL, NULL); 62 62 return i; … … 90 90 int storespace; 91 91 CPXgetcolname(env, lp, 0, 0, 0, &storespace, col, col); 92 92 if (storespace == 0) { 93 name.clear(); 94 return; 95 } 96 93 97 storespace *= -1; 94 98 std::vector<char> buf(storespace); … … 137 141 138 142 void LpCplex::_getRowCoeffs(int i, RowIterator b) const { 143 int tmp1, tmp2, tmp3, length; 144 CPXgetrows(env, lp, &tmp1, &tmp2, 0, 0, 0, &length, i, i); 145 146 length = -length; 147 std::vector<int> indices(length); 148 std::vector<double> values(length); 149 150 CPXgetrows(env, lp, &tmp1, &tmp2, &indices[0], &values[0], 151 length, &tmp3, i, i); 152 153 for (int i = 0; i < length; ++i) { 154 *b = std::make_pair(indices[i], values[i]); 155 ++b; 156 } 157 139 158 /// \todo implement 140 159 } … … 157 176 158 177 void LpCplex::_getColCoeffs(int i, ColIterator b) const { 159 /// \todo implement 178 179 int tmp1, tmp2, tmp3, length; 180 CPXgetcols(env, lp, &tmp1, &tmp2, 0, 0, 0, &length, i, i); 181 182 length = -length; 183 std::vector<int> indices(length); 184 std::vector<double> values(length); 185 186 CPXgetcols(env, lp, &tmp1, &tmp2, &indices[0], &values[0], 187 length, &tmp3, i, i); 188 189 for (int i = 0; i < length; ++i) { 190 *b = std::make_pair(indices[i], values[i]); 191 ++b; 192 } 193 160 194 } 161 195 … … 188 222 LpCplex::Value x; 189 223 CPXgetlb (env, lp, &x, i, i); 224 if (x <= -CPX_INFBOUND) x = -INF; 190 225 return x; 191 226 } … … 206 241 LpCplex::Value x; 207 242 CPXgetub (env, lp, &x, i, i); 243 if (x >= CPX_INFBOUND) x = INF; 208 244 return x; 209 245 } … … 470 506 // Description: Method for linear optimization. 471 507 // Determines which algorithm is used when CPXlpopt() (or "optimize" in the Interactive Optimizer) is called. Currently the behavior of the "Automatic" setting is that CPLEX simply invokes the dual simplex method, but this capability may be expanded in the future so that CPLEX chooses the method based on problem characteristics 508 #if CPX_VERSION < 900 472 509 void statusSwitch(CPXENVptr env,int& stat){ 473 #if CPX_VERSION < 900474 510 int lpmethod; 475 511 CPXgetintparam (env,CPX_PARAM_LPMETHOD,&lpmethod); … … 483 519 } 484 520 } 521 } 522 #else 523 void statusSwitch(CPXENVptr,int&){} 485 524 #endif 486 }487 525 488 526 LpCplex::SolutionStatus LpCplex::_getPrimalStatus() const
Note: See TracChangeset
for help on using the changeset viewer.