140 class Row { |
141 class Row { |
141 protected: |
142 protected: |
142 int id; |
143 int id; |
143 friend class LpSolverBase; |
144 friend class LpSolverBase; |
144 public: |
145 public: |
|
146 typedef Value ExprValue; |
145 typedef True LpSolverRow; |
147 typedef True LpSolverRow; |
146 Row() {} |
148 Row() {} |
147 Row(const Invalid&) : id(-1) {} |
149 Row(const Invalid&) : id(-1) {} |
148 typedef True LpSolverRow; |
150 typedef True LpSolverRow; |
149 bool operator<(Row c) const {return id<c.id;} |
151 bool operator<(Row c) const {return id<c.id;} |
150 bool operator==(Row c) const {return id==c.id;} |
152 bool operator==(Row c) const {return id==c.id;} |
151 bool operator!=(Row c) const {return id==c.id;} |
153 bool operator!=(Row c) const {return id==c.id;} |
152 }; |
154 }; |
153 |
155 |
154 typedef SparseLinExpr<Col, Value> Expr; |
156 ///Linear expression |
|
157 typedef SparseLinExpr<Col> Expr; |
155 |
158 |
156 protected: |
159 protected: |
157 _FixId rows; |
160 _FixId rows; |
158 _FixId cols; |
161 _FixId cols; |
159 |
162 |
182 |
185 |
183 /// \e |
186 /// \e |
184 |
187 |
185 /// The lower bound of a variable (column) have to be given by an |
188 /// The lower bound of a variable (column) have to be given by an |
186 /// extended number of type Value, i.e. a finite number of type |
189 /// extended number of type Value, i.e. a finite number of type |
187 /// Value or -INF. |
190 /// Value or -\ref INF. |
188 virtual void _setColLowerBound(int i, Value value) = 0; |
191 virtual void _setColLowerBound(int i, Value value) = 0; |
189 /// \e |
192 /// \e |
190 |
193 |
191 /// The upper bound of a variable (column) have to be given by an |
194 /// The upper bound of a variable (column) have to be given by an |
192 /// extended number of type Value, i.e. a finite number of type |
195 /// extended number of type Value, i.e. a finite number of type |
193 /// Value or INF. |
196 /// Value or \ref INF. |
194 virtual void _setColUpperBound(int i, Value value) = 0; |
197 virtual void _setColUpperBound(int i, Value value) = 0; |
195 /// \e |
198 /// \e |
196 |
199 |
197 /// The lower bound of a linear expression (row) have to be given by an |
200 /// The lower bound of a linear expression (row) have to be given by an |
198 /// extended number of type Value, i.e. a finite number of type |
201 /// extended number of type Value, i.e. a finite number of type |
199 /// Value or -INF. |
202 /// Value or -\ref INF. |
200 virtual void _setRowLowerBound(int i, Value value) = 0; |
203 virtual void _setRowLowerBound(int i, Value value) = 0; |
201 /// \e |
204 /// \e |
202 |
205 |
203 /// The upper bound of a linear expression (row) have to be given by an |
206 /// The upper bound of a linear expression (row) have to be given by an |
204 /// extended number of type Value, i.e. a finite number of type |
207 /// extended number of type Value, i.e. a finite number of type |
205 /// Value or INF. |
208 /// Value or \ref INF. |
206 virtual void _setRowUpperBound(int i, Value value) = 0; |
209 virtual void _setRowUpperBound(int i, Value value) = 0; |
207 |
210 |
208 /// \e |
211 /// \e |
209 virtual void _setObjCoeff(int i, Value obj_coef) = 0; |
212 virtual void _setObjCoeff(int i, Value obj_coef) = 0; |
210 |
213 |
265 Row addRow() { Row r; r.id=rows.insert(_addRow()); return r;} |
268 Row addRow() { Row r; r.id=rows.insert(_addRow()); return r;} |
266 |
269 |
267 ///Set a row (i.e a constaint) of the LP |
270 ///Set a row (i.e a constaint) of the LP |
268 |
271 |
269 ///\param r is the row to be modified |
272 ///\param r is the row to be modified |
270 ///\param l is lower bound (-INF means no bound) |
273 ///\param l is lower bound (-\ref INF means no bound) |
271 ///\param e is a linear expression (see \ref Expr) |
274 ///\param e is a linear expression (see \ref Expr) |
272 ///\param u is the upper bound (INF means no bound) |
275 ///\param u is the upper bound (\ref INF means no bound) |
273 ///\bug This is a temportary function. The interface will change to |
276 ///\bug This is a temportary function. The interface will change to |
274 ///a better one. |
277 ///a better one. |
275 void setRow(Row r, Value l,const Expr &e, Value u) { |
278 void setRow(Row r, Value l,const Expr &e, Value u) { |
276 std::vector<int> indices; |
279 std::vector<int> indices; |
277 std::vector<Value> values; |
280 std::vector<Value> values; |
288 _setRowUpperBound(rows.floatingId(r.id),u-e.constComp()); |
291 _setRowUpperBound(rows.floatingId(r.id),u-e.constComp()); |
289 } |
292 } |
290 |
293 |
291 ///Add a new row (i.e a new constaint) to the LP |
294 ///Add a new row (i.e a new constaint) to the LP |
292 |
295 |
293 ///\param l is the lower bound (-INF means no bound) |
296 ///\param l is the lower bound (-\ref INF means no bound) |
294 ///\param e is a linear expression (see \ref Expr) |
297 ///\param e is a linear expression (see \ref Expr) |
295 ///\param u is the upper bound (INF means no bound) |
298 ///\param u is the upper bound (\ref INF means no bound) |
296 ///\return The created row. |
299 ///\return The created row. |
297 ///\bug This is a temportary function. The interface will change to |
300 ///\bug This is a temportary function. The interface will change to |
298 ///a better one. |
301 ///a better one. |
299 Row addRow(Value l,const Expr &e, Value u) { |
302 Row addRow(Value l,const Expr &e, Value u) { |
300 Row r=addRow(); |
303 Row r=addRow(); |
304 |
307 |
305 /// Set the lower bound of a column (i.e a variable) |
308 /// Set the lower bound of a column (i.e a variable) |
306 |
309 |
307 /// The upper bound of a variable (column) have to be given by an |
310 /// The upper bound of a variable (column) have to be given by an |
308 /// extended number of type Value, i.e. a finite number of type |
311 /// extended number of type Value, i.e. a finite number of type |
309 /// Value or -INF. |
312 /// Value or -\ref INF. |
310 virtual void setColLowerBound(Col c, Value value) { |
313 virtual void setColLowerBound(Col c, Value value) { |
311 _setColLowerBound(cols.floatingId(c.id),value); |
314 _setColLowerBound(cols.floatingId(c.id),value); |
312 } |
315 } |
313 /// Set the upper bound of a column (i.e a variable) |
316 /// Set the upper bound of a column (i.e a variable) |
314 |
317 |
315 /// The upper bound of a variable (column) have to be given by an |
318 /// The upper bound of a variable (column) have to be given by an |
316 /// extended number of type Value, i.e. a finite number of type |
319 /// extended number of type Value, i.e. a finite number of type |
317 /// Value or INF. |
320 /// Value or \ref INF. |
318 virtual void setColUpperBound(Col c, Value value) { |
321 virtual void setColUpperBound(Col c, Value value) { |
319 _setColUpperBound(cols.floatingId(c.id),value); |
322 _setColUpperBound(cols.floatingId(c.id),value); |
320 }; |
323 }; |
321 /// Set the lower bound of a row (i.e a constraint) |
324 /// Set the lower bound of a row (i.e a constraint) |
322 |
325 |
323 /// The lower bound of a linear expression (row) have to be given by an |
326 /// The lower bound of a linear expression (row) have to be given by an |
324 /// extended number of type Value, i.e. a finite number of type |
327 /// extended number of type Value, i.e. a finite number of type |
325 /// Value or -INF. |
328 /// Value or -\ref INF. |
326 virtual void setRowLowerBound(Row r, Value value) { |
329 virtual void setRowLowerBound(Row r, Value value) { |
327 _setRowLowerBound(rows.floatingId(r.id),value); |
330 _setRowLowerBound(rows.floatingId(r.id),value); |
328 }; |
331 }; |
329 /// Set the upper bound of a row (i.e a constraint) |
332 /// Set the upper bound of a row (i.e a constraint) |
330 |
333 |
331 /// The upper bound of a linear expression (row) have to be given by an |
334 /// The upper bound of a linear expression (row) have to be given by an |
332 /// extended number of type Value, i.e. a finite number of type |
335 /// extended number of type Value, i.e. a finite number of type |
333 /// Value or INF. |
336 /// Value or \ref INF. |
334 virtual void setRowUpperBound(Row r, Value value) { |
337 virtual void setRowUpperBound(Row r, Value value) { |
335 _setRowUpperBound(rows.floatingId(r.id),value); |
338 _setRowUpperBound(rows.floatingId(r.id),value); |
336 }; |
339 }; |
337 ///Set an element of the objective function |
340 ///Set an element of the objective function |
338 void setObjCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); }; |
341 void setObjCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); }; |