1.1 --- a/lemon/cplex.cc Mon Jan 12 23:11:39 2009 +0100
1.2 +++ b/lemon/cplex.cc Thu Nov 05 15:48:01 2009 +0100
1.3 @@ -2,7 +2,7 @@
1.4 *
1.5 * This file is a part of LEMON, a generic C++ optimization library.
1.6 *
1.7 - * Copyright (C) 2003-2008
1.8 + * Copyright (C) 2003-2009
1.9 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 *
1.12 @@ -72,12 +72,14 @@
1.13 CplexBase::CplexBase() : LpBase() {
1.14 int status;
1.15 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
1.16 + messageLevel(MESSAGE_NOTHING);
1.17 }
1.18
1.19 CplexBase::CplexBase(const CplexEnv& env)
1.20 : LpBase(), _env(env) {
1.21 int status;
1.22 _prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem");
1.23 + messageLevel(MESSAGE_NOTHING);
1.24 }
1.25
1.26 CplexBase::CplexBase(const CplexBase& cplex)
1.27 @@ -86,6 +88,7 @@
1.28 _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status);
1.29 rows = cplex.rows;
1.30 cols = cplex.cols;
1.31 + messageLevel(MESSAGE_NOTHING);
1.32 }
1.33
1.34 CplexBase::~CplexBase() {
1.35 @@ -108,6 +111,39 @@
1.36 return i;
1.37 }
1.38
1.39 + int CplexBase::_addRow(Value lb, ExprIterator b,
1.40 + ExprIterator e, Value ub) {
1.41 + int i = CPXgetnumrows(cplexEnv(), _prob);
1.42 + if (lb == -INF) {
1.43 + const char s = 'L';
1.44 + CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0);
1.45 + } else if (ub == INF) {
1.46 + const char s = 'G';
1.47 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
1.48 + } else if (lb == ub){
1.49 + const char s = 'E';
1.50 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0);
1.51 + } else {
1.52 + const char s = 'R';
1.53 + double len = ub - lb;
1.54 + CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0);
1.55 + }
1.56 +
1.57 + std::vector<int> indices;
1.58 + std::vector<int> rowlist;
1.59 + std::vector<Value> values;
1.60 +
1.61 + for(ExprIterator it=b; it!=e; ++it) {
1.62 + indices.push_back(it->first);
1.63 + values.push_back(it->second);
1.64 + rowlist.push_back(i);
1.65 + }
1.66 +
1.67 + CPXchgcoeflist(cplexEnv(), _prob, values.size(),
1.68 + &rowlist.front(), &indices.front(), &values.front());
1.69 +
1.70 + return i;
1.71 + }
1.72
1.73 void CplexBase::_eraseCol(int i) {
1.74 CPXdelcols(cplexEnv(), _prob, i, i);
1.75 @@ -438,21 +474,40 @@
1.76 cols.clear();
1.77 }
1.78
1.79 + void CplexBase::_messageLevel(MessageLevel level) {
1.80 + switch (level) {
1.81 + case MESSAGE_NOTHING:
1.82 + _message_enabled = false;
1.83 + break;
1.84 + case MESSAGE_ERROR:
1.85 + case MESSAGE_WARNING:
1.86 + case MESSAGE_NORMAL:
1.87 + case MESSAGE_VERBOSE:
1.88 + _message_enabled = true;
1.89 + break;
1.90 + }
1.91 + }
1.92 +
1.93 + void CplexBase::_applyMessageLevel() {
1.94 + CPXsetintparam(cplexEnv(), CPX_PARAM_SCRIND,
1.95 + _message_enabled ? CPX_ON : CPX_OFF);
1.96 + }
1.97 +
1.98 // CplexLp members
1.99
1.100 CplexLp::CplexLp()
1.101 - : LpBase(), CplexBase(), LpSolver() {}
1.102 + : LpBase(), LpSolver(), CplexBase() {}
1.103
1.104 CplexLp::CplexLp(const CplexEnv& env)
1.105 - : LpBase(), CplexBase(env), LpSolver() {}
1.106 + : LpBase(), LpSolver(), CplexBase(env) {}
1.107
1.108 CplexLp::CplexLp(const CplexLp& other)
1.109 - : LpBase(), CplexBase(other), LpSolver() {}
1.110 + : LpBase(), LpSolver(), CplexBase(other) {}
1.111
1.112 CplexLp::~CplexLp() {}
1.113
1.114 - CplexLp* CplexLp::_newSolver() const { return new CplexLp; }
1.115 - CplexLp* CplexLp::_cloneSolver() const {return new CplexLp(*this); }
1.116 + CplexLp* CplexLp::newSolver() const { return new CplexLp; }
1.117 + CplexLp* CplexLp::cloneSolver() const {return new CplexLp(*this); }
1.118
1.119 const char* CplexLp::_solverName() const { return "CplexLp"; }
1.120
1.121 @@ -507,21 +562,25 @@
1.122
1.123 CplexLp::SolveExitStatus CplexLp::_solve() {
1.124 _clear_temporals();
1.125 + _applyMessageLevel();
1.126 return convertStatus(CPXlpopt(cplexEnv(), _prob));
1.127 }
1.128
1.129 CplexLp::SolveExitStatus CplexLp::solvePrimal() {
1.130 _clear_temporals();
1.131 + _applyMessageLevel();
1.132 return convertStatus(CPXprimopt(cplexEnv(), _prob));
1.133 }
1.134
1.135 CplexLp::SolveExitStatus CplexLp::solveDual() {
1.136 _clear_temporals();
1.137 + _applyMessageLevel();
1.138 return convertStatus(CPXdualopt(cplexEnv(), _prob));
1.139 }
1.140
1.141 CplexLp::SolveExitStatus CplexLp::solveBarrier() {
1.142 _clear_temporals();
1.143 + _applyMessageLevel();
1.144 return convertStatus(CPXbaropt(cplexEnv(), _prob));
1.145 }
1.146
1.147 @@ -600,7 +659,7 @@
1.148 return _dual_ray[i];
1.149 }
1.150
1.151 - //7.5-os cplex statusai (Vigyazat: a 9.0-asei masok!)
1.152 + // Cplex 7.0 status values
1.153 // This table lists the statuses, returned by the CPXgetstat()
1.154 // routine, for solutions to LP problems or mixed integer problems. If
1.155 // no solution exists, the return value is zero.
1.156 @@ -647,7 +706,7 @@
1.157 // 20 CPX_PIVOT
1.158 // User pivot used
1.159 //
1.160 - // Ezeket hova tegyem:
1.161 + // Pending return values
1.162 // ??case CPX_ABORT_DUAL_INFEAS
1.163 // ??case CPX_ABORT_CROSSOVER
1.164 // ??case CPX_INForUNBD
1.165 @@ -718,7 +777,6 @@
1.166 #else
1.167 statusSwitch(cplexEnv(),stat);
1.168 //CPXgetstat(cplexEnv(), _prob);
1.169 - //printf("A primal status: %d, CPX_OPTIMAL=%d \n",stat,CPX_OPTIMAL);
1.170 switch (stat) {
1.171 case 0:
1.172 return UNDEFINED; //Undefined
1.173 @@ -751,7 +809,7 @@
1.174 #endif
1.175 }
1.176
1.177 - //9.0-as cplex verzio statusai
1.178 + // Cplex 9.0 status values
1.179 // CPX_STAT_ABORT_DUAL_OBJ_LIM
1.180 // CPX_STAT_ABORT_IT_LIM
1.181 // CPX_STAT_ABORT_OBJ_LIM
1.182 @@ -798,7 +856,7 @@
1.183 // CplexMip members
1.184
1.185 CplexMip::CplexMip()
1.186 - : LpBase(), CplexBase(), MipSolver() {
1.187 + : LpBase(), MipSolver(), CplexBase() {
1.188
1.189 #if CPX_VERSION < 800
1.190 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
1.191 @@ -808,7 +866,7 @@
1.192 }
1.193
1.194 CplexMip::CplexMip(const CplexEnv& env)
1.195 - : LpBase(), CplexBase(env), MipSolver() {
1.196 + : LpBase(), MipSolver(), CplexBase(env) {
1.197
1.198 #if CPX_VERSION < 800
1.199 CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP);
1.200 @@ -819,12 +877,12 @@
1.201 }
1.202
1.203 CplexMip::CplexMip(const CplexMip& other)
1.204 - : LpBase(), CplexBase(other), MipSolver() {}
1.205 + : LpBase(), MipSolver(), CplexBase(other) {}
1.206
1.207 CplexMip::~CplexMip() {}
1.208
1.209 - CplexMip* CplexMip::_newSolver() const { return new CplexMip; }
1.210 - CplexMip* CplexMip::_cloneSolver() const {return new CplexMip(*this); }
1.211 + CplexMip* CplexMip::newSolver() const { return new CplexMip; }
1.212 + CplexMip* CplexMip::cloneSolver() const {return new CplexMip(*this); }
1.213
1.214 const char* CplexMip::_solverName() const { return "CplexMip"; }
1.215
1.216 @@ -864,6 +922,7 @@
1.217
1.218 CplexMip::SolveExitStatus CplexMip::_solve() {
1.219 int status;
1.220 + _applyMessageLevel();
1.221 status = CPXmipopt (cplexEnv(), _prob);
1.222 if (status==0)
1.223 return SOLVED;