2 * lemon/lp_base.h - Part of LEMON, a generic C++ optimization library
4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Research Group on Combinatorial Optimization, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef LEMON_LP_BASE_H
18 #define LEMON_LP_BASE_H
25 #include<lemon/utility.h>
26 #include<lemon/error.h>
27 #include<lemon/invalid.h>
29 //#include"lin_expr.h"
32 ///\brief The interface of the LP solver interface.
33 ///\ingroup gen_opt_group
36 ///Internal data structure to convert floating id's to fix one's
38 ///\todo This might be implemented to be also usable in other places.
41 std::vector<int> index;
42 std::vector<int> cross;
45 _FixId() : first_free(-1) {};
46 ///Convert a floating id to a fix one
48 ///\param n is a floating id
49 ///\return the corresponding fix id
50 int fixId(int n) {return cross[n];}
51 ///Convert a fix id to a floating one
53 ///\param n is a fix id
54 ///\return the corresponding floating id
55 int floatingId(int n) { return index[n];}
56 ///Add a new floating id.
58 ///\param n is a floating id
59 ///\return the fix id of the new value
60 ///\todo Multiple additions should also be handled.
63 if(n>=int(cross.size())) {
66 cross[n]=index.size();
71 int next=index[first_free];
77 ///\todo Create an own exception type.
78 else throw LogicError(); //floatingId-s must form a continuous range;
82 ///\param n is a fix id
89 for(int i=fl+1;i<int(cross.size());++i) {
95 ///An upper bound on the largest fix id.
97 ///\todo Do we need this?
99 std::size_t maxFixId() { return cross.size()-1; }
103 ///Common base class for LP solvers
105 ///\todo Much more docs
106 ///\ingroup gen_opt_group
111 ///Possible outcomes of an LP solving procedure
112 enum SolveExitStatus {
113 ///This means that the problem has been successfully solved: either
114 ///an optimal solution has been found or infeasibility/unboundedness
117 ///Any other case (including the case when some user specified limit has been exceeded)
122 enum SolutionStatus {
123 ///Feasible solution has'n been found (but may exist).
125 ///\todo NOTFOUND might be a better name.
128 ///The problem has no feasible solution
130 ///Feasible solution found
132 ///Optimal solution exists and found
134 ///The cost function is unbounded
136 ///\todo Give a feasible solution and an infinite ray (and the
137 ///corresponding bases)
141 ///The floating point type used by the solver
142 typedef double Value;
143 ///The infinity constant
144 static const Value INF;
145 ///The not a number constant
146 static const Value NaN;
148 ///Refer to a column of the LP.
150 ///This type is used to refer to a column of the LP.
152 ///Its value remains valid and correct even after the addition or erase of
155 ///\todo Document what can one do with a Col (INVALID, comparing,
156 ///it is similar to Node/Edge)
160 friend class LpSolverBase;
162 typedef Value ExprValue;
163 typedef True LpSolverCol;
165 Col(const Invalid&) : id(-1) {}
166 bool operator<(Col c) const {return id<c.id;}
167 bool operator==(Col c) const {return id==c.id;}
168 bool operator!=(Col c) const {return id==c.id;}
171 ///Refer to a row of the LP.
173 ///This type is used to refer to a row of the LP.
175 ///Its value remains valid and correct even after the addition or erase of
178 ///\todo Document what can one do with a Row (INVALID, comparing,
179 ///it is similar to Node/Edge)
183 friend class LpSolverBase;
185 typedef Value ExprValue;
186 typedef True LpSolverRow;
188 Row(const Invalid&) : id(-1) {}
190 bool operator<(Row c) const {return id<c.id;}
191 bool operator==(Row c) const {return id==c.id;}
192 bool operator!=(Row c) const {return id==c.id;}
195 ///Linear expression of variables and a constant component
197 ///This data structure strores a linear expression of the variables
198 ///(\ref Col "Col"s) and also has a constant component.
200 ///There are several ways to access and modify the contents of this
202 ///- Its it fully compatible with \c std::map<Col,double>, so for expamle
203 ///if \c e is an Expr and \c v and \c w are of type \ref Col, then you can
204 ///read and modify the coefficients like
211 ///or you can also iterate through its elements.
214 ///for(LpSolverBase::Expr::iterator i=e.begin();i!=e.end();++i)
217 ///(This code computes the sum of all coefficients).
218 ///- Numbers (<tt>double</tt>'s)
219 ///and variables (\ref Col "Col"s) directly convert to an
220 ///\ref Expr and the usual linear operations are defined so
223 ///2*v-3.12*(v-w/2)+2
224 ///v*2.1+(3*v+(v*12+w+6)*3)/2
226 ///are valid \ref Expr "Expr"essions.
227 ///The usual assignment operations are also defined.
230 ///e+=2*v-3.12*(v-w/2)+2;
234 ///- The constant member can be set and read by \ref constComp()
237 ///double c=e.constComp();
240 ///\note \ref clear() not only sets all coefficients to 0 but also
241 ///clears the constant components.
245 class Expr : public std::map<Col,Value>
248 typedef LpSolverBase::Col Key;
249 typedef LpSolverBase::Value Value;
252 typedef std::map<Col,Value> Base;
256 typedef True IsLinExpression;
258 Expr() : Base(), const_comp(0) { }
260 Expr(const Key &v) : const_comp(0) {
261 Base::insert(std::make_pair(v, 1));
264 Expr(const Value &v) : const_comp(v) {}
266 void set(const Key &v,const Value &c) {
267 Base::insert(std::make_pair(v, c));
270 Value &constComp() { return const_comp; }
272 const Value &constComp() const { return const_comp; }
274 ///Removes the components with zero coefficient.
276 for (Base::iterator i=Base::begin(); i!=Base::end();) {
279 if ((*i).second==0) Base::erase(i);
284 ///Sets all coefficients and the constant component to 0.
291 Expr &operator+=(const Expr &e) {
292 for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
293 (*this)[j->first]+=j->second;
294 ///\todo it might be speeded up using "hints"
295 const_comp+=e.const_comp;
299 Expr &operator-=(const Expr &e) {
300 for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
301 (*this)[j->first]-=j->second;
302 const_comp-=e.const_comp;
306 Expr &operator*=(const Value &c) {
307 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
313 Expr &operator/=(const Value &c) {
314 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
323 ///This data stucture represents a linear constraint in the LP.
324 ///Basically it is a linear expression with a lower or an upper bound
325 ///(or both). These parts of the constraint can be obtained by the member
326 ///functions \ref expr(), \ref lowerBound() and \ref upperBound(),
328 ///There are two ways to construct a constraint.
329 ///- You can set the linear expression and the bounds directly
330 /// by the functions above.
331 ///- The operators <tt>\<=</tt>, <tt>==</tt> and <tt>\>=</tt>
332 /// are defined between expressions, or even between constraints whenever
333 /// it makes sense. Therefore if \c e and \c f are linear expressions and
334 /// \c s and \c t are numbers, then the followings are valid expressions
335 /// and thus they can be used directly e.g. in \ref addRow() whenever
343 ///\warning The validity of a constraint is checked only at run time, so
344 ///e.g. \ref addRow(<tt>x[1]\<=x[2]<=5</tt>) will compile, but will throw a
345 ///\ref LogicError exception.
349 typedef LpSolverBase::Expr Expr;
350 typedef Expr::Key Key;
351 typedef Expr::Value Value;
353 // static const Value INF;
354 // static const Value NaN;
361 Constr() : _expr(), _lb(NaN), _ub(NaN) {}
363 Constr(Value lb,const Expr &e,Value ub) :
364 _expr(e), _lb(lb), _ub(ub) {}
366 Constr(const Expr &e,Value ub) :
367 _expr(e), _lb(NaN), _ub(ub) {}
369 Constr(Value lb,const Expr &e) :
370 _expr(e), _lb(lb), _ub(NaN) {}
372 Constr(const Expr &e) :
373 _expr(e), _lb(NaN), _ub(NaN) {}
381 ///Reference to the linear expression
382 Expr &expr() { return _expr; }
383 ///Cont reference to the linear expression
384 const Expr &expr() const { return _expr; }
385 ///Reference to the lower bound.
388 ///- -\ref INF: the constraint is lower unbounded.
389 ///- -\ref NaN: lower bound has not been set.
390 ///- finite number: the lower bound
391 Value &lowerBound() { return _lb; }
392 ///The const version of \ref lowerBound()
393 const Value &lowerBound() const { return _lb; }
394 ///Reference to the upper bound.
397 ///- -\ref INF: the constraint is upper unbounded.
398 ///- -\ref NaN: upper bound has not been set.
399 ///- finite number: the upper bound
400 Value &upperBound() { return _ub; }
401 ///The const version of \ref upperBound()
402 const Value &upperBound() const { return _ub; }
403 ///Is the constraint lower bounded?
404 bool lowerBounded() const {
408 ///Is the constraint upper bounded?
409 bool upperBounded() const {
415 ///Linear expression of rows
417 ///This data structure represents a column of the matrix,
418 ///thas is it strores a linear expression of the dual variables
419 ///(\ref Row "Row"s).
421 ///There are several ways to access and modify the contents of this
423 ///- Its it fully compatible with \c std::map<Row,double>, so for expamle
424 ///if \c e is an DualExpr and \c v
425 ///and \c w are of type \ref Row, then you can
426 ///read and modify the coefficients like
433 ///or you can also iterate through its elements.
436 ///for(LpSolverBase::DualExpr::iterator i=e.begin();i!=e.end();++i)
439 ///(This code computes the sum of all coefficients).
440 ///- Numbers (<tt>double</tt>'s)
441 ///and variables (\ref Row "Row"s) directly convert to an
442 ///\ref DualExpr and the usual linear operations are defined so
446 ///v*2.1+(3*v+(v*12+w)*3)/2
448 ///are valid \ref DualExpr "DualExpr"essions.
449 ///The usual assignment operations are also defined.
452 ///e+=2*v-3.12*(v-w/2);
459 class DualExpr : public std::map<Row,Value>
462 typedef LpSolverBase::Row Key;
463 typedef LpSolverBase::Value Value;
466 typedef std::map<Row,Value> Base;
469 typedef True IsLinExpression;
471 DualExpr() : Base() { }
473 DualExpr(const Key &v) {
474 Base::insert(std::make_pair(v, 1));
477 DualExpr(const Value &v) {}
479 void set(const Key &v,const Value &c) {
480 Base::insert(std::make_pair(v, c));
483 ///Removes the components with zero coefficient.
485 for (Base::iterator i=Base::begin(); i!=Base::end();) {
488 if ((*i).second==0) Base::erase(i);
493 ///Sets all coefficients to 0.
499 DualExpr &operator+=(const DualExpr &e) {
500 for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
501 (*this)[j->first]+=j->second;
502 ///\todo it might be speeded up using "hints"
506 DualExpr &operator-=(const DualExpr &e) {
507 for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
508 (*this)[j->first]-=j->second;
512 DualExpr &operator*=(const Value &c) {
513 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
518 DualExpr &operator/=(const Value &c) {
519 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
530 //Abstract virtual functions
531 virtual LpSolverBase &_newLp() = 0;
532 virtual LpSolverBase &_copyLp(){
533 ///\todo This should be implemented here, too, when we have problem retrieving routines. It can be overriden.
536 LpSolverBase & newlp(_newLp());
538 //return *(LpSolverBase*)0;
541 virtual int _addCol() = 0;
542 virtual int _addRow() = 0;
543 virtual void _setRowCoeffs(int i,
546 Value const * values ) = 0;
547 virtual void _setColCoeffs(int i,
550 Value const * values ) = 0;
551 virtual void _setCoeff(int row, int col, Value value) = 0;
552 virtual void _setColLowerBound(int i, Value value) = 0;
553 virtual void _setColUpperBound(int i, Value value) = 0;
554 // virtual void _setRowLowerBound(int i, Value value) = 0;
555 // virtual void _setRowUpperBound(int i, Value value) = 0;
556 virtual void _setRowBounds(int i, Value lower, Value upper) = 0;
557 virtual void _setObjCoeff(int i, Value obj_coef) = 0;
558 virtual void _clearObj()=0;
559 // virtual void _setObj(int length,
560 // int const * indices,
561 // Value const * values ) = 0;
562 virtual SolveExitStatus _solve() = 0;
563 virtual Value _getPrimal(int i) = 0;
564 virtual Value _getPrimalValue() = 0;
565 virtual SolutionStatus _getPrimalStatus() = 0;
566 virtual void _setMax() = 0;
567 virtual void _setMin() = 0;
569 //Own protected stuff
571 //Constant component of the objective function
572 Value obj_const_comp;
580 LpSolverBase() : obj_const_comp(0) {}
583 virtual ~LpSolverBase() {}
585 ///Creates a new LP problem
586 LpSolverBase &newLp() {return _newLp();}
587 ///Makes a copy of the LP problem
588 LpSolverBase ©Lp() {return _copyLp();}
590 ///\name Build up and modify of the LP
594 ///Add a new empty column (i.e a new variable) to the LP
595 Col addCol() { Col c; c.id=cols.insert(_addCol()); return c;}
597 ///\brief Adds several new columns
598 ///(i.e a variables) at once
600 ///This magic function takes a container as its argument
601 ///and fills its elements
602 ///with new columns (i.e. variables)
604 ///- a standard STL compatible iterable container with
605 ///\ref Col as its \c values_type
608 ///std::vector<LpSolverBase::Col>
609 ///std::list<LpSolverBase::Col>
611 ///- a standard STL compatible iterable container with
612 ///\ref Col as its \c mapped_type
615 ///std::map<AnyType,LpSolverBase::Col>
617 ///- an iterable lemon \ref concept::WriteMap "write map" like
619 ///ListGraph::NodeMap<LpSolverBase::Col>
620 ///ListGraph::EdgeMap<LpSolverBase::Col>
622 ///\return The number of the created column.
625 int addColSet(T &t) { return 0;}
628 typename enable_if<typename T::value_type::LpSolverCol,int>::type
629 addColSet(T &t,dummy<0> = 0) {
631 for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addCol();s++;}
635 typename enable_if<typename T::value_type::second_type::LpSolverCol,
637 addColSet(T &t,dummy<1> = 1) {
639 for(typename T::iterator i=t.begin();i!=t.end();++i) {
646 typename enable_if<typename T::ValueSet::value_type::LpSolverCol,
648 addColSet(T &t,dummy<2> = 2) {
649 ///\bug <tt>return addColSet(t.valueSet());</tt> should also work.
651 for(typename T::ValueSet::iterator i=t.valueSet().begin();
652 i!=t.valueSet().end();
662 ///Set a column (i.e a dual constraint) of the LP
664 ///\param c is the column to be modified
665 ///\param e is a dual linear expression (see \ref DualExpr)
666 ///\bug This is a temportary function. The interface will change to
668 void setCol(Col c,const DualExpr &e) {
669 std::vector<int> indices;
670 std::vector<Value> values;
671 indices.push_back(0);
673 for(DualExpr::const_iterator i=e.begin(); i!=e.end(); ++i)
674 if((*i).second!=0) { ///\bug EPSILON would be necessary here!!!
675 indices.push_back(cols.floatingId((*i).first.id));
676 values.push_back((*i).second);
678 _setColCoeffs(cols.floatingId(c.id),indices.size()-1,
679 &indices[0],&values[0]);
682 ///Add a new column to the LP
684 ///\param e is a dual linear expression (see \ref DualExpr)
685 ///\param obj is the corresponding component of the objective
686 ///function. It is 0 by default.
687 ///\return The created column.
688 ///\bug This is a temportary function. The interface will change to
690 Col addCol(Value l,const DualExpr &e, Value obj=0) {
697 ///Add a new empty row (i.e a new constraint) to the LP
699 ///This function adds a new empty row (i.e a new constraint) to the LP.
700 ///\return The created row
701 Row addRow() { Row r; r.id=rows.insert(_addRow()); return r;}
703 ///\brief Adds several new row
704 ///(i.e a variables) at once
706 ///This magic function takes a container as its argument
707 ///and fills its elements
708 ///with new row (i.e. variables)
710 ///- a standard STL compatible iterable container with
711 ///\ref Row as its \c values_type
714 ///std::vector<LpSolverBase::Row>
715 ///std::list<LpSolverBase::Row>
717 ///- a standard STL compatible iterable container with
718 ///\ref Row as its \c mapped_type
721 ///std::map<AnyType,LpSolverBase::Row>
723 ///- an iterable lemon \ref concept::WriteMap "write map" like
725 ///ListGraph::NodeMap<LpSolverBase::Row>
726 ///ListGraph::EdgeMap<LpSolverBase::Row>
728 ///\return The number of rows created.
731 int addRowSet(T &t) { return 0;}
734 typename enable_if<typename T::value_type::LpSolverRow,int>::type
735 addRowSet(T &t,dummy<0> = 0) {
737 for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addRow();s++;}
741 typename enable_if<typename T::value_type::second_type::LpSolverRow,
743 addRowSet(T &t,dummy<1> = 1) {
745 for(typename T::iterator i=t.begin();i!=t.end();++i) {
752 typename enable_if<typename T::ValueSet::value_type::LpSolverRow,
754 addRowSet(T &t,dummy<2> = 2) {
755 ///\bug <tt>return addRowSet(t.valueSet());</tt> should also work.
757 for(typename T::ValueSet::iterator i=t.valueSet().begin();
758 i!=t.valueSet().end();
768 ///Set a row (i.e a constraint) of the LP
770 ///\param r is the row to be modified
771 ///\param l is lower bound (-\ref INF means no bound)
772 ///\param e is a linear expression (see \ref Expr)
773 ///\param u is the upper bound (\ref INF means no bound)
774 ///\bug This is a temportary function. The interface will change to
776 ///\todo Option to control whether a constraint with a single variable is
778 void setRow(Row r, Value l,const Expr &e, Value u) {
779 std::vector<int> indices;
780 std::vector<Value> values;
781 indices.push_back(0);
783 for(Expr::const_iterator i=e.begin(); i!=e.end(); ++i)
784 if((*i).second!=0) { ///\bug EPSILON would be necessary here!!!
785 indices.push_back(cols.floatingId((*i).first.id));
786 values.push_back((*i).second);
788 _setRowCoeffs(rows.floatingId(r.id),indices.size()-1,
789 &indices[0],&values[0]);
790 // _setRowLowerBound(rows.floatingId(r.id),l-e.constComp());
791 // _setRowUpperBound(rows.floatingId(r.id),u-e.constComp());
792 _setRowBounds(rows.floatingId(r.id),l-e.constComp(),u-e.constComp());
795 ///Set a row (i.e a constraint) of the LP
797 ///\param r is the row to be modified
798 ///\param c is a linear expression (see \ref Constr)
799 void setRow(Row r, const Constr &c) {
801 c.lowerBounded()?c.lowerBound():-INF,
803 c.upperBounded()?c.upperBound():INF);
806 ///Add a new row (i.e a new constraint) to the LP
808 ///\param l is the lower bound (-\ref INF means no bound)
809 ///\param e is a linear expression (see \ref Expr)
810 ///\param u is the upper bound (\ref INF means no bound)
811 ///\return The created row.
812 ///\bug This is a temportary function. The interface will change to
814 Row addRow(Value l,const Expr &e, Value u) {
820 ///Add a new row (i.e a new constraint) to the LP
822 ///\param c is a linear expression (see \ref Constr)
823 ///\return The created row.
824 Row addRow(const Constr &c) {
830 ///Set an element of the coefficient matrix of the LP
832 ///\param r is the row of the element to be modified
833 ///\param c is the coloumn of the element to be modified
834 ///\param val is the new value of the coefficient
835 void setCoeff(Row r, Col c, Value val){
836 _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
839 /// Set the lower bound of a column (i.e a variable)
841 /// The upper bound of a variable (column) has to be given by an
842 /// extended number of type Value, i.e. a finite number of type
843 /// Value or -\ref INF.
844 void colLowerBound(Col c, Value value) {
845 _setColLowerBound(cols.floatingId(c.id),value);
847 /// Set the upper bound of a column (i.e a variable)
849 /// The upper bound of a variable (column) has to be given by an
850 /// extended number of type Value, i.e. a finite number of type
851 /// Value or \ref INF.
852 void colUpperBound(Col c, Value value) {
853 _setColUpperBound(cols.floatingId(c.id),value);
855 /// Set the lower and the upper bounds of a column (i.e a variable)
857 /// The lower and the upper bounds of
858 /// a variable (column) have to be given by an
859 /// extended number of type Value, i.e. a finite number of type
860 /// Value, -\ref INF or \ref INF.
861 void colBounds(Col c, Value lower, Value upper) {
862 _setColLowerBound(cols.floatingId(c.id),lower);
863 _setColUpperBound(cols.floatingId(c.id),upper);
866 // /// Set the lower bound of a row (i.e a constraint)
868 // /// The lower bound of a linear expression (row) has to be given by an
869 // /// extended number of type Value, i.e. a finite number of type
870 // /// Value or -\ref INF.
871 // void rowLowerBound(Row r, Value value) {
872 // _setRowLowerBound(rows.floatingId(r.id),value);
874 // /// Set the upper bound of a row (i.e a constraint)
876 // /// The upper bound of a linear expression (row) has to be given by an
877 // /// extended number of type Value, i.e. a finite number of type
878 // /// Value or \ref INF.
879 // void rowUpperBound(Row r, Value value) {
880 // _setRowUpperBound(rows.floatingId(r.id),value);
883 /// Set the lower and the upper bounds of a row (i.e a constraint)
885 /// The lower and the upper bounds of
886 /// a constraint (row) have to be given by an
887 /// extended number of type Value, i.e. a finite number of type
888 /// Value, -\ref INF or \ref INF.
889 void rowBounds(Row c, Value lower, Value upper) {
890 _setRowBounds(rows.floatingId(c.id),lower, upper);
891 // _setRowUpperBound(rows.floatingId(c.id),upper);
894 ///Set an element of the objective function
895 void objCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); };
896 ///Set the objective function
898 ///\param e is a linear expression of type \ref Expr.
899 ///\bug The previous objective function is not cleared!
900 void setObj(Expr e) {
902 for (Expr::iterator i=e.begin(); i!=e.end(); ++i)
903 objCoeff((*i).first,(*i).second);
904 obj_const_comp=e.constComp();
908 void max() { _setMax(); }
910 void min() { _setMin(); }
916 ///\name Solve the LP
920 ///\e Solve the LP problem at hand
922 ///\return The result of the optimization procedure. Possible values and their meanings can be found in the documentation of \ref SolveExitStatus.
924 ///\todo Which method is used to solve the problem
925 SolveExitStatus solve() { return _solve(); }
929 ///\name Obtain the solution
934 SolutionStatus primalStatus() {
935 return _getPrimalStatus();
939 Value primal(Col c) { return _getPrimal(cols.floatingId(c.id)); }
944 ///- \ref INF or -\ref INF means either infeasibility or unboundedness
945 /// of the primal problem, depending on whether we minimize or maximize.
946 ///- \ref NaN if no primal solution is found.
947 ///- The (finite) objective value if an optimal solution is found.
948 Value primalValue() { return _getPrimalValue()+obj_const_comp;}
955 ///\relates LpSolverBase::Expr
957 inline LpSolverBase::Expr operator+(const LpSolverBase::Expr &a,
958 const LpSolverBase::Expr &b)
960 LpSolverBase::Expr tmp(a);
961 tmp+=b; ///\todo Doesn't STL have some special 'merge' algorithm?
966 ///\relates LpSolverBase::Expr
968 inline LpSolverBase::Expr operator-(const LpSolverBase::Expr &a,
969 const LpSolverBase::Expr &b)
971 LpSolverBase::Expr tmp(a);
972 tmp-=b; ///\todo Doesn't STL have some special 'merge' algorithm?
977 ///\relates LpSolverBase::Expr
979 inline LpSolverBase::Expr operator*(const LpSolverBase::Expr &a,
980 const LpSolverBase::Value &b)
982 LpSolverBase::Expr tmp(a);
983 tmp*=b; ///\todo Doesn't STL have some special 'merge' algorithm?
989 ///\relates LpSolverBase::Expr
991 inline LpSolverBase::Expr operator*(const LpSolverBase::Value &a,
992 const LpSolverBase::Expr &b)
994 LpSolverBase::Expr tmp(b);
995 tmp*=a; ///\todo Doesn't STL have some special 'merge' algorithm?
1000 ///\relates LpSolverBase::Expr
1002 inline LpSolverBase::Expr operator/(const LpSolverBase::Expr &a,
1003 const LpSolverBase::Value &b)
1005 LpSolverBase::Expr tmp(a);
1006 tmp/=b; ///\todo Doesn't STL have some special 'merge' algorithm?
1012 ///\relates LpSolverBase::Constr
1014 inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e,
1015 const LpSolverBase::Expr &f)
1017 return LpSolverBase::Constr(-LpSolverBase::INF,e-f,0);
1022 ///\relates LpSolverBase::Constr
1024 inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &e,
1025 const LpSolverBase::Expr &f)
1027 return LpSolverBase::Constr(e,f);
1032 ///\relates LpSolverBase::Constr
1034 inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e,
1035 const LpSolverBase::Value &f)
1037 return LpSolverBase::Constr(e,f);
1042 ///\relates LpSolverBase::Constr
1044 inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e,
1045 const LpSolverBase::Expr &f)
1047 return LpSolverBase::Constr(-LpSolverBase::INF,f-e,0);
1053 ///\relates LpSolverBase::Constr
1055 inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &e,
1056 const LpSolverBase::Expr &f)
1058 return LpSolverBase::Constr(f,e);
1064 ///\relates LpSolverBase::Constr
1066 inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e,
1067 const LpSolverBase::Value &f)
1069 return LpSolverBase::Constr(f,e);
1074 ///\relates LpSolverBase::Constr
1076 inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e,
1077 const LpSolverBase::Expr &f)
1079 return LpSolverBase::Constr(0,e-f,0);
1084 ///\relates LpSolverBase::Constr
1086 inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &n,
1087 const LpSolverBase::Constr&c)
1089 LpSolverBase::Constr tmp(c);
1090 ///\todo Create an own exception type.
1091 if(!isnan(tmp.lowerBound())) throw LogicError();
1092 else tmp.lowerBound()=n;
1097 ///\relates LpSolverBase::Constr
1099 inline LpSolverBase::Constr operator<=(const LpSolverBase::Constr& c,
1100 const LpSolverBase::Value &n)
1102 LpSolverBase::Constr tmp(c);
1103 ///\todo Create an own exception type.
1104 if(!isnan(tmp.upperBound())) throw LogicError();
1105 else tmp.upperBound()=n;
1111 ///\relates LpSolverBase::Constr
1113 inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &n,
1114 const LpSolverBase::Constr&c)
1116 LpSolverBase::Constr tmp(c);
1117 ///\todo Create an own exception type.
1118 if(!isnan(tmp.upperBound())) throw LogicError();
1119 else tmp.upperBound()=n;
1124 ///\relates LpSolverBase::Constr
1126 inline LpSolverBase::Constr operator>=(const LpSolverBase::Constr& c,
1127 const LpSolverBase::Value &n)
1129 LpSolverBase::Constr tmp(c);
1130 ///\todo Create an own exception type.
1131 if(!isnan(tmp.lowerBound())) throw LogicError();
1132 else tmp.lowerBound()=n;
1138 ///\relates LpSolverBase::DualExpr
1140 inline LpSolverBase::DualExpr operator+(const LpSolverBase::DualExpr &a,
1141 const LpSolverBase::DualExpr &b)
1143 LpSolverBase::DualExpr tmp(a);
1144 tmp+=b; ///\todo Doesn't STL have some special 'merge' algorithm?
1149 ///\relates LpSolverBase::DualExpr
1151 inline LpSolverBase::DualExpr operator-(const LpSolverBase::DualExpr &a,
1152 const LpSolverBase::DualExpr &b)
1154 LpSolverBase::DualExpr tmp(a);
1155 tmp-=b; ///\todo Doesn't STL have some special 'merge' algorithm?
1160 ///\relates LpSolverBase::DualExpr
1162 inline LpSolverBase::DualExpr operator*(const LpSolverBase::DualExpr &a,
1163 const LpSolverBase::Value &b)
1165 LpSolverBase::DualExpr tmp(a);
1166 tmp*=b; ///\todo Doesn't STL have some special 'merge' algorithm?
1172 ///\relates LpSolverBase::DualExpr
1174 inline LpSolverBase::DualExpr operator*(const LpSolverBase::Value &a,
1175 const LpSolverBase::DualExpr &b)
1177 LpSolverBase::DualExpr tmp(b);
1178 tmp*=a; ///\todo Doesn't STL have some special 'merge' algorithm?
1183 ///\relates LpSolverBase::DualExpr
1185 inline LpSolverBase::DualExpr operator/(const LpSolverBase::DualExpr &a,
1186 const LpSolverBase::Value &b)
1188 LpSolverBase::DualExpr tmp(a);
1189 tmp/=b; ///\todo Doesn't STL have some special 'merge' algorithm?
1196 #endif //LEMON_LP_BASE_H