[1247] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
[1956] | 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
[1359] | 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
[1247] | 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[1246] | 19 | #ifndef LEMON_LP_BASE_H |
---|
| 20 | #define LEMON_LP_BASE_H |
---|
| 21 | |
---|
[1253] | 22 | #include<vector> |
---|
[1272] | 23 | #include<map> |
---|
[1256] | 24 | #include<limits> |
---|
[1397] | 25 | #include<cmath> |
---|
[1253] | 26 | |
---|
[1993] | 27 | #include<lemon/bits/utility.h> |
---|
[1253] | 28 | #include<lemon/error.h> |
---|
[1993] | 29 | #include<lemon/bits/invalid.h> |
---|
[1253] | 30 | |
---|
[1246] | 31 | ///\file |
---|
| 32 | ///\brief The interface of the LP solver interface. |
---|
[1328] | 33 | ///\ingroup gen_opt_group |
---|
[1246] | 34 | namespace lemon { |
---|
[1253] | 35 | |
---|
| 36 | ///Internal data structure to convert floating id's to fix one's |
---|
| 37 | |
---|
[1279] | 38 | ///\todo This might be implemented to be also usable in other places. |
---|
[1253] | 39 | class _FixId |
---|
| 40 | { |
---|
[1787] | 41 | protected: |
---|
[1253] | 42 | std::vector<int> index; |
---|
| 43 | std::vector<int> cross; |
---|
| 44 | int first_free; |
---|
| 45 | public: |
---|
| 46 | _FixId() : first_free(-1) {}; |
---|
| 47 | ///Convert a floating id to a fix one |
---|
| 48 | |
---|
| 49 | ///\param n is a floating id |
---|
| 50 | ///\return the corresponding fix id |
---|
[1484] | 51 | int fixId(int n) const {return cross[n];} |
---|
[1253] | 52 | ///Convert a fix id to a floating one |
---|
| 53 | |
---|
| 54 | ///\param n is a fix id |
---|
| 55 | ///\return the corresponding floating id |
---|
[1484] | 56 | int floatingId(int n) const { return index[n];} |
---|
[1253] | 57 | ///Add a new floating id. |
---|
| 58 | |
---|
| 59 | ///\param n is a floating id |
---|
| 60 | ///\return the fix id of the new value |
---|
| 61 | ///\todo Multiple additions should also be handled. |
---|
| 62 | int insert(int n) |
---|
| 63 | { |
---|
| 64 | if(n>=int(cross.size())) { |
---|
| 65 | cross.resize(n+1); |
---|
| 66 | if(first_free==-1) { |
---|
| 67 | cross[n]=index.size(); |
---|
| 68 | index.push_back(n); |
---|
| 69 | } |
---|
| 70 | else { |
---|
| 71 | cross[n]=first_free; |
---|
| 72 | int next=index[first_free]; |
---|
| 73 | index[first_free]=n; |
---|
| 74 | first_free=next; |
---|
| 75 | } |
---|
[1256] | 76 | return cross[n]; |
---|
[1253] | 77 | } |
---|
[1273] | 78 | ///\todo Create an own exception type. |
---|
[1253] | 79 | else throw LogicError(); //floatingId-s must form a continuous range; |
---|
| 80 | } |
---|
| 81 | ///Remove a fix id. |
---|
| 82 | |
---|
| 83 | ///\param n is a fix id |
---|
| 84 | /// |
---|
| 85 | void erase(int n) |
---|
| 86 | { |
---|
| 87 | int fl=index[n]; |
---|
| 88 | index[n]=first_free; |
---|
| 89 | first_free=n; |
---|
| 90 | for(int i=fl+1;i<int(cross.size());++i) { |
---|
| 91 | cross[i-1]=cross[i]; |
---|
| 92 | index[cross[i]]--; |
---|
| 93 | } |
---|
| 94 | cross.pop_back(); |
---|
| 95 | } |
---|
| 96 | ///An upper bound on the largest fix id. |
---|
| 97 | |
---|
| 98 | ///\todo Do we need this? |
---|
| 99 | /// |
---|
| 100 | std::size_t maxFixId() { return cross.size()-1; } |
---|
| 101 | |
---|
| 102 | }; |
---|
| 103 | |
---|
| 104 | ///Common base class for LP solvers |
---|
[1328] | 105 | |
---|
| 106 | ///\todo Much more docs |
---|
| 107 | ///\ingroup gen_opt_group |
---|
[1246] | 108 | class LpSolverBase { |
---|
[1323] | 109 | |
---|
[1247] | 110 | public: |
---|
| 111 | |
---|
[1458] | 112 | ///Possible outcomes of an LP solving procedure |
---|
[1303] | 113 | enum SolveExitStatus { |
---|
[1458] | 114 | ///This means that the problem has been successfully solved: either |
---|
| 115 | ///an optimal solution has been found or infeasibility/unboundedness |
---|
| 116 | ///has been proved. |
---|
[1293] | 117 | SOLVED = 0, |
---|
[1458] | 118 | ///Any other case (including the case when some user specified limit has been exceeded) |
---|
[1293] | 119 | UNSOLVED = 1 |
---|
[1291] | 120 | }; |
---|
| 121 | |
---|
[1460] | 122 | ///\e |
---|
[1303] | 123 | enum SolutionStatus { |
---|
[1295] | 124 | ///Feasible solution has'n been found (but may exist). |
---|
| 125 | |
---|
| 126 | ///\todo NOTFOUND might be a better name. |
---|
| 127 | /// |
---|
[1293] | 128 | UNDEFINED = 0, |
---|
[1295] | 129 | ///The problem has no feasible solution |
---|
[1293] | 130 | INFEASIBLE = 1, |
---|
[1295] | 131 | ///Feasible solution found |
---|
[1293] | 132 | FEASIBLE = 2, |
---|
[1295] | 133 | ///Optimal solution exists and found |
---|
| 134 | OPTIMAL = 3, |
---|
| 135 | ///The cost function is unbounded |
---|
| 136 | |
---|
| 137 | ///\todo Give a feasible solution and an infinite ray (and the |
---|
| 138 | ///corresponding bases) |
---|
| 139 | INFINITE = 4 |
---|
[1263] | 140 | }; |
---|
[1460] | 141 | |
---|
[1542] | 142 | ///\e The type of the investigated LP problem |
---|
| 143 | enum ProblemTypes { |
---|
| 144 | ///Primal-dual feasible |
---|
| 145 | PRIMAL_DUAL_FEASIBLE = 0, |
---|
| 146 | ///Primal feasible dual infeasible |
---|
| 147 | PRIMAL_FEASIBLE_DUAL_INFEASIBLE = 1, |
---|
| 148 | ///Primal infeasible dual feasible |
---|
| 149 | PRIMAL_INFEASIBLE_DUAL_FEASIBLE = 2, |
---|
| 150 | ///Primal-dual infeasible |
---|
| 151 | PRIMAL_DUAL_INFEASIBLE = 3, |
---|
| 152 | ///Could not determine so far |
---|
| 153 | UNKNOWN = 4 |
---|
| 154 | }; |
---|
[1508] | 155 | |
---|
[1256] | 156 | ///The floating point type used by the solver |
---|
[1247] | 157 | typedef double Value; |
---|
[1256] | 158 | ///The infinity constant |
---|
[1247] | 159 | static const Value INF; |
---|
[1264] | 160 | ///The not a number constant |
---|
| 161 | static const Value NaN; |
---|
[2026] | 162 | |
---|
| 163 | static inline bool isNaN(const Value& v) { return v!=v; } |
---|
[1253] | 164 | |
---|
[1256] | 165 | ///Refer to a column of the LP. |
---|
| 166 | |
---|
| 167 | ///This type is used to refer to a column of the LP. |
---|
| 168 | /// |
---|
| 169 | ///Its value remains valid and correct even after the addition or erase of |
---|
[1273] | 170 | ///other columns. |
---|
[1256] | 171 | /// |
---|
| 172 | ///\todo Document what can one do with a Col (INVALID, comparing, |
---|
| 173 | ///it is similar to Node/Edge) |
---|
| 174 | class Col { |
---|
| 175 | protected: |
---|
| 176 | int id; |
---|
| 177 | friend class LpSolverBase; |
---|
| 178 | public: |
---|
[1259] | 179 | typedef Value ExprValue; |
---|
[1256] | 180 | typedef True LpSolverCol; |
---|
| 181 | Col() {} |
---|
| 182 | Col(const Invalid&) : id(-1) {} |
---|
[1900] | 183 | bool operator< (Col c) const {return id< c.id;} |
---|
| 184 | bool operator> (Col c) const {return id> c.id;} |
---|
[1256] | 185 | bool operator==(Col c) const {return id==c.id;} |
---|
[1900] | 186 | bool operator!=(Col c) const {return id!=c.id;} |
---|
[1256] | 187 | }; |
---|
| 188 | |
---|
| 189 | ///Refer to a row of the LP. |
---|
| 190 | |
---|
| 191 | ///This type is used to refer to a row of the LP. |
---|
| 192 | /// |
---|
| 193 | ///Its value remains valid and correct even after the addition or erase of |
---|
[1273] | 194 | ///other rows. |
---|
[1256] | 195 | /// |
---|
| 196 | ///\todo Document what can one do with a Row (INVALID, comparing, |
---|
| 197 | ///it is similar to Node/Edge) |
---|
| 198 | class Row { |
---|
| 199 | protected: |
---|
| 200 | int id; |
---|
| 201 | friend class LpSolverBase; |
---|
| 202 | public: |
---|
[1259] | 203 | typedef Value ExprValue; |
---|
[1256] | 204 | typedef True LpSolverRow; |
---|
| 205 | Row() {} |
---|
| 206 | Row(const Invalid&) : id(-1) {} |
---|
[1439] | 207 | |
---|
[1900] | 208 | bool operator< (Row c) const {return id< c.id;} |
---|
| 209 | bool operator> (Row c) const {return id> c.id;} |
---|
[1256] | 210 | bool operator==(Row c) const {return id==c.id;} |
---|
[1900] | 211 | bool operator!=(Row c) const {return id!=c.id;} |
---|
[1256] | 212 | }; |
---|
[1259] | 213 | |
---|
[1279] | 214 | ///Linear expression of variables and a constant component |
---|
| 215 | |
---|
| 216 | ///This data structure strores a linear expression of the variables |
---|
| 217 | ///(\ref Col "Col"s) and also has a constant component. |
---|
| 218 | /// |
---|
| 219 | ///There are several ways to access and modify the contents of this |
---|
| 220 | ///container. |
---|
| 221 | ///- Its it fully compatible with \c std::map<Col,double>, so for expamle |
---|
[1364] | 222 | ///if \c e is an Expr and \c v and \c w are of type \ref Col, then you can |
---|
[1279] | 223 | ///read and modify the coefficients like |
---|
| 224 | ///these. |
---|
| 225 | ///\code |
---|
| 226 | ///e[v]=5; |
---|
| 227 | ///e[v]+=12; |
---|
| 228 | ///e.erase(v); |
---|
| 229 | ///\endcode |
---|
| 230 | ///or you can also iterate through its elements. |
---|
| 231 | ///\code |
---|
| 232 | ///double s=0; |
---|
| 233 | ///for(LpSolverBase::Expr::iterator i=e.begin();i!=e.end();++i) |
---|
| 234 | /// s+=i->second; |
---|
| 235 | ///\endcode |
---|
| 236 | ///(This code computes the sum of all coefficients). |
---|
| 237 | ///- Numbers (<tt>double</tt>'s) |
---|
| 238 | ///and variables (\ref Col "Col"s) directly convert to an |
---|
[1908] | 239 | ///\ref Expr and the usual linear operations are defined, so |
---|
[1279] | 240 | ///\code |
---|
| 241 | ///v+w |
---|
| 242 | ///2*v-3.12*(v-w/2)+2 |
---|
| 243 | ///v*2.1+(3*v+(v*12+w+6)*3)/2 |
---|
| 244 | ///\endcode |
---|
[1328] | 245 | ///are valid \ref Expr "Expr"essions. |
---|
| 246 | ///The usual assignment operations are also defined. |
---|
[1279] | 247 | ///\code |
---|
| 248 | ///e=v+w; |
---|
| 249 | ///e+=2*v-3.12*(v-w/2)+2; |
---|
| 250 | ///e*=3.4; |
---|
| 251 | ///e/=5; |
---|
| 252 | ///\endcode |
---|
| 253 | ///- The constant member can be set and read by \ref constComp() |
---|
| 254 | ///\code |
---|
| 255 | ///e.constComp()=12; |
---|
| 256 | ///double c=e.constComp(); |
---|
| 257 | ///\endcode |
---|
| 258 | /// |
---|
[1328] | 259 | ///\note \ref clear() not only sets all coefficients to 0 but also |
---|
[1279] | 260 | ///clears the constant components. |
---|
[1328] | 261 | /// |
---|
| 262 | ///\sa Constr |
---|
| 263 | /// |
---|
[1273] | 264 | class Expr : public std::map<Col,Value> |
---|
[1272] | 265 | { |
---|
| 266 | public: |
---|
[1273] | 267 | typedef LpSolverBase::Col Key; |
---|
| 268 | typedef LpSolverBase::Value Value; |
---|
[1272] | 269 | |
---|
| 270 | protected: |
---|
[1273] | 271 | typedef std::map<Col,Value> Base; |
---|
[1272] | 272 | |
---|
[1273] | 273 | Value const_comp; |
---|
[1272] | 274 | public: |
---|
| 275 | typedef True IsLinExpression; |
---|
| 276 | ///\e |
---|
| 277 | Expr() : Base(), const_comp(0) { } |
---|
| 278 | ///\e |
---|
[1273] | 279 | Expr(const Key &v) : const_comp(0) { |
---|
[1272] | 280 | Base::insert(std::make_pair(v, 1)); |
---|
| 281 | } |
---|
| 282 | ///\e |
---|
[1273] | 283 | Expr(const Value &v) : const_comp(v) {} |
---|
[1272] | 284 | ///\e |
---|
[1273] | 285 | void set(const Key &v,const Value &c) { |
---|
[1272] | 286 | Base::insert(std::make_pair(v, c)); |
---|
| 287 | } |
---|
| 288 | ///\e |
---|
[1273] | 289 | Value &constComp() { return const_comp; } |
---|
[1272] | 290 | ///\e |
---|
[1273] | 291 | const Value &constComp() const { return const_comp; } |
---|
[1272] | 292 | |
---|
| 293 | ///Removes the components with zero coefficient. |
---|
| 294 | void simplify() { |
---|
| 295 | for (Base::iterator i=Base::begin(); i!=Base::end();) { |
---|
| 296 | Base::iterator j=i; |
---|
| 297 | ++j; |
---|
| 298 | if ((*i).second==0) Base::erase(i); |
---|
[2085] | 299 | i=j; |
---|
[1272] | 300 | } |
---|
| 301 | } |
---|
[1273] | 302 | |
---|
[1771] | 303 | ///Removes the coefficients closer to zero than \c tolerance. |
---|
| 304 | void simplify(double &tolerance) { |
---|
| 305 | for (Base::iterator i=Base::begin(); i!=Base::end();) { |
---|
| 306 | Base::iterator j=i; |
---|
| 307 | ++j; |
---|
| 308 | if (std::fabs((*i).second)<tolerance) Base::erase(i); |
---|
[2085] | 309 | i=j; |
---|
[1771] | 310 | } |
---|
| 311 | } |
---|
| 312 | |
---|
[1273] | 313 | ///Sets all coefficients and the constant component to 0. |
---|
| 314 | void clear() { |
---|
| 315 | Base::clear(); |
---|
| 316 | const_comp=0; |
---|
| 317 | } |
---|
| 318 | |
---|
[1272] | 319 | ///\e |
---|
| 320 | Expr &operator+=(const Expr &e) { |
---|
| 321 | for (Base::const_iterator j=e.begin(); j!=e.end(); ++j) |
---|
| 322 | (*this)[j->first]+=j->second; |
---|
| 323 | const_comp+=e.const_comp; |
---|
| 324 | return *this; |
---|
| 325 | } |
---|
| 326 | ///\e |
---|
| 327 | Expr &operator-=(const Expr &e) { |
---|
| 328 | for (Base::const_iterator j=e.begin(); j!=e.end(); ++j) |
---|
| 329 | (*this)[j->first]-=j->second; |
---|
| 330 | const_comp-=e.const_comp; |
---|
| 331 | return *this; |
---|
| 332 | } |
---|
| 333 | ///\e |
---|
[1273] | 334 | Expr &operator*=(const Value &c) { |
---|
[1272] | 335 | for (Base::iterator j=Base::begin(); j!=Base::end(); ++j) |
---|
| 336 | j->second*=c; |
---|
| 337 | const_comp*=c; |
---|
| 338 | return *this; |
---|
| 339 | } |
---|
| 340 | ///\e |
---|
[1273] | 341 | Expr &operator/=(const Value &c) { |
---|
[1272] | 342 | for (Base::iterator j=Base::begin(); j!=Base::end(); ++j) |
---|
| 343 | j->second/=c; |
---|
| 344 | const_comp/=c; |
---|
| 345 | return *this; |
---|
| 346 | } |
---|
| 347 | }; |
---|
| 348 | |
---|
[1264] | 349 | ///Linear constraint |
---|
[1328] | 350 | |
---|
[1364] | 351 | ///This data stucture represents a linear constraint in the LP. |
---|
| 352 | ///Basically it is a linear expression with a lower or an upper bound |
---|
| 353 | ///(or both). These parts of the constraint can be obtained by the member |
---|
| 354 | ///functions \ref expr(), \ref lowerBound() and \ref upperBound(), |
---|
| 355 | ///respectively. |
---|
| 356 | ///There are two ways to construct a constraint. |
---|
| 357 | ///- You can set the linear expression and the bounds directly |
---|
| 358 | /// by the functions above. |
---|
| 359 | ///- The operators <tt>\<=</tt>, <tt>==</tt> and <tt>\>=</tt> |
---|
| 360 | /// are defined between expressions, or even between constraints whenever |
---|
| 361 | /// it makes sense. Therefore if \c e and \c f are linear expressions and |
---|
| 362 | /// \c s and \c t are numbers, then the followings are valid expressions |
---|
| 363 | /// and thus they can be used directly e.g. in \ref addRow() whenever |
---|
| 364 | /// it makes sense. |
---|
[1908] | 365 | ///\code |
---|
[1364] | 366 | /// e<=s |
---|
| 367 | /// e<=f |
---|
[1908] | 368 | /// e==f |
---|
[1364] | 369 | /// s<=e<=t |
---|
| 370 | /// e>=t |
---|
[1908] | 371 | ///\endcode |
---|
[1364] | 372 | ///\warning The validity of a constraint is checked only at run time, so |
---|
| 373 | ///e.g. \ref addRow(<tt>x[1]\<=x[2]<=5</tt>) will compile, but will throw a |
---|
| 374 | ///\ref LogicError exception. |
---|
[1272] | 375 | class Constr |
---|
| 376 | { |
---|
| 377 | public: |
---|
| 378 | typedef LpSolverBase::Expr Expr; |
---|
[1273] | 379 | typedef Expr::Key Key; |
---|
| 380 | typedef Expr::Value Value; |
---|
[1272] | 381 | |
---|
[1364] | 382 | // static const Value INF; |
---|
| 383 | // static const Value NaN; |
---|
| 384 | |
---|
[1273] | 385 | protected: |
---|
| 386 | Expr _expr; |
---|
| 387 | Value _lb,_ub; |
---|
| 388 | public: |
---|
| 389 | ///\e |
---|
| 390 | Constr() : _expr(), _lb(NaN), _ub(NaN) {} |
---|
| 391 | ///\e |
---|
| 392 | Constr(Value lb,const Expr &e,Value ub) : |
---|
| 393 | _expr(e), _lb(lb), _ub(ub) {} |
---|
| 394 | ///\e |
---|
| 395 | Constr(const Expr &e,Value ub) : |
---|
| 396 | _expr(e), _lb(NaN), _ub(ub) {} |
---|
| 397 | ///\e |
---|
| 398 | Constr(Value lb,const Expr &e) : |
---|
| 399 | _expr(e), _lb(lb), _ub(NaN) {} |
---|
| 400 | ///\e |
---|
[1272] | 401 | Constr(const Expr &e) : |
---|
[1273] | 402 | _expr(e), _lb(NaN), _ub(NaN) {} |
---|
| 403 | ///\e |
---|
| 404 | void clear() |
---|
| 405 | { |
---|
| 406 | _expr.clear(); |
---|
| 407 | _lb=_ub=NaN; |
---|
| 408 | } |
---|
[1364] | 409 | |
---|
| 410 | ///Reference to the linear expression |
---|
[1273] | 411 | Expr &expr() { return _expr; } |
---|
[1364] | 412 | ///Cont reference to the linear expression |
---|
[1273] | 413 | const Expr &expr() const { return _expr; } |
---|
[1364] | 414 | ///Reference to the lower bound. |
---|
| 415 | |
---|
| 416 | ///\return |
---|
[1536] | 417 | ///- \ref INF "INF": the constraint is lower unbounded. |
---|
| 418 | ///- \ref NaN "NaN": lower bound has not been set. |
---|
[1364] | 419 | ///- finite number: the lower bound |
---|
[1273] | 420 | Value &lowerBound() { return _lb; } |
---|
[1364] | 421 | ///The const version of \ref lowerBound() |
---|
[1273] | 422 | const Value &lowerBound() const { return _lb; } |
---|
[1364] | 423 | ///Reference to the upper bound. |
---|
| 424 | |
---|
| 425 | ///\return |
---|
[1536] | 426 | ///- \ref INF "INF": the constraint is upper unbounded. |
---|
| 427 | ///- \ref NaN "NaN": upper bound has not been set. |
---|
[1364] | 428 | ///- finite number: the upper bound |
---|
[1273] | 429 | Value &upperBound() { return _ub; } |
---|
[1364] | 430 | ///The const version of \ref upperBound() |
---|
[1273] | 431 | const Value &upperBound() const { return _ub; } |
---|
[1364] | 432 | ///Is the constraint lower bounded? |
---|
[1295] | 433 | bool lowerBounded() const { |
---|
| 434 | using namespace std; |
---|
[1397] | 435 | return finite(_lb); |
---|
[1295] | 436 | } |
---|
[1364] | 437 | ///Is the constraint upper bounded? |
---|
[1295] | 438 | bool upperBounded() const { |
---|
| 439 | using namespace std; |
---|
[1397] | 440 | return finite(_ub); |
---|
[1295] | 441 | } |
---|
[1272] | 442 | }; |
---|
| 443 | |
---|
[1445] | 444 | ///Linear expression of rows |
---|
| 445 | |
---|
| 446 | ///This data structure represents a column of the matrix, |
---|
| 447 | ///thas is it strores a linear expression of the dual variables |
---|
| 448 | ///(\ref Row "Row"s). |
---|
| 449 | /// |
---|
| 450 | ///There are several ways to access and modify the contents of this |
---|
| 451 | ///container. |
---|
| 452 | ///- Its it fully compatible with \c std::map<Row,double>, so for expamle |
---|
| 453 | ///if \c e is an DualExpr and \c v |
---|
| 454 | ///and \c w are of type \ref Row, then you can |
---|
| 455 | ///read and modify the coefficients like |
---|
| 456 | ///these. |
---|
| 457 | ///\code |
---|
| 458 | ///e[v]=5; |
---|
| 459 | ///e[v]+=12; |
---|
| 460 | ///e.erase(v); |
---|
| 461 | ///\endcode |
---|
| 462 | ///or you can also iterate through its elements. |
---|
| 463 | ///\code |
---|
| 464 | ///double s=0; |
---|
| 465 | ///for(LpSolverBase::DualExpr::iterator i=e.begin();i!=e.end();++i) |
---|
| 466 | /// s+=i->second; |
---|
| 467 | ///\endcode |
---|
| 468 | ///(This code computes the sum of all coefficients). |
---|
| 469 | ///- Numbers (<tt>double</tt>'s) |
---|
| 470 | ///and variables (\ref Row "Row"s) directly convert to an |
---|
[1908] | 471 | ///\ref DualExpr and the usual linear operations are defined, so |
---|
[1445] | 472 | ///\code |
---|
| 473 | ///v+w |
---|
| 474 | ///2*v-3.12*(v-w/2) |
---|
| 475 | ///v*2.1+(3*v+(v*12+w)*3)/2 |
---|
| 476 | ///\endcode |
---|
| 477 | ///are valid \ref DualExpr "DualExpr"essions. |
---|
| 478 | ///The usual assignment operations are also defined. |
---|
| 479 | ///\code |
---|
| 480 | ///e=v+w; |
---|
| 481 | ///e+=2*v-3.12*(v-w/2); |
---|
| 482 | ///e*=3.4; |
---|
| 483 | ///e/=5; |
---|
| 484 | ///\endcode |
---|
| 485 | /// |
---|
| 486 | ///\sa Expr |
---|
| 487 | /// |
---|
| 488 | class DualExpr : public std::map<Row,Value> |
---|
| 489 | { |
---|
| 490 | public: |
---|
| 491 | typedef LpSolverBase::Row Key; |
---|
| 492 | typedef LpSolverBase::Value Value; |
---|
| 493 | |
---|
| 494 | protected: |
---|
| 495 | typedef std::map<Row,Value> Base; |
---|
| 496 | |
---|
| 497 | public: |
---|
| 498 | typedef True IsLinExpression; |
---|
| 499 | ///\e |
---|
| 500 | DualExpr() : Base() { } |
---|
| 501 | ///\e |
---|
| 502 | DualExpr(const Key &v) { |
---|
| 503 | Base::insert(std::make_pair(v, 1)); |
---|
| 504 | } |
---|
| 505 | ///\e |
---|
| 506 | void set(const Key &v,const Value &c) { |
---|
| 507 | Base::insert(std::make_pair(v, c)); |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | ///Removes the components with zero coefficient. |
---|
| 511 | void simplify() { |
---|
| 512 | for (Base::iterator i=Base::begin(); i!=Base::end();) { |
---|
| 513 | Base::iterator j=i; |
---|
| 514 | ++j; |
---|
| 515 | if ((*i).second==0) Base::erase(i); |
---|
[2085] | 516 | i=j; |
---|
[1445] | 517 | } |
---|
| 518 | } |
---|
| 519 | |
---|
[1771] | 520 | ///Removes the coefficients closer to zero than \c tolerance. |
---|
| 521 | void simplify(double &tolerance) { |
---|
| 522 | for (Base::iterator i=Base::begin(); i!=Base::end();) { |
---|
| 523 | Base::iterator j=i; |
---|
| 524 | ++j; |
---|
| 525 | if (std::fabs((*i).second)<tolerance) Base::erase(i); |
---|
[2085] | 526 | i=j; |
---|
[1771] | 527 | } |
---|
| 528 | } |
---|
| 529 | |
---|
| 530 | |
---|
[1445] | 531 | ///Sets all coefficients to 0. |
---|
| 532 | void clear() { |
---|
| 533 | Base::clear(); |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | ///\e |
---|
| 537 | DualExpr &operator+=(const DualExpr &e) { |
---|
| 538 | for (Base::const_iterator j=e.begin(); j!=e.end(); ++j) |
---|
| 539 | (*this)[j->first]+=j->second; |
---|
| 540 | return *this; |
---|
| 541 | } |
---|
| 542 | ///\e |
---|
| 543 | DualExpr &operator-=(const DualExpr &e) { |
---|
| 544 | for (Base::const_iterator j=e.begin(); j!=e.end(); ++j) |
---|
| 545 | (*this)[j->first]-=j->second; |
---|
| 546 | return *this; |
---|
| 547 | } |
---|
| 548 | ///\e |
---|
| 549 | DualExpr &operator*=(const Value &c) { |
---|
| 550 | for (Base::iterator j=Base::begin(); j!=Base::end(); ++j) |
---|
| 551 | j->second*=c; |
---|
| 552 | return *this; |
---|
| 553 | } |
---|
| 554 | ///\e |
---|
| 555 | DualExpr &operator/=(const Value &c) { |
---|
| 556 | for (Base::iterator j=Base::begin(); j!=Base::end(); ++j) |
---|
| 557 | j->second/=c; |
---|
| 558 | return *this; |
---|
| 559 | } |
---|
| 560 | }; |
---|
| 561 | |
---|
[1253] | 562 | |
---|
| 563 | protected: |
---|
| 564 | _FixId rows; |
---|
| 565 | _FixId cols; |
---|
[1246] | 566 | |
---|
[1323] | 567 | //Abstract virtual functions |
---|
[1364] | 568 | virtual LpSolverBase &_newLp() = 0; |
---|
[1436] | 569 | virtual LpSolverBase &_copyLp(){ |
---|
| 570 | ///\todo This should be implemented here, too, when we have problem retrieving routines. It can be overriden. |
---|
| 571 | |
---|
| 572 | //Starting: |
---|
| 573 | LpSolverBase & newlp(_newLp()); |
---|
| 574 | return newlp; |
---|
| 575 | //return *(LpSolverBase*)0; |
---|
| 576 | }; |
---|
[1364] | 577 | |
---|
[1246] | 578 | virtual int _addCol() = 0; |
---|
| 579 | virtual int _addRow() = 0; |
---|
[1542] | 580 | virtual void _eraseCol(int col) = 0; |
---|
| 581 | virtual void _eraseRow(int row) = 0; |
---|
[1895] | 582 | virtual void _getColName(int col, std::string & name) = 0; |
---|
| 583 | virtual void _setColName(int col, const std::string & name) = 0; |
---|
[1246] | 584 | virtual void _setRowCoeffs(int i, |
---|
[1251] | 585 | int length, |
---|
[1247] | 586 | int const * indices, |
---|
| 587 | Value const * values ) = 0; |
---|
[1246] | 588 | virtual void _setColCoeffs(int i, |
---|
[1251] | 589 | int length, |
---|
[1247] | 590 | int const * indices, |
---|
| 591 | Value const * values ) = 0; |
---|
[1431] | 592 | virtual void _setCoeff(int row, int col, Value value) = 0; |
---|
[1294] | 593 | virtual void _setColLowerBound(int i, Value value) = 0; |
---|
| 594 | virtual void _setColUpperBound(int i, Value value) = 0; |
---|
[1405] | 595 | // virtual void _setRowLowerBound(int i, Value value) = 0; |
---|
| 596 | // virtual void _setRowUpperBound(int i, Value value) = 0; |
---|
[1379] | 597 | virtual void _setRowBounds(int i, Value lower, Value upper) = 0; |
---|
[1294] | 598 | virtual void _setObjCoeff(int i, Value obj_coef) = 0; |
---|
[1377] | 599 | virtual void _clearObj()=0; |
---|
| 600 | // virtual void _setObj(int length, |
---|
| 601 | // int const * indices, |
---|
| 602 | // Value const * values ) = 0; |
---|
[1303] | 603 | virtual SolveExitStatus _solve() = 0; |
---|
[1294] | 604 | virtual Value _getPrimal(int i) = 0; |
---|
[1787] | 605 | virtual Value _getDual(int i) = 0; |
---|
[1312] | 606 | virtual Value _getPrimalValue() = 0; |
---|
[1840] | 607 | virtual bool _isBasicCol(int i) = 0; |
---|
[1312] | 608 | virtual SolutionStatus _getPrimalStatus() = 0; |
---|
[1460] | 609 | virtual SolutionStatus _getDualStatus() = 0; |
---|
| 610 | ///\todo This could be implemented here, too, using _getPrimalStatus() and |
---|
| 611 | ///_getDualStatus() |
---|
| 612 | virtual ProblemTypes _getProblemType() = 0; |
---|
| 613 | |
---|
[1312] | 614 | virtual void _setMax() = 0; |
---|
| 615 | virtual void _setMin() = 0; |
---|
| 616 | |
---|
[1323] | 617 | //Own protected stuff |
---|
| 618 | |
---|
| 619 | //Constant component of the objective function |
---|
| 620 | Value obj_const_comp; |
---|
| 621 | |
---|
[1377] | 622 | |
---|
| 623 | |
---|
[1323] | 624 | |
---|
[1253] | 625 | public: |
---|
| 626 | |
---|
[1323] | 627 | ///\e |
---|
| 628 | LpSolverBase() : obj_const_comp(0) {} |
---|
[1253] | 629 | |
---|
| 630 | ///\e |
---|
| 631 | virtual ~LpSolverBase() {} |
---|
| 632 | |
---|
[1364] | 633 | ///Creates a new LP problem |
---|
| 634 | LpSolverBase &newLp() {return _newLp();} |
---|
[1381] | 635 | ///Makes a copy of the LP problem |
---|
[1364] | 636 | LpSolverBase ©Lp() {return _copyLp();} |
---|
| 637 | |
---|
[1612] | 638 | ///\name Build up and modify the LP |
---|
[1263] | 639 | |
---|
| 640 | ///@{ |
---|
| 641 | |
---|
[1253] | 642 | ///Add a new empty column (i.e a new variable) to the LP |
---|
| 643 | Col addCol() { Col c; c.id=cols.insert(_addCol()); return c;} |
---|
[1263] | 644 | |
---|
[1294] | 645 | ///\brief Adds several new columns |
---|
| 646 | ///(i.e a variables) at once |
---|
[1256] | 647 | /// |
---|
[1273] | 648 | ///This magic function takes a container as its argument |
---|
[1256] | 649 | ///and fills its elements |
---|
| 650 | ///with new columns (i.e. variables) |
---|
[1273] | 651 | ///\param t can be |
---|
| 652 | ///- a standard STL compatible iterable container with |
---|
| 653 | ///\ref Col as its \c values_type |
---|
| 654 | ///like |
---|
| 655 | ///\code |
---|
| 656 | ///std::vector<LpSolverBase::Col> |
---|
| 657 | ///std::list<LpSolverBase::Col> |
---|
| 658 | ///\endcode |
---|
| 659 | ///- a standard STL compatible iterable container with |
---|
| 660 | ///\ref Col as its \c mapped_type |
---|
| 661 | ///like |
---|
| 662 | ///\code |
---|
[1364] | 663 | ///std::map<AnyType,LpSolverBase::Col> |
---|
[1273] | 664 | ///\endcode |
---|
| 665 | ///- an iterable lemon \ref concept::WriteMap "write map" like |
---|
| 666 | ///\code |
---|
| 667 | ///ListGraph::NodeMap<LpSolverBase::Col> |
---|
| 668 | ///ListGraph::EdgeMap<LpSolverBase::Col> |
---|
| 669 | ///\endcode |
---|
[1256] | 670 | ///\return The number of the created column. |
---|
| 671 | #ifdef DOXYGEN |
---|
| 672 | template<class T> |
---|
| 673 | int addColSet(T &t) { return 0;} |
---|
| 674 | #else |
---|
| 675 | template<class T> |
---|
| 676 | typename enable_if<typename T::value_type::LpSolverCol,int>::type |
---|
| 677 | addColSet(T &t,dummy<0> = 0) { |
---|
| 678 | int s=0; |
---|
| 679 | for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addCol();s++;} |
---|
| 680 | return s; |
---|
| 681 | } |
---|
| 682 | template<class T> |
---|
| 683 | typename enable_if<typename T::value_type::second_type::LpSolverCol, |
---|
| 684 | int>::type |
---|
| 685 | addColSet(T &t,dummy<1> = 1) { |
---|
| 686 | int s=0; |
---|
| 687 | for(typename T::iterator i=t.begin();i!=t.end();++i) { |
---|
| 688 | i->second=addCol(); |
---|
| 689 | s++; |
---|
| 690 | } |
---|
| 691 | return s; |
---|
| 692 | } |
---|
[1272] | 693 | template<class T> |
---|
[1810] | 694 | typename enable_if<typename T::MapIt::Value::LpSolverCol, |
---|
[1272] | 695 | int>::type |
---|
| 696 | addColSet(T &t,dummy<2> = 2) { |
---|
| 697 | int s=0; |
---|
[1810] | 698 | for(typename T::MapIt i(t); i!=INVALID; ++i) |
---|
[1272] | 699 | { |
---|
[1810] | 700 | i.set(addCol()); |
---|
[1272] | 701 | s++; |
---|
| 702 | } |
---|
| 703 | return s; |
---|
| 704 | } |
---|
[1256] | 705 | #endif |
---|
[1263] | 706 | |
---|
[1445] | 707 | ///Set a column (i.e a dual constraint) of the LP |
---|
[1258] | 708 | |
---|
[1445] | 709 | ///\param c is the column to be modified |
---|
| 710 | ///\param e is a dual linear expression (see \ref DualExpr) |
---|
| 711 | ///a better one. |
---|
[1899] | 712 | void col(Col c,const DualExpr &e) { |
---|
[1445] | 713 | std::vector<int> indices; |
---|
| 714 | std::vector<Value> values; |
---|
| 715 | indices.push_back(0); |
---|
| 716 | values.push_back(0); |
---|
| 717 | for(DualExpr::const_iterator i=e.begin(); i!=e.end(); ++i) |
---|
[1899] | 718 | if((*i).second!=0) { |
---|
[1787] | 719 | indices.push_back(rows.floatingId((*i).first.id)); |
---|
[1445] | 720 | values.push_back((*i).second); |
---|
| 721 | } |
---|
| 722 | _setColCoeffs(cols.floatingId(c.id),indices.size()-1, |
---|
| 723 | &indices[0],&values[0]); |
---|
| 724 | } |
---|
| 725 | |
---|
| 726 | ///Add a new column to the LP |
---|
| 727 | |
---|
| 728 | ///\param e is a dual linear expression (see \ref DualExpr) |
---|
| 729 | ///\param obj is the corresponding component of the objective |
---|
| 730 | ///function. It is 0 by default. |
---|
| 731 | ///\return The created column. |
---|
[1493] | 732 | Col addCol(const DualExpr &e, Value obj=0) { |
---|
[1445] | 733 | Col c=addCol(); |
---|
[1899] | 734 | col(c,e); |
---|
[1493] | 735 | objCoeff(c,obj); |
---|
[1445] | 736 | return c; |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | ///Add a new empty row (i.e a new constraint) to the LP |
---|
| 740 | |
---|
| 741 | ///This function adds a new empty row (i.e a new constraint) to the LP. |
---|
[1258] | 742 | ///\return The created row |
---|
[1253] | 743 | Row addRow() { Row r; r.id=rows.insert(_addRow()); return r;} |
---|
| 744 | |
---|
[1542] | 745 | ///\brief Add several new rows |
---|
| 746 | ///(i.e a constraints) at once |
---|
[1445] | 747 | /// |
---|
| 748 | ///This magic function takes a container as its argument |
---|
| 749 | ///and fills its elements |
---|
| 750 | ///with new row (i.e. variables) |
---|
| 751 | ///\param t can be |
---|
| 752 | ///- a standard STL compatible iterable container with |
---|
| 753 | ///\ref Row as its \c values_type |
---|
| 754 | ///like |
---|
| 755 | ///\code |
---|
| 756 | ///std::vector<LpSolverBase::Row> |
---|
| 757 | ///std::list<LpSolverBase::Row> |
---|
| 758 | ///\endcode |
---|
| 759 | ///- a standard STL compatible iterable container with |
---|
| 760 | ///\ref Row as its \c mapped_type |
---|
| 761 | ///like |
---|
| 762 | ///\code |
---|
| 763 | ///std::map<AnyType,LpSolverBase::Row> |
---|
| 764 | ///\endcode |
---|
| 765 | ///- an iterable lemon \ref concept::WriteMap "write map" like |
---|
| 766 | ///\code |
---|
| 767 | ///ListGraph::NodeMap<LpSolverBase::Row> |
---|
| 768 | ///ListGraph::EdgeMap<LpSolverBase::Row> |
---|
| 769 | ///\endcode |
---|
| 770 | ///\return The number of rows created. |
---|
| 771 | #ifdef DOXYGEN |
---|
| 772 | template<class T> |
---|
| 773 | int addRowSet(T &t) { return 0;} |
---|
| 774 | #else |
---|
| 775 | template<class T> |
---|
| 776 | typename enable_if<typename T::value_type::LpSolverRow,int>::type |
---|
| 777 | addRowSet(T &t,dummy<0> = 0) { |
---|
| 778 | int s=0; |
---|
| 779 | for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addRow();s++;} |
---|
| 780 | return s; |
---|
| 781 | } |
---|
| 782 | template<class T> |
---|
| 783 | typename enable_if<typename T::value_type::second_type::LpSolverRow, |
---|
| 784 | int>::type |
---|
| 785 | addRowSet(T &t,dummy<1> = 1) { |
---|
| 786 | int s=0; |
---|
| 787 | for(typename T::iterator i=t.begin();i!=t.end();++i) { |
---|
| 788 | i->second=addRow(); |
---|
| 789 | s++; |
---|
| 790 | } |
---|
| 791 | return s; |
---|
| 792 | } |
---|
| 793 | template<class T> |
---|
[1810] | 794 | typename enable_if<typename T::MapIt::Value::LpSolverRow, |
---|
[1445] | 795 | int>::type |
---|
| 796 | addRowSet(T &t,dummy<2> = 2) { |
---|
| 797 | int s=0; |
---|
[1810] | 798 | for(typename T::MapIt i(t); i!=INVALID; ++i) |
---|
[1445] | 799 | { |
---|
[1810] | 800 | i.set(addRow()); |
---|
[1445] | 801 | s++; |
---|
| 802 | } |
---|
| 803 | return s; |
---|
| 804 | } |
---|
| 805 | #endif |
---|
| 806 | |
---|
| 807 | ///Set a row (i.e a constraint) of the LP |
---|
[1253] | 808 | |
---|
[1258] | 809 | ///\param r is the row to be modified |
---|
[1259] | 810 | ///\param l is lower bound (-\ref INF means no bound) |
---|
[1258] | 811 | ///\param e is a linear expression (see \ref Expr) |
---|
[1259] | 812 | ///\param u is the upper bound (\ref INF means no bound) |
---|
[1253] | 813 | ///\bug This is a temportary function. The interface will change to |
---|
| 814 | ///a better one. |
---|
[1328] | 815 | ///\todo Option to control whether a constraint with a single variable is |
---|
| 816 | ///added or not. |
---|
[1895] | 817 | void row(Row r, Value l,const Expr &e, Value u) { |
---|
[1253] | 818 | std::vector<int> indices; |
---|
| 819 | std::vector<Value> values; |
---|
| 820 | indices.push_back(0); |
---|
| 821 | values.push_back(0); |
---|
[1258] | 822 | for(Expr::const_iterator i=e.begin(); i!=e.end(); ++i) |
---|
[1256] | 823 | if((*i).second!=0) { ///\bug EPSILON would be necessary here!!! |
---|
| 824 | indices.push_back(cols.floatingId((*i).first.id)); |
---|
| 825 | values.push_back((*i).second); |
---|
| 826 | } |
---|
[1253] | 827 | _setRowCoeffs(rows.floatingId(r.id),indices.size()-1, |
---|
| 828 | &indices[0],&values[0]); |
---|
[1405] | 829 | // _setRowLowerBound(rows.floatingId(r.id),l-e.constComp()); |
---|
| 830 | // _setRowUpperBound(rows.floatingId(r.id),u-e.constComp()); |
---|
| 831 | _setRowBounds(rows.floatingId(r.id),l-e.constComp(),u-e.constComp()); |
---|
[1258] | 832 | } |
---|
| 833 | |
---|
[1445] | 834 | ///Set a row (i.e a constraint) of the LP |
---|
[1264] | 835 | |
---|
| 836 | ///\param r is the row to be modified |
---|
| 837 | ///\param c is a linear expression (see \ref Constr) |
---|
[1895] | 838 | void row(Row r, const Constr &c) { |
---|
| 839 | row(r, |
---|
[1275] | 840 | c.lowerBounded()?c.lowerBound():-INF, |
---|
[1273] | 841 | c.expr(), |
---|
[1275] | 842 | c.upperBounded()?c.upperBound():INF); |
---|
[1264] | 843 | } |
---|
| 844 | |
---|
[1445] | 845 | ///Add a new row (i.e a new constraint) to the LP |
---|
[1258] | 846 | |
---|
[1259] | 847 | ///\param l is the lower bound (-\ref INF means no bound) |
---|
[1258] | 848 | ///\param e is a linear expression (see \ref Expr) |
---|
[1259] | 849 | ///\param u is the upper bound (\ref INF means no bound) |
---|
[1258] | 850 | ///\return The created row. |
---|
| 851 | ///\bug This is a temportary function. The interface will change to |
---|
| 852 | ///a better one. |
---|
| 853 | Row addRow(Value l,const Expr &e, Value u) { |
---|
| 854 | Row r=addRow(); |
---|
[1895] | 855 | row(r,l,e,u); |
---|
[1253] | 856 | return r; |
---|
| 857 | } |
---|
| 858 | |
---|
[1445] | 859 | ///Add a new row (i.e a new constraint) to the LP |
---|
[1264] | 860 | |
---|
| 861 | ///\param c is a linear expression (see \ref Constr) |
---|
| 862 | ///\return The created row. |
---|
| 863 | Row addRow(const Constr &c) { |
---|
| 864 | Row r=addRow(); |
---|
[1895] | 865 | row(r,c); |
---|
[1264] | 866 | return r; |
---|
| 867 | } |
---|
[1542] | 868 | ///Erase a coloumn (i.e a variable) from the LP |
---|
| 869 | |
---|
| 870 | ///\param c is the coloumn to be deleted |
---|
| 871 | ///\todo Please check this |
---|
| 872 | void eraseCol(Col c) { |
---|
| 873 | _eraseCol(cols.floatingId(c.id)); |
---|
| 874 | cols.erase(c.id); |
---|
| 875 | } |
---|
| 876 | ///Erase a row (i.e a constraint) from the LP |
---|
| 877 | |
---|
| 878 | ///\param r is the row to be deleted |
---|
| 879 | ///\todo Please check this |
---|
| 880 | void eraseRow(Row r) { |
---|
| 881 | _eraseRow(rows.floatingId(r.id)); |
---|
| 882 | rows.erase(r.id); |
---|
| 883 | } |
---|
[1264] | 884 | |
---|
[1895] | 885 | /// Get the name of a column |
---|
| 886 | |
---|
| 887 | ///\param c is the coresponding coloumn |
---|
| 888 | ///\return The name of the colunm |
---|
| 889 | std::string ColName(Col c){ |
---|
| 890 | std::string name; |
---|
| 891 | _getColName(cols.floatingId(c.id), name); |
---|
| 892 | return name; |
---|
| 893 | } |
---|
| 894 | |
---|
| 895 | /// Set the name of a column |
---|
| 896 | |
---|
| 897 | ///\param c is the coresponding coloumn |
---|
| 898 | ///\param name The name to be given |
---|
| 899 | void ColName(Col c, const std::string & name){ |
---|
| 900 | _setColName(cols.floatingId(c.id), name); |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | /// Set an element of the coefficient matrix of the LP |
---|
[1436] | 904 | |
---|
| 905 | ///\param r is the row of the element to be modified |
---|
| 906 | ///\param c is the coloumn of the element to be modified |
---|
| 907 | ///\param val is the new value of the coefficient |
---|
[1895] | 908 | |
---|
| 909 | void Coeff(Row r, Col c, Value val){ |
---|
[1436] | 910 | _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val); |
---|
| 911 | } |
---|
| 912 | |
---|
[1253] | 913 | /// Set the lower bound of a column (i.e a variable) |
---|
| 914 | |
---|
[1895] | 915 | /// The lower bound of a variable (column) has to be given by an |
---|
[1253] | 916 | /// extended number of type Value, i.e. a finite number of type |
---|
[1259] | 917 | /// Value or -\ref INF. |
---|
[1293] | 918 | void colLowerBound(Col c, Value value) { |
---|
[1253] | 919 | _setColLowerBound(cols.floatingId(c.id),value); |
---|
| 920 | } |
---|
[1895] | 921 | |
---|
| 922 | ///\brief Set the lower bound of several columns |
---|
| 923 | ///(i.e a variables) at once |
---|
| 924 | /// |
---|
| 925 | ///This magic function takes a container as its argument |
---|
| 926 | ///and applies the function on all of its elements. |
---|
| 927 | /// The lower bound of a variable (column) has to be given by an |
---|
| 928 | /// extended number of type Value, i.e. a finite number of type |
---|
| 929 | /// Value or -\ref INF. |
---|
| 930 | #ifdef DOXYGEN |
---|
| 931 | template<class T> |
---|
| 932 | void colLowerBound(T &t, Value value) { return 0;} |
---|
| 933 | #else |
---|
| 934 | template<class T> |
---|
| 935 | typename enable_if<typename T::value_type::LpSolverCol,void>::type |
---|
| 936 | colLowerBound(T &t, Value value,dummy<0> = 0) { |
---|
| 937 | for(typename T::iterator i=t.begin();i!=t.end();++i) { |
---|
| 938 | colLowerBound(*i, value); |
---|
| 939 | } |
---|
| 940 | } |
---|
| 941 | template<class T> |
---|
| 942 | typename enable_if<typename T::value_type::second_type::LpSolverCol, |
---|
| 943 | void>::type |
---|
| 944 | colLowerBound(T &t, Value value,dummy<1> = 1) { |
---|
| 945 | for(typename T::iterator i=t.begin();i!=t.end();++i) { |
---|
| 946 | colLowerBound(i->second, value); |
---|
| 947 | } |
---|
| 948 | } |
---|
| 949 | template<class T> |
---|
| 950 | typename enable_if<typename T::MapIt::Value::LpSolverCol, |
---|
| 951 | void>::type |
---|
| 952 | colLowerBound(T &t, Value value,dummy<2> = 2) { |
---|
| 953 | for(typename T::MapIt i(t); i!=INVALID; ++i){ |
---|
| 954 | colLowerBound(*i, value); |
---|
| 955 | } |
---|
| 956 | } |
---|
| 957 | #endif |
---|
| 958 | |
---|
[1253] | 959 | /// Set the upper bound of a column (i.e a variable) |
---|
| 960 | |
---|
[1293] | 961 | /// The upper bound of a variable (column) has to be given by an |
---|
[1253] | 962 | /// extended number of type Value, i.e. a finite number of type |
---|
[1259] | 963 | /// Value or \ref INF. |
---|
[1293] | 964 | void colUpperBound(Col c, Value value) { |
---|
[1253] | 965 | _setColUpperBound(cols.floatingId(c.id),value); |
---|
| 966 | }; |
---|
[1895] | 967 | |
---|
| 968 | ///\brief Set the lower bound of several columns |
---|
| 969 | ///(i.e a variables) at once |
---|
| 970 | /// |
---|
| 971 | ///This magic function takes a container as its argument |
---|
| 972 | ///and applies the function on all of its elements. |
---|
| 973 | /// The upper bound of a variable (column) has to be given by an |
---|
| 974 | /// extended number of type Value, i.e. a finite number of type |
---|
| 975 | /// Value or \ref INF. |
---|
| 976 | #ifdef DOXYGEN |
---|
| 977 | template<class T> |
---|
| 978 | void colUpperBound(T &t, Value value) { return 0;} |
---|
| 979 | #else |
---|
| 980 | template<class T> |
---|
| 981 | typename enable_if<typename T::value_type::LpSolverCol,void>::type |
---|
| 982 | colUpperBound(T &t, Value value,dummy<0> = 0) { |
---|
| 983 | for(typename T::iterator i=t.begin();i!=t.end();++i) { |
---|
| 984 | colUpperBound(*i, value); |
---|
| 985 | } |
---|
| 986 | } |
---|
| 987 | template<class T> |
---|
| 988 | typename enable_if<typename T::value_type::second_type::LpSolverCol, |
---|
| 989 | void>::type |
---|
| 990 | colUpperBound(T &t, Value value,dummy<1> = 1) { |
---|
| 991 | for(typename T::iterator i=t.begin();i!=t.end();++i) { |
---|
| 992 | colUpperBound(i->second, value); |
---|
| 993 | } |
---|
| 994 | } |
---|
| 995 | template<class T> |
---|
| 996 | typename enable_if<typename T::MapIt::Value::LpSolverCol, |
---|
| 997 | void>::type |
---|
| 998 | colUpperBound(T &t, Value value,dummy<2> = 2) { |
---|
| 999 | for(typename T::MapIt i(t); i!=INVALID; ++i){ |
---|
| 1000 | colUpperBound(*i, value); |
---|
| 1001 | } |
---|
| 1002 | } |
---|
| 1003 | #endif |
---|
| 1004 | |
---|
[1293] | 1005 | /// Set the lower and the upper bounds of a column (i.e a variable) |
---|
| 1006 | |
---|
| 1007 | /// The lower and the upper bounds of |
---|
| 1008 | /// a variable (column) have to be given by an |
---|
| 1009 | /// extended number of type Value, i.e. a finite number of type |
---|
| 1010 | /// Value, -\ref INF or \ref INF. |
---|
| 1011 | void colBounds(Col c, Value lower, Value upper) { |
---|
| 1012 | _setColLowerBound(cols.floatingId(c.id),lower); |
---|
| 1013 | _setColUpperBound(cols.floatingId(c.id),upper); |
---|
| 1014 | } |
---|
| 1015 | |
---|
[1895] | 1016 | ///\brief Set the lower and the upper bound of several columns |
---|
| 1017 | ///(i.e a variables) at once |
---|
| 1018 | /// |
---|
| 1019 | ///This magic function takes a container as its argument |
---|
| 1020 | ///and applies the function on all of its elements. |
---|
| 1021 | /// The lower and the upper bounds of |
---|
| 1022 | /// a variable (column) have to be given by an |
---|
| 1023 | /// extended number of type Value, i.e. a finite number of type |
---|
| 1024 | /// Value, -\ref INF or \ref INF. |
---|
| 1025 | #ifdef DOXYGEN |
---|
| 1026 | template<class T> |
---|
| 1027 | void colBounds(T &t, Value lower, Value upper) { return 0;} |
---|
| 1028 | #else |
---|
| 1029 | template<class T> |
---|
| 1030 | typename enable_if<typename T::value_type::LpSolverCol,void>::type |
---|
| 1031 | colBounds(T &t, Value lower, Value upper,dummy<0> = 0) { |
---|
| 1032 | for(typename T::iterator i=t.begin();i!=t.end();++i) { |
---|
| 1033 | colBounds(*i, lower, upper); |
---|
| 1034 | } |
---|
| 1035 | } |
---|
| 1036 | template<class T> |
---|
| 1037 | typename enable_if<typename T::value_type::second_type::LpSolverCol, |
---|
| 1038 | void>::type |
---|
| 1039 | colBounds(T &t, Value lower, Value upper,dummy<1> = 1) { |
---|
| 1040 | for(typename T::iterator i=t.begin();i!=t.end();++i) { |
---|
| 1041 | colBounds(i->second, lower, upper); |
---|
| 1042 | } |
---|
| 1043 | } |
---|
| 1044 | template<class T> |
---|
| 1045 | typename enable_if<typename T::MapIt::Value::LpSolverCol, |
---|
| 1046 | void>::type |
---|
| 1047 | colBounds(T &t, Value lower, Value upper,dummy<2> = 2) { |
---|
| 1048 | for(typename T::MapIt i(t); i!=INVALID; ++i){ |
---|
| 1049 | colBounds(*i, lower, upper); |
---|
| 1050 | } |
---|
| 1051 | } |
---|
| 1052 | #endif |
---|
| 1053 | |
---|
[1405] | 1054 | // /// Set the lower bound of a row (i.e a constraint) |
---|
[1253] | 1055 | |
---|
[1405] | 1056 | // /// The lower bound of a linear expression (row) has to be given by an |
---|
| 1057 | // /// extended number of type Value, i.e. a finite number of type |
---|
| 1058 | // /// Value or -\ref INF. |
---|
| 1059 | // void rowLowerBound(Row r, Value value) { |
---|
| 1060 | // _setRowLowerBound(rows.floatingId(r.id),value); |
---|
| 1061 | // }; |
---|
| 1062 | // /// Set the upper bound of a row (i.e a constraint) |
---|
[1253] | 1063 | |
---|
[1405] | 1064 | // /// The upper bound of a linear expression (row) has to be given by an |
---|
| 1065 | // /// extended number of type Value, i.e. a finite number of type |
---|
| 1066 | // /// Value or \ref INF. |
---|
| 1067 | // void rowUpperBound(Row r, Value value) { |
---|
| 1068 | // _setRowUpperBound(rows.floatingId(r.id),value); |
---|
| 1069 | // }; |
---|
| 1070 | |
---|
| 1071 | /// Set the lower and the upper bounds of a row (i.e a constraint) |
---|
[1293] | 1072 | |
---|
| 1073 | /// The lower and the upper bounds of |
---|
| 1074 | /// a constraint (row) have to be given by an |
---|
| 1075 | /// extended number of type Value, i.e. a finite number of type |
---|
| 1076 | /// Value, -\ref INF or \ref INF. |
---|
| 1077 | void rowBounds(Row c, Value lower, Value upper) { |
---|
[1379] | 1078 | _setRowBounds(rows.floatingId(c.id),lower, upper); |
---|
| 1079 | // _setRowUpperBound(rows.floatingId(c.id),upper); |
---|
[1293] | 1080 | } |
---|
| 1081 | |
---|
[1253] | 1082 | ///Set an element of the objective function |
---|
[1293] | 1083 | void objCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); }; |
---|
[1253] | 1084 | ///Set the objective function |
---|
| 1085 | |
---|
| 1086 | ///\param e is a linear expression of type \ref Expr. |
---|
[1895] | 1087 | ///\bug Is should be called obj() |
---|
[1253] | 1088 | void setObj(Expr e) { |
---|
[1377] | 1089 | _clearObj(); |
---|
[1253] | 1090 | for (Expr::iterator i=e.begin(); i!=e.end(); ++i) |
---|
[1293] | 1091 | objCoeff((*i).first,(*i).second); |
---|
[1323] | 1092 | obj_const_comp=e.constComp(); |
---|
[1253] | 1093 | } |
---|
[1263] | 1094 | |
---|
[1312] | 1095 | ///Maximize |
---|
| 1096 | void max() { _setMax(); } |
---|
| 1097 | ///Minimize |
---|
| 1098 | void min() { _setMin(); } |
---|
| 1099 | |
---|
| 1100 | |
---|
[1263] | 1101 | ///@} |
---|
| 1102 | |
---|
| 1103 | |
---|
[1294] | 1104 | ///\name Solve the LP |
---|
[1263] | 1105 | |
---|
| 1106 | ///@{ |
---|
| 1107 | |
---|
[1458] | 1108 | ///\e Solve the LP problem at hand |
---|
| 1109 | /// |
---|
[2026] | 1110 | ///\return The result of the optimization procedure. Possible |
---|
| 1111 | ///values and their meanings can be found in the documentation of |
---|
| 1112 | ///\ref SolveExitStatus. |
---|
[1458] | 1113 | /// |
---|
| 1114 | ///\todo Which method is used to solve the problem |
---|
[1303] | 1115 | SolveExitStatus solve() { return _solve(); } |
---|
[1263] | 1116 | |
---|
| 1117 | ///@} |
---|
| 1118 | |
---|
[1294] | 1119 | ///\name Obtain the solution |
---|
[1263] | 1120 | |
---|
| 1121 | ///@{ |
---|
| 1122 | |
---|
[1460] | 1123 | /// The status of the primal problem (the original LP problem) |
---|
[1312] | 1124 | SolutionStatus primalStatus() { |
---|
| 1125 | return _getPrimalStatus(); |
---|
[1294] | 1126 | } |
---|
| 1127 | |
---|
[1460] | 1128 | /// The status of the dual (of the original LP) problem |
---|
| 1129 | SolutionStatus dualStatus() { |
---|
| 1130 | return _getDualStatus(); |
---|
| 1131 | } |
---|
| 1132 | |
---|
| 1133 | ///The type of the original LP problem |
---|
[1462] | 1134 | ProblemTypes problemType() { |
---|
[1460] | 1135 | return _getProblemType(); |
---|
| 1136 | } |
---|
| 1137 | |
---|
[1294] | 1138 | ///\e |
---|
[1293] | 1139 | Value primal(Col c) { return _getPrimal(cols.floatingId(c.id)); } |
---|
[1263] | 1140 | |
---|
[1312] | 1141 | ///\e |
---|
[1787] | 1142 | Value dual(Row r) { return _getDual(rows.floatingId(r.id)); } |
---|
| 1143 | |
---|
| 1144 | ///\e |
---|
[1840] | 1145 | bool isBasicCol(Col c) { return _isBasicCol(cols.floatingId(c.id)); } |
---|
| 1146 | |
---|
| 1147 | ///\e |
---|
[1312] | 1148 | |
---|
| 1149 | ///\return |
---|
| 1150 | ///- \ref INF or -\ref INF means either infeasibility or unboundedness |
---|
| 1151 | /// of the primal problem, depending on whether we minimize or maximize. |
---|
[1364] | 1152 | ///- \ref NaN if no primal solution is found. |
---|
[1312] | 1153 | ///- The (finite) objective value if an optimal solution is found. |
---|
[1323] | 1154 | Value primalValue() { return _getPrimalValue()+obj_const_comp;} |
---|
[1263] | 1155 | ///@} |
---|
[1253] | 1156 | |
---|
[1248] | 1157 | }; |
---|
[1246] | 1158 | |
---|
[1272] | 1159 | ///\e |
---|
| 1160 | |
---|
| 1161 | ///\relates LpSolverBase::Expr |
---|
| 1162 | /// |
---|
| 1163 | inline LpSolverBase::Expr operator+(const LpSolverBase::Expr &a, |
---|
| 1164 | const LpSolverBase::Expr &b) |
---|
| 1165 | { |
---|
| 1166 | LpSolverBase::Expr tmp(a); |
---|
[1766] | 1167 | tmp+=b; |
---|
[1272] | 1168 | return tmp; |
---|
| 1169 | } |
---|
| 1170 | ///\e |
---|
| 1171 | |
---|
| 1172 | ///\relates LpSolverBase::Expr |
---|
| 1173 | /// |
---|
| 1174 | inline LpSolverBase::Expr operator-(const LpSolverBase::Expr &a, |
---|
| 1175 | const LpSolverBase::Expr &b) |
---|
| 1176 | { |
---|
| 1177 | LpSolverBase::Expr tmp(a); |
---|
[1766] | 1178 | tmp-=b; |
---|
[1272] | 1179 | return tmp; |
---|
| 1180 | } |
---|
| 1181 | ///\e |
---|
| 1182 | |
---|
| 1183 | ///\relates LpSolverBase::Expr |
---|
| 1184 | /// |
---|
| 1185 | inline LpSolverBase::Expr operator*(const LpSolverBase::Expr &a, |
---|
[1273] | 1186 | const LpSolverBase::Value &b) |
---|
[1272] | 1187 | { |
---|
| 1188 | LpSolverBase::Expr tmp(a); |
---|
[1766] | 1189 | tmp*=b; |
---|
[1272] | 1190 | return tmp; |
---|
| 1191 | } |
---|
| 1192 | |
---|
| 1193 | ///\e |
---|
| 1194 | |
---|
| 1195 | ///\relates LpSolverBase::Expr |
---|
| 1196 | /// |
---|
[1273] | 1197 | inline LpSolverBase::Expr operator*(const LpSolverBase::Value &a, |
---|
[1272] | 1198 | const LpSolverBase::Expr &b) |
---|
| 1199 | { |
---|
| 1200 | LpSolverBase::Expr tmp(b); |
---|
[1766] | 1201 | tmp*=a; |
---|
[1272] | 1202 | return tmp; |
---|
| 1203 | } |
---|
| 1204 | ///\e |
---|
| 1205 | |
---|
| 1206 | ///\relates LpSolverBase::Expr |
---|
| 1207 | /// |
---|
| 1208 | inline LpSolverBase::Expr operator/(const LpSolverBase::Expr &a, |
---|
[1273] | 1209 | const LpSolverBase::Value &b) |
---|
[1272] | 1210 | { |
---|
| 1211 | LpSolverBase::Expr tmp(a); |
---|
[1766] | 1212 | tmp/=b; |
---|
[1272] | 1213 | return tmp; |
---|
| 1214 | } |
---|
| 1215 | |
---|
| 1216 | ///\e |
---|
| 1217 | |
---|
| 1218 | ///\relates LpSolverBase::Constr |
---|
| 1219 | /// |
---|
| 1220 | inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e, |
---|
| 1221 | const LpSolverBase::Expr &f) |
---|
| 1222 | { |
---|
| 1223 | return LpSolverBase::Constr(-LpSolverBase::INF,e-f,0); |
---|
| 1224 | } |
---|
| 1225 | |
---|
| 1226 | ///\e |
---|
| 1227 | |
---|
| 1228 | ///\relates LpSolverBase::Constr |
---|
| 1229 | /// |
---|
[1273] | 1230 | inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &e, |
---|
[1272] | 1231 | const LpSolverBase::Expr &f) |
---|
| 1232 | { |
---|
| 1233 | return LpSolverBase::Constr(e,f); |
---|
| 1234 | } |
---|
| 1235 | |
---|
| 1236 | ///\e |
---|
| 1237 | |
---|
| 1238 | ///\relates LpSolverBase::Constr |
---|
| 1239 | /// |
---|
| 1240 | inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e, |
---|
[1273] | 1241 | const LpSolverBase::Value &f) |
---|
[1272] | 1242 | { |
---|
| 1243 | return LpSolverBase::Constr(e,f); |
---|
| 1244 | } |
---|
| 1245 | |
---|
| 1246 | ///\e |
---|
| 1247 | |
---|
| 1248 | ///\relates LpSolverBase::Constr |
---|
| 1249 | /// |
---|
| 1250 | inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e, |
---|
| 1251 | const LpSolverBase::Expr &f) |
---|
| 1252 | { |
---|
| 1253 | return LpSolverBase::Constr(-LpSolverBase::INF,f-e,0); |
---|
| 1254 | } |
---|
| 1255 | |
---|
| 1256 | |
---|
| 1257 | ///\e |
---|
| 1258 | |
---|
| 1259 | ///\relates LpSolverBase::Constr |
---|
| 1260 | /// |
---|
[1273] | 1261 | inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &e, |
---|
[1272] | 1262 | const LpSolverBase::Expr &f) |
---|
| 1263 | { |
---|
| 1264 | return LpSolverBase::Constr(f,e); |
---|
| 1265 | } |
---|
| 1266 | |
---|
| 1267 | |
---|
| 1268 | ///\e |
---|
| 1269 | |
---|
| 1270 | ///\relates LpSolverBase::Constr |
---|
| 1271 | /// |
---|
| 1272 | inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e, |
---|
[1273] | 1273 | const LpSolverBase::Value &f) |
---|
[1272] | 1274 | { |
---|
| 1275 | return LpSolverBase::Constr(f,e); |
---|
| 1276 | } |
---|
| 1277 | |
---|
| 1278 | ///\e |
---|
| 1279 | |
---|
| 1280 | ///\relates LpSolverBase::Constr |
---|
| 1281 | /// |
---|
| 1282 | inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e, |
---|
| 1283 | const LpSolverBase::Expr &f) |
---|
| 1284 | { |
---|
| 1285 | return LpSolverBase::Constr(0,e-f,0); |
---|
| 1286 | } |
---|
| 1287 | |
---|
| 1288 | ///\e |
---|
| 1289 | |
---|
| 1290 | ///\relates LpSolverBase::Constr |
---|
| 1291 | /// |
---|
[1273] | 1292 | inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &n, |
---|
[1272] | 1293 | const LpSolverBase::Constr&c) |
---|
| 1294 | { |
---|
| 1295 | LpSolverBase::Constr tmp(c); |
---|
[1273] | 1296 | ///\todo Create an own exception type. |
---|
[2026] | 1297 | if(!LpSolverBase::isNaN(tmp.lowerBound())) throw LogicError(); |
---|
[1273] | 1298 | else tmp.lowerBound()=n; |
---|
[1272] | 1299 | return tmp; |
---|
| 1300 | } |
---|
| 1301 | ///\e |
---|
| 1302 | |
---|
| 1303 | ///\relates LpSolverBase::Constr |
---|
| 1304 | /// |
---|
| 1305 | inline LpSolverBase::Constr operator<=(const LpSolverBase::Constr& c, |
---|
[1273] | 1306 | const LpSolverBase::Value &n) |
---|
[1272] | 1307 | { |
---|
| 1308 | LpSolverBase::Constr tmp(c); |
---|
[1273] | 1309 | ///\todo Create an own exception type. |
---|
[2026] | 1310 | if(!LpSolverBase::isNaN(tmp.upperBound())) throw LogicError(); |
---|
[1273] | 1311 | else tmp.upperBound()=n; |
---|
[1272] | 1312 | return tmp; |
---|
| 1313 | } |
---|
| 1314 | |
---|
| 1315 | ///\e |
---|
| 1316 | |
---|
| 1317 | ///\relates LpSolverBase::Constr |
---|
| 1318 | /// |
---|
[1273] | 1319 | inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &n, |
---|
[1272] | 1320 | const LpSolverBase::Constr&c) |
---|
| 1321 | { |
---|
| 1322 | LpSolverBase::Constr tmp(c); |
---|
[1273] | 1323 | ///\todo Create an own exception type. |
---|
[2026] | 1324 | if(!LpSolverBase::isNaN(tmp.upperBound())) throw LogicError(); |
---|
[1273] | 1325 | else tmp.upperBound()=n; |
---|
[1272] | 1326 | return tmp; |
---|
| 1327 | } |
---|
| 1328 | ///\e |
---|
| 1329 | |
---|
| 1330 | ///\relates LpSolverBase::Constr |
---|
| 1331 | /// |
---|
| 1332 | inline LpSolverBase::Constr operator>=(const LpSolverBase::Constr& c, |
---|
[1273] | 1333 | const LpSolverBase::Value &n) |
---|
[1272] | 1334 | { |
---|
| 1335 | LpSolverBase::Constr tmp(c); |
---|
[1273] | 1336 | ///\todo Create an own exception type. |
---|
[2026] | 1337 | if(!LpSolverBase::isNaN(tmp.lowerBound())) throw LogicError(); |
---|
[1273] | 1338 | else tmp.lowerBound()=n; |
---|
[1272] | 1339 | return tmp; |
---|
| 1340 | } |
---|
| 1341 | |
---|
[1445] | 1342 | ///\e |
---|
| 1343 | |
---|
| 1344 | ///\relates LpSolverBase::DualExpr |
---|
| 1345 | /// |
---|
| 1346 | inline LpSolverBase::DualExpr operator+(const LpSolverBase::DualExpr &a, |
---|
| 1347 | const LpSolverBase::DualExpr &b) |
---|
| 1348 | { |
---|
| 1349 | LpSolverBase::DualExpr tmp(a); |
---|
[1766] | 1350 | tmp+=b; |
---|
[1445] | 1351 | return tmp; |
---|
| 1352 | } |
---|
| 1353 | ///\e |
---|
| 1354 | |
---|
| 1355 | ///\relates LpSolverBase::DualExpr |
---|
| 1356 | /// |
---|
| 1357 | inline LpSolverBase::DualExpr operator-(const LpSolverBase::DualExpr &a, |
---|
| 1358 | const LpSolverBase::DualExpr &b) |
---|
| 1359 | { |
---|
| 1360 | LpSolverBase::DualExpr tmp(a); |
---|
[1766] | 1361 | tmp-=b; |
---|
[1445] | 1362 | return tmp; |
---|
| 1363 | } |
---|
| 1364 | ///\e |
---|
| 1365 | |
---|
| 1366 | ///\relates LpSolverBase::DualExpr |
---|
| 1367 | /// |
---|
| 1368 | inline LpSolverBase::DualExpr operator*(const LpSolverBase::DualExpr &a, |
---|
| 1369 | const LpSolverBase::Value &b) |
---|
| 1370 | { |
---|
| 1371 | LpSolverBase::DualExpr tmp(a); |
---|
[1766] | 1372 | tmp*=b; |
---|
[1445] | 1373 | return tmp; |
---|
| 1374 | } |
---|
| 1375 | |
---|
| 1376 | ///\e |
---|
| 1377 | |
---|
| 1378 | ///\relates LpSolverBase::DualExpr |
---|
| 1379 | /// |
---|
| 1380 | inline LpSolverBase::DualExpr operator*(const LpSolverBase::Value &a, |
---|
| 1381 | const LpSolverBase::DualExpr &b) |
---|
| 1382 | { |
---|
| 1383 | LpSolverBase::DualExpr tmp(b); |
---|
[1766] | 1384 | tmp*=a; |
---|
[1445] | 1385 | return tmp; |
---|
| 1386 | } |
---|
| 1387 | ///\e |
---|
| 1388 | |
---|
| 1389 | ///\relates LpSolverBase::DualExpr |
---|
| 1390 | /// |
---|
| 1391 | inline LpSolverBase::DualExpr operator/(const LpSolverBase::DualExpr &a, |
---|
| 1392 | const LpSolverBase::Value &b) |
---|
| 1393 | { |
---|
| 1394 | LpSolverBase::DualExpr tmp(a); |
---|
[1766] | 1395 | tmp/=b; |
---|
[1445] | 1396 | return tmp; |
---|
| 1397 | } |
---|
| 1398 | |
---|
[1272] | 1399 | |
---|
[1246] | 1400 | } //namespace lemon |
---|
| 1401 | |
---|
| 1402 | #endif //LEMON_LP_BASE_H |
---|