87 |
87 |
88 return soplex->nRows() - 1; |
88 return soplex->nRows() - 1; |
89 } |
89 } |
90 |
90 |
91 |
91 |
92 void LpSoplex::_eraseCol(int i) { |
92 void SoplexLp::_eraseCol(int i) { |
93 soplex->removeCol(i); |
93 soplex->removeCol(i); |
94 _col_names_ref.erase(_col_names[i]); |
94 _col_names_ref.erase(_col_names[i]); |
95 _col_names[i] = _col_names.back(); |
95 _col_names[i] = _col_names.back(); |
96 _col_names_ref[_col_names.back()] = i; |
96 _col_names_ref[_col_names.back()] = i; |
97 _col_names.pop_back(); |
97 _col_names.pop_back(); |
98 } |
98 } |
99 |
99 |
100 void LpSoplex::_eraseRow(int i) { |
100 void SoplexLp::_eraseRow(int i) { |
101 soplex->removeRow(i); |
101 soplex->removeRow(i); |
102 _row_names_ref.erase(_row_names[i]); |
102 _row_names_ref.erase(_row_names[i]); |
103 _row_names[i] = _row_names.back(); |
103 _row_names[i] = _row_names.back(); |
104 _row_names_ref[_row_names.back()] = i; |
104 _row_names_ref[_row_names.back()] = i; |
105 _row_names.pop_back(); |
105 _row_names.pop_back(); |
106 } |
106 } |
107 |
107 |
108 void LpSoplex::_eraseColId(int i) { |
108 void SoplexLp::_eraseColId(int i) { |
109 cols.eraseIndex(i); |
109 cols.eraseIndex(i); |
110 cols.relocateIndex(i, cols.maxIndex()); |
110 cols.relocateIndex(i, cols.maxIndex()); |
111 } |
111 } |
112 void LpSoplex::_eraseRowId(int i) { |
112 void SoplexLp::_eraseRowId(int i) { |
113 rows.eraseIndex(i); |
113 rows.eraseIndex(i); |
114 rows.relocateIndex(i, rows.maxIndex()); |
114 rows.relocateIndex(i, rows.maxIndex()); |
115 } |
115 } |
116 |
116 |
117 void LpSoplex::_getColName(int c, std::string &name) const { |
117 void SoplexLp::_getColName(int c, std::string &name) const { |
118 name = _col_names[c]; |
118 name = _col_names[c]; |
119 } |
119 } |
120 |
120 |
121 void LpSoplex::_setColName(int c, const std::string &name) { |
121 void SoplexLp::_setColName(int c, const std::string &name) { |
122 _col_names_ref.erase(_col_names[c]); |
122 _col_names_ref.erase(_col_names[c]); |
123 _col_names[c] = name; |
123 _col_names[c] = name; |
124 if (!name.empty()) { |
124 if (!name.empty()) { |
125 _col_names_ref.insert(std::make_pair(name, c)); |
125 _col_names_ref.insert(std::make_pair(name, c)); |
126 } |
126 } |
127 } |
127 } |
128 |
128 |
129 int LpSoplex::_colByName(const std::string& name) const { |
129 int SoplexLp::_colByName(const std::string& name) const { |
130 std::map<std::string, int>::const_iterator it = |
130 std::map<std::string, int>::const_iterator it = |
131 _col_names_ref.find(name); |
131 _col_names_ref.find(name); |
132 if (it != _col_names_ref.end()) { |
132 if (it != _col_names_ref.end()) { |
133 return it->second; |
133 return it->second; |
134 } else { |
134 } else { |
135 return -1; |
135 return -1; |
136 } |
136 } |
137 } |
137 } |
138 |
138 |
139 void LpSoplex::_getRowName(int r, std::string &name) const { |
139 void SoplexLp::_getRowName(int r, std::string &name) const { |
140 name = _row_names[r]; |
140 name = _row_names[r]; |
141 } |
141 } |
142 |
142 |
143 void LpSoplex::_setRowName(int r, const std::string &name) { |
143 void SoplexLp::_setRowName(int r, const std::string &name) { |
144 _row_names_ref.erase(_row_names[r]); |
144 _row_names_ref.erase(_row_names[r]); |
145 _row_names[r] = name; |
145 _row_names[r] = name; |
146 if (!name.empty()) { |
146 if (!name.empty()) { |
147 _row_names_ref.insert(std::make_pair(name, r)); |
147 _row_names_ref.insert(std::make_pair(name, r)); |
148 } |
148 } |
149 } |
149 } |
150 |
150 |
151 int LpSoplex::_rowByName(const std::string& name) const { |
151 int SoplexLp::_rowByName(const std::string& name) const { |
152 std::map<std::string, int>::const_iterator it = |
152 std::map<std::string, int>::const_iterator it = |
153 _row_names_ref.find(name); |
153 _row_names_ref.find(name); |
154 if (it != _row_names_ref.end()) { |
154 if (it != _row_names_ref.end()) { |
155 return it->second; |
155 return it->second; |
156 } else { |
156 } else { |
157 return -1; |
157 return -1; |
158 } |
158 } |
159 } |
159 } |
160 |
160 |
161 |
161 |
162 void LpSoplex::_setRowCoeffs(int i, ExprIterator b, ExprIterator e) { |
162 void SoplexLp::_setRowCoeffs(int i, ExprIterator b, ExprIterator e) { |
163 for (int j = 0; j < soplex->nCols(); ++j) { |
163 for (int j = 0; j < soplex->nCols(); ++j) { |
164 soplex->changeElement(i, j, 0.0); |
164 soplex->changeElement(i, j, 0.0); |
165 } |
165 } |
166 for(ExprIterator it = b; it != e; ++it) { |
166 for(ExprIterator it = b; it != e; ++it) { |
167 soplex->changeElement(i, it->first, it->second); |
167 soplex->changeElement(i, it->first, it->second); |
168 } |
168 } |
169 } |
169 } |
170 |
170 |
171 void LpSoplex::_getRowCoeffs(int i, InsertIterator b) const { |
171 void SoplexLp::_getRowCoeffs(int i, InsertIterator b) const { |
172 const soplex::SVector& vec = soplex->rowVector(i); |
172 const soplex::SVector& vec = soplex->rowVector(i); |
173 for (int k = 0; k < vec.size(); ++k) { |
173 for (int k = 0; k < vec.size(); ++k) { |
174 *b = std::make_pair(vec.index(k), vec.value(k)); |
174 *b = std::make_pair(vec.index(k), vec.value(k)); |
175 ++b; |
175 ++b; |
176 } |
176 } |
177 } |
177 } |
178 |
178 |
179 void LpSoplex::_setColCoeffs(int j, ExprIterator b, ExprIterator e) { |
179 void SoplexLp::_setColCoeffs(int j, ExprIterator b, ExprIterator e) { |
180 for (int i = 0; i < soplex->nRows(); ++i) { |
180 for (int i = 0; i < soplex->nRows(); ++i) { |
181 soplex->changeElement(i, j, 0.0); |
181 soplex->changeElement(i, j, 0.0); |
182 } |
182 } |
183 for(ExprIterator it = b; it != e; ++it) { |
183 for(ExprIterator it = b; it != e; ++it) { |
184 soplex->changeElement(it->first, j, it->second); |
184 soplex->changeElement(it->first, j, it->second); |
185 } |
185 } |
186 } |
186 } |
187 |
187 |
188 void LpSoplex::_getColCoeffs(int i, InsertIterator b) const { |
188 void SoplexLp::_getColCoeffs(int i, InsertIterator b) const { |
189 const soplex::SVector& vec = soplex->colVector(i); |
189 const soplex::SVector& vec = soplex->colVector(i); |
190 for (int k = 0; k < vec.size(); ++k) { |
190 for (int k = 0; k < vec.size(); ++k) { |
191 *b = std::make_pair(vec.index(k), vec.value(k)); |
191 *b = std::make_pair(vec.index(k), vec.value(k)); |
192 ++b; |
192 ++b; |
193 } |
193 } |
194 } |
194 } |
195 |
195 |
196 void LpSoplex::_setCoeff(int i, int j, Value value) { |
196 void SoplexLp::_setCoeff(int i, int j, Value value) { |
197 soplex->changeElement(i, j, value); |
197 soplex->changeElement(i, j, value); |
198 } |
198 } |
199 |
199 |
200 LpSoplex::Value LpSoplex::_getCoeff(int i, int j) const { |
200 SoplexLp::Value SoplexLp::_getCoeff(int i, int j) const { |
201 return soplex->rowVector(i)[j]; |
201 return soplex->rowVector(i)[j]; |
202 } |
202 } |
203 |
203 |
204 void LpSoplex::_setColLowerBound(int i, Value value) { |
204 void SoplexLp::_setColLowerBound(int i, Value value) { |
205 LEMON_ASSERT(value != INF, "Invalid bound"); |
205 LEMON_ASSERT(value != INF, "Invalid bound"); |
206 soplex->changeLower(i, value != -INF ? value : -soplex::infinity); |
206 soplex->changeLower(i, value != -INF ? value : -soplex::infinity); |
207 } |
207 } |
208 |
208 |
209 LpSoplex::Value LpSoplex::_getColLowerBound(int i) const { |
209 SoplexLp::Value SoplexLp::_getColLowerBound(int i) const { |
210 double value = soplex->lower(i); |
210 double value = soplex->lower(i); |
211 return value != -soplex::infinity ? value : -INF; |
211 return value != -soplex::infinity ? value : -INF; |
212 } |
212 } |
213 |
213 |
214 void LpSoplex::_setColUpperBound(int i, Value value) { |
214 void SoplexLp::_setColUpperBound(int i, Value value) { |
215 LEMON_ASSERT(value != -INF, "Invalid bound"); |
215 LEMON_ASSERT(value != -INF, "Invalid bound"); |
216 soplex->changeUpper(i, value != INF ? value : soplex::infinity); |
216 soplex->changeUpper(i, value != INF ? value : soplex::infinity); |
217 } |
217 } |
218 |
218 |
219 LpSoplex::Value LpSoplex::_getColUpperBound(int i) const { |
219 SoplexLp::Value SoplexLp::_getColUpperBound(int i) const { |
220 double value = soplex->upper(i); |
220 double value = soplex->upper(i); |
221 return value != soplex::infinity ? value : INF; |
221 return value != soplex::infinity ? value : INF; |
222 } |
222 } |
223 |
223 |
224 void LpSoplex::_setRowLowerBound(int i, Value lb) { |
224 void SoplexLp::_setRowLowerBound(int i, Value lb) { |
225 LEMON_ASSERT(lb != INF, "Invalid bound"); |
225 LEMON_ASSERT(lb != INF, "Invalid bound"); |
226 soplex->changeRange(i, lb != -INF ? lb : -soplex::infinity, soplex->rhs(i)); |
226 soplex->changeRange(i, lb != -INF ? lb : -soplex::infinity, soplex->rhs(i)); |
227 } |
227 } |
228 |
228 |
229 LpSoplex::Value LpSoplex::_getRowLowerBound(int i) const { |
229 SoplexLp::Value SoplexLp::_getRowLowerBound(int i) const { |
230 double res = soplex->lhs(i); |
230 double res = soplex->lhs(i); |
231 return res == -soplex::infinity ? -INF : res; |
231 return res == -soplex::infinity ? -INF : res; |
232 } |
232 } |
233 |
233 |
234 void LpSoplex::_setRowUpperBound(int i, Value ub) { |
234 void SoplexLp::_setRowUpperBound(int i, Value ub) { |
235 LEMON_ASSERT(ub != -INF, "Invalid bound"); |
235 LEMON_ASSERT(ub != -INF, "Invalid bound"); |
236 soplex->changeRange(i, soplex->lhs(i), ub != INF ? ub : soplex::infinity); |
236 soplex->changeRange(i, soplex->lhs(i), ub != INF ? ub : soplex::infinity); |
237 } |
237 } |
238 |
238 |
239 LpSoplex::Value LpSoplex::_getRowUpperBound(int i) const { |
239 SoplexLp::Value SoplexLp::_getRowUpperBound(int i) const { |
240 double res = soplex->rhs(i); |
240 double res = soplex->rhs(i); |
241 return res == soplex::infinity ? INF : res; |
241 return res == soplex::infinity ? INF : res; |
242 } |
242 } |
243 |
243 |
244 void LpSoplex::_setObjCoeffs(ExprIterator b, ExprIterator e) { |
244 void SoplexLp::_setObjCoeffs(ExprIterator b, ExprIterator e) { |
245 for (int j = 0; j < soplex->nCols(); ++j) { |
245 for (int j = 0; j < soplex->nCols(); ++j) { |
246 soplex->changeObj(j, 0.0); |
246 soplex->changeObj(j, 0.0); |
247 } |
247 } |
248 for (ExprIterator it = b; it != e; ++it) { |
248 for (ExprIterator it = b; it != e; ++it) { |
249 soplex->changeObj(it->first, it->second); |
249 soplex->changeObj(it->first, it->second); |
250 } |
250 } |
251 } |
251 } |
252 |
252 |
253 void LpSoplex::_getObjCoeffs(InsertIterator b) const { |
253 void SoplexLp::_getObjCoeffs(InsertIterator b) const { |
254 for (int j = 0; j < soplex->nCols(); ++j) { |
254 for (int j = 0; j < soplex->nCols(); ++j) { |
255 Value coef = soplex->obj(j); |
255 Value coef = soplex->obj(j); |
256 if (coef != 0.0) { |
256 if (coef != 0.0) { |
257 *b = std::make_pair(j, coef); |
257 *b = std::make_pair(j, coef); |
258 ++b; |
258 ++b; |
259 } |
259 } |
260 } |
260 } |
261 } |
261 } |
262 |
262 |
263 void LpSoplex::_setObjCoeff(int i, Value obj_coef) { |
263 void SoplexLp::_setObjCoeff(int i, Value obj_coef) { |
264 soplex->changeObj(i, obj_coef); |
264 soplex->changeObj(i, obj_coef); |
265 } |
265 } |
266 |
266 |
267 LpSoplex::Value LpSoplex::_getObjCoeff(int i) const { |
267 SoplexLp::Value SoplexLp::_getObjCoeff(int i) const { |
268 return soplex->obj(i); |
268 return soplex->obj(i); |
269 } |
269 } |
270 |
270 |
271 LpSoplex::SolveExitStatus LpSoplex::_solve() { |
271 SoplexLp::SolveExitStatus SoplexLp::_solve() { |
272 |
272 |
273 _clear_temporals(); |
273 _clear_temporals(); |
274 |
274 |
275 soplex::SPxSolver::Status status = soplex->solve(); |
275 soplex::SPxSolver::Status status = soplex->solve(); |
276 |
276 |