Changeset 1140:f8ec64f78b5f in lemon-main
- Timestamp:
- 05/07/15 11:42:19 (10 years ago)
- Branch:
- default
- Parents:
- 1138:f95b18d99843 (diff), 1139:0900cfe4a84d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/cplex.cc
r1130 r1140 38 38 } 39 39 40 void CplexEnv::incCnt() 41 { 42 _cnt_lock->lock(); 43 ++(*_cnt); 44 _cnt_lock->unlock(); 45 } 46 47 void CplexEnv::decCnt() 48 { 49 _cnt_lock->lock(); 50 --(*_cnt); 51 if (*_cnt == 0) { 52 delete _cnt; 53 _cnt_lock->unlock(); 54 delete _cnt_lock; 55 CPXcloseCPLEX(&_env); 56 } 57 else _cnt_lock->unlock(); 58 } 59 40 60 CplexEnv::CplexEnv() { 41 61 int status; 62 _env = CPXopenCPLEX(&status); 63 if (_env == 0) 64 throw LicenseError(status); 42 65 _cnt = new int; 43 66 (*_cnt) = 1; 44 _env = CPXopenCPLEX(&status); 45 if (_env == 0) { 46 delete _cnt; 47 _cnt = 0; 48 throw LicenseError(status); 49 } 67 _cnt_lock = new bits::Lock; 50 68 } 51 69 … … 53 71 _env = other._env; 54 72 _cnt = other._cnt; 55 ++(*_cnt); 73 _cnt_lock = other._cnt_lock; 74 incCnt(); 56 75 } 57 76 58 77 CplexEnv& CplexEnv::operator=(const CplexEnv& other) { 78 decCnt(); 59 79 _env = other._env; 60 80 _cnt = other._cnt; 61 ++(*_cnt); 81 _cnt_lock = other._cnt_lock; 82 incCnt(); 62 83 return *this; 63 84 } 64 85 65 86 CplexEnv::~CplexEnv() { 66 --(*_cnt); 67 if (*_cnt == 0) { 68 delete _cnt; 69 CPXcloseCPLEX(&_env); 70 } 87 decCnt(); 71 88 } 72 89 -
lemon/cplex.cc
r1139 r1140 105 105 int status; 106 106 _prob = CPXcloneprob(cplexEnv(), cplex._prob, &status); 107 rows = cplex.rows;108 cols = cplex.cols;107 _rows = cplex._rows; 108 _cols = cplex._cols; 109 109 messageLevel(MESSAGE_NOTHING); 110 110 } … … 133 133 ExprIterator e, Value ub) { 134 134 int i = CPXgetnumrows(cplexEnv(), _prob); 135 136 int rmatbeg = 0; 137 138 std::vector<int> indices; 139 std::vector<Value> values; 140 141 for(ExprIterator it=b; it!=e; ++it) { 142 indices.push_back(it->first); 143 values.push_back(it->second); 144 } 145 135 146 if (lb == -INF) { 136 147 const char s = 'L'; 137 CPXnewrows(cplexEnv(), _prob, 1, &ub, &s, 0, 0); 148 CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &ub, &s, 149 &rmatbeg, &indices.front(), &values.front(), 0, 0); 138 150 } else if (ub == INF) { 139 151 const char s = 'G'; 140 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); 152 CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &lb, &s, 153 &rmatbeg, &indices.front(), &values.front(), 0, 0); 141 154 } else if (lb == ub){ 142 155 const char s = 'E'; 143 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, 0, 0); 156 CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &lb, &s, 157 &rmatbeg, &indices.front(), &values.front(), 0, 0); 144 158 } else { 145 159 const char s = 'R'; 146 160 double len = ub - lb; 147 CPXnewrows(cplexEnv(), _prob, 1, &lb, &s, &len, 0); 148 } 149 150 std::vector<int> indices; 151 std::vector<int> rowlist; 152 std::vector<Value> values; 153 154 for(ExprIterator it=b; it!=e; ++it) { 155 indices.push_back(it->first); 156 values.push_back(it->second); 157 rowlist.push_back(i); 158 } 159 160 CPXchgcoeflist(cplexEnv(), _prob, values.size(), 161 &rowlist.front(), &indices.front(), &values.front()); 162 161 CPXaddrows(cplexEnv(), _prob, 0, 1, values.size(), &ub, &s, 162 &rmatbeg, &indices.front(), &values.front(), 0, 0); 163 CPXchgrngval(cplexEnv(), _prob, 1, &i, &len); 164 } 165 163 166 return i; 164 167 } … … 173 176 174 177 void CplexBase::_eraseColId(int i) { 175 cols.eraseIndex(i);176 cols.shiftIndices(i);178 _cols.eraseIndex(i); 179 _cols.shiftIndices(i); 177 180 } 178 181 void CplexBase::_eraseRowId(int i) { 179 rows.eraseIndex(i);180 rows.shiftIndices(i);182 _rows.eraseIndex(i); 183 _rows.shiftIndices(i); 181 184 } 182 185
Note: See TracChangeset
for help on using the changeset viewer.