Tons of todos have been removed.
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>
30 ///\brief The interface of the LP solver interface.
31 ///\ingroup gen_opt_group
34 ///Internal data structure to convert floating id's to fix one's
36 ///\todo This might be implemented to be also usable in other places.
39 std::vector<int> index;
40 std::vector<int> cross;
43 _FixId() : first_free(-1) {};
44 ///Convert a floating id to a fix one
46 ///\param n is a floating id
47 ///\return the corresponding fix id
48 int fixId(int n) const {return cross[n];}
49 ///Convert a fix id to a floating one
51 ///\param n is a fix id
52 ///\return the corresponding floating id
53 int floatingId(int n) const { return index[n];}
54 ///Add a new floating id.
56 ///\param n is a floating id
57 ///\return the fix id of the new value
58 ///\todo Multiple additions should also be handled.
61 if(n>=int(cross.size())) {
64 cross[n]=index.size();
69 int next=index[first_free];
75 ///\todo Create an own exception type.
76 else throw LogicError(); //floatingId-s must form a continuous range;
80 ///\param n is a fix id
87 for(int i=fl+1;i<int(cross.size());++i) {
93 ///An upper bound on the largest fix id.
95 ///\todo Do we need this?
97 std::size_t maxFixId() { return cross.size()-1; }
101 ///Common base class for LP solvers
103 ///\todo Much more docs
104 ///\ingroup gen_opt_group
109 ///Possible outcomes of an LP solving procedure
110 enum SolveExitStatus {
111 ///This means that the problem has been successfully solved: either
112 ///an optimal solution has been found or infeasibility/unboundedness
115 ///Any other case (including the case when some user specified limit has been exceeded)
120 enum SolutionStatus {
121 ///Feasible solution has'n been found (but may exist).
123 ///\todo NOTFOUND might be a better name.
126 ///The problem has no feasible solution
128 ///Feasible solution found
130 ///Optimal solution exists and found
132 ///The cost function is unbounded
134 ///\todo Give a feasible solution and an infinite ray (and the
135 ///corresponding bases)
139 ///\e The type of the investigated LP problem
141 ///Primal-dual feasible
142 PRIMAL_DUAL_FEASIBLE = 0,
143 ///Primal feasible dual infeasible
144 PRIMAL_FEASIBLE_DUAL_INFEASIBLE = 1,
145 ///Primal infeasible dual feasible
146 PRIMAL_INFEASIBLE_DUAL_FEASIBLE = 2,
147 ///Primal-dual infeasible
148 PRIMAL_DUAL_INFEASIBLE = 3,
149 ///Could not determine so far
153 ///The floating point type used by the solver
154 typedef double Value;
155 ///The infinity constant
156 static const Value INF;
157 ///The not a number constant
158 static const Value NaN;
160 ///Refer to a column of the LP.
162 ///This type is used to refer to a column of the LP.
164 ///Its value remains valid and correct even after the addition or erase of
167 ///\todo Document what can one do with a Col (INVALID, comparing,
168 ///it is similar to Node/Edge)
172 friend class LpSolverBase;
174 typedef Value ExprValue;
175 typedef True LpSolverCol;
177 Col(const Invalid&) : id(-1) {}
178 bool operator<(Col c) const {return id<c.id;}
179 bool operator==(Col c) const {return id==c.id;}
180 bool operator!=(Col c) const {return id==c.id;}
183 ///Refer to a row of the LP.
185 ///This type is used to refer to a row of the LP.
187 ///Its value remains valid and correct even after the addition or erase of
190 ///\todo Document what can one do with a Row (INVALID, comparing,
191 ///it is similar to Node/Edge)
195 friend class LpSolverBase;
197 typedef Value ExprValue;
198 typedef True LpSolverRow;
200 Row(const Invalid&) : id(-1) {}
202 bool operator<(Row c) const {return id<c.id;}
203 bool operator==(Row c) const {return id==c.id;}
204 bool operator!=(Row c) const {return id==c.id;}
207 ///Linear expression of variables and a constant component
209 ///This data structure strores a linear expression of the variables
210 ///(\ref Col "Col"s) and also has a constant component.
212 ///There are several ways to access and modify the contents of this
214 ///- Its it fully compatible with \c std::map<Col,double>, so for expamle
215 ///if \c e is an Expr and \c v and \c w are of type \ref Col, then you can
216 ///read and modify the coefficients like
223 ///or you can also iterate through its elements.
226 ///for(LpSolverBase::Expr::iterator i=e.begin();i!=e.end();++i)
229 ///(This code computes the sum of all coefficients).
230 ///- Numbers (<tt>double</tt>'s)
231 ///and variables (\ref Col "Col"s) directly convert to an
232 ///\ref Expr and the usual linear operations are defined so
235 ///2*v-3.12*(v-w/2)+2
236 ///v*2.1+(3*v+(v*12+w+6)*3)/2
238 ///are valid \ref Expr "Expr"essions.
239 ///The usual assignment operations are also defined.
242 ///e+=2*v-3.12*(v-w/2)+2;
246 ///- The constant member can be set and read by \ref constComp()
249 ///double c=e.constComp();
252 ///\note \ref clear() not only sets all coefficients to 0 but also
253 ///clears the constant components.
257 class Expr : public std::map<Col,Value>
260 typedef LpSolverBase::Col Key;
261 typedef LpSolverBase::Value Value;
264 typedef std::map<Col,Value> Base;
268 typedef True IsLinExpression;
270 Expr() : Base(), const_comp(0) { }
272 Expr(const Key &v) : const_comp(0) {
273 Base::insert(std::make_pair(v, 1));
276 Expr(const Value &v) : const_comp(v) {}
278 void set(const Key &v,const Value &c) {
279 Base::insert(std::make_pair(v, c));
282 Value &constComp() { return const_comp; }
284 const Value &constComp() const { return const_comp; }
286 ///Removes the components with zero coefficient.
288 for (Base::iterator i=Base::begin(); i!=Base::end();) {
291 if ((*i).second==0) Base::erase(i);
296 ///Sets all coefficients and the constant component to 0.
303 Expr &operator+=(const Expr &e) {
304 for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
305 (*this)[j->first]+=j->second;
306 const_comp+=e.const_comp;
310 Expr &operator-=(const Expr &e) {
311 for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
312 (*this)[j->first]-=j->second;
313 const_comp-=e.const_comp;
317 Expr &operator*=(const Value &c) {
318 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
324 Expr &operator/=(const Value &c) {
325 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
334 ///This data stucture represents a linear constraint in the LP.
335 ///Basically it is a linear expression with a lower or an upper bound
336 ///(or both). These parts of the constraint can be obtained by the member
337 ///functions \ref expr(), \ref lowerBound() and \ref upperBound(),
339 ///There are two ways to construct a constraint.
340 ///- You can set the linear expression and the bounds directly
341 /// by the functions above.
342 ///- The operators <tt>\<=</tt>, <tt>==</tt> and <tt>\>=</tt>
343 /// are defined between expressions, or even between constraints whenever
344 /// it makes sense. Therefore if \c e and \c f are linear expressions and
345 /// \c s and \c t are numbers, then the followings are valid expressions
346 /// and thus they can be used directly e.g. in \ref addRow() whenever
354 ///\warning The validity of a constraint is checked only at run time, so
355 ///e.g. \ref addRow(<tt>x[1]\<=x[2]<=5</tt>) will compile, but will throw a
356 ///\ref LogicError exception.
360 typedef LpSolverBase::Expr Expr;
361 typedef Expr::Key Key;
362 typedef Expr::Value Value;
364 // static const Value INF;
365 // static const Value NaN;
372 Constr() : _expr(), _lb(NaN), _ub(NaN) {}
374 Constr(Value lb,const Expr &e,Value ub) :
375 _expr(e), _lb(lb), _ub(ub) {}
377 Constr(const Expr &e,Value ub) :
378 _expr(e), _lb(NaN), _ub(ub) {}
380 Constr(Value lb,const Expr &e) :
381 _expr(e), _lb(lb), _ub(NaN) {}
383 Constr(const Expr &e) :
384 _expr(e), _lb(NaN), _ub(NaN) {}
392 ///Reference to the linear expression
393 Expr &expr() { return _expr; }
394 ///Cont reference to the linear expression
395 const Expr &expr() const { return _expr; }
396 ///Reference to the lower bound.
399 ///- \ref INF "INF": the constraint is lower unbounded.
400 ///- \ref NaN "NaN": lower bound has not been set.
401 ///- finite number: the lower bound
402 Value &lowerBound() { return _lb; }
403 ///The const version of \ref lowerBound()
404 const Value &lowerBound() const { return _lb; }
405 ///Reference to the upper bound.
408 ///- \ref INF "INF": the constraint is upper unbounded.
409 ///- \ref NaN "NaN": upper bound has not been set.
410 ///- finite number: the upper bound
411 Value &upperBound() { return _ub; }
412 ///The const version of \ref upperBound()
413 const Value &upperBound() const { return _ub; }
414 ///Is the constraint lower bounded?
415 bool lowerBounded() const {
419 ///Is the constraint upper bounded?
420 bool upperBounded() const {
426 ///Linear expression of rows
428 ///This data structure represents a column of the matrix,
429 ///thas is it strores a linear expression of the dual variables
430 ///(\ref Row "Row"s).
432 ///There are several ways to access and modify the contents of this
434 ///- Its it fully compatible with \c std::map<Row,double>, so for expamle
435 ///if \c e is an DualExpr and \c v
436 ///and \c w are of type \ref Row, then you can
437 ///read and modify the coefficients like
444 ///or you can also iterate through its elements.
447 ///for(LpSolverBase::DualExpr::iterator i=e.begin();i!=e.end();++i)
450 ///(This code computes the sum of all coefficients).
451 ///- Numbers (<tt>double</tt>'s)
452 ///and variables (\ref Row "Row"s) directly convert to an
453 ///\ref DualExpr and the usual linear operations are defined so
457 ///v*2.1+(3*v+(v*12+w)*3)/2
459 ///are valid \ref DualExpr "DualExpr"essions.
460 ///The usual assignment operations are also defined.
463 ///e+=2*v-3.12*(v-w/2);
470 class DualExpr : public std::map<Row,Value>
473 typedef LpSolverBase::Row Key;
474 typedef LpSolverBase::Value Value;
477 typedef std::map<Row,Value> Base;
480 typedef True IsLinExpression;
482 DualExpr() : Base() { }
484 DualExpr(const Key &v) {
485 Base::insert(std::make_pair(v, 1));
488 void set(const Key &v,const Value &c) {
489 Base::insert(std::make_pair(v, c));
492 ///Removes the components with zero coefficient.
494 for (Base::iterator i=Base::begin(); i!=Base::end();) {
497 if ((*i).second==0) Base::erase(i);
502 ///Sets all coefficients to 0.
508 DualExpr &operator+=(const DualExpr &e) {
509 for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
510 (*this)[j->first]+=j->second;
514 DualExpr &operator-=(const DualExpr &e) {
515 for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
516 (*this)[j->first]-=j->second;
520 DualExpr &operator*=(const Value &c) {
521 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
526 DualExpr &operator/=(const Value &c) {
527 for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
538 //Abstract virtual functions
539 virtual LpSolverBase &_newLp() = 0;
540 virtual LpSolverBase &_copyLp(){
541 ///\todo This should be implemented here, too, when we have problem retrieving routines. It can be overriden.
544 LpSolverBase & newlp(_newLp());
546 //return *(LpSolverBase*)0;
549 virtual int _addCol() = 0;
550 virtual int _addRow() = 0;
551 virtual void _eraseCol(int col) = 0;
552 virtual void _eraseRow(int row) = 0;
553 virtual void _setRowCoeffs(int i,
556 Value const * values ) = 0;
557 virtual void _setColCoeffs(int i,
560 Value const * values ) = 0;
561 virtual void _setCoeff(int row, int col, Value value) = 0;
562 virtual void _setColLowerBound(int i, Value value) = 0;
563 virtual void _setColUpperBound(int i, Value value) = 0;
564 // virtual void _setRowLowerBound(int i, Value value) = 0;
565 // virtual void _setRowUpperBound(int i, Value value) = 0;
566 virtual void _setRowBounds(int i, Value lower, Value upper) = 0;
567 virtual void _setObjCoeff(int i, Value obj_coef) = 0;
568 virtual void _clearObj()=0;
569 // virtual void _setObj(int length,
570 // int const * indices,
571 // Value const * values ) = 0;
572 virtual SolveExitStatus _solve() = 0;
573 virtual Value _getPrimal(int i) = 0;
574 virtual Value _getPrimalValue() = 0;
575 virtual SolutionStatus _getPrimalStatus() = 0;
576 virtual SolutionStatus _getDualStatus() = 0;
577 ///\todo This could be implemented here, too, using _getPrimalStatus() and
579 virtual ProblemTypes _getProblemType() = 0;
581 virtual void _setMax() = 0;
582 virtual void _setMin() = 0;
584 //Own protected stuff
586 //Constant component of the objective function
587 Value obj_const_comp;
595 LpSolverBase() : obj_const_comp(0) {}
598 virtual ~LpSolverBase() {}
600 ///Creates a new LP problem
601 LpSolverBase &newLp() {return _newLp();}
602 ///Makes a copy of the LP problem
603 LpSolverBase ©Lp() {return _copyLp();}
605 ///\name Build up and modify the LP
609 ///Add a new empty column (i.e a new variable) to the LP
610 Col addCol() { Col c; c.id=cols.insert(_addCol()); return c;}
612 ///\brief Adds several new columns
613 ///(i.e a variables) at once
615 ///This magic function takes a container as its argument
616 ///and fills its elements
617 ///with new columns (i.e. variables)
619 ///- a standard STL compatible iterable container with
620 ///\ref Col as its \c values_type
623 ///std::vector<LpSolverBase::Col>
624 ///std::list<LpSolverBase::Col>
626 ///- a standard STL compatible iterable container with
627 ///\ref Col as its \c mapped_type
630 ///std::map<AnyType,LpSolverBase::Col>
632 ///- an iterable lemon \ref concept::WriteMap "write map" like
634 ///ListGraph::NodeMap<LpSolverBase::Col>
635 ///ListGraph::EdgeMap<LpSolverBase::Col>
637 ///\return The number of the created column.
640 int addColSet(T &t) { return 0;}
643 typename enable_if<typename T::value_type::LpSolverCol,int>::type
644 addColSet(T &t,dummy<0> = 0) {
646 for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addCol();s++;}
650 typename enable_if<typename T::value_type::second_type::LpSolverCol,
652 addColSet(T &t,dummy<1> = 1) {
654 for(typename T::iterator i=t.begin();i!=t.end();++i) {
661 typename enable_if<typename T::ValueSet::value_type::LpSolverCol,
663 addColSet(T &t,dummy<2> = 2) {
664 ///\bug <tt>return addColSet(t.valueSet());</tt> should also work.
666 for(typename T::ValueSet::iterator i=t.valueSet().begin();
667 i!=t.valueSet().end();
677 ///Set a column (i.e a dual constraint) of the LP
679 ///\param c is the column to be modified
680 ///\param e is a dual linear expression (see \ref DualExpr)
681 ///\bug This is a temporary function. The interface will change to
683 void setCol(Col c,const DualExpr &e) {
684 std::vector<int> indices;
685 std::vector<Value> values;
686 indices.push_back(0);
688 for(DualExpr::const_iterator i=e.begin(); i!=e.end(); ++i)
689 if((*i).second!=0) { ///\bug EPSILON would be necessary here!!!
690 indices.push_back(cols.floatingId((*i).first.id));
691 values.push_back((*i).second);
693 _setColCoeffs(cols.floatingId(c.id),indices.size()-1,
694 &indices[0],&values[0]);
697 ///Add a new column to the LP
699 ///\param e is a dual linear expression (see \ref DualExpr)
700 ///\param obj is the corresponding component of the objective
701 ///function. It is 0 by default.
702 ///\return The created column.
703 ///\bug This is a temportary function. The interface will change to
705 Col addCol(const DualExpr &e, Value obj=0) {
712 ///Add a new empty row (i.e a new constraint) to the LP
714 ///This function adds a new empty row (i.e a new constraint) to the LP.
715 ///\return The created row
716 Row addRow() { Row r; r.id=rows.insert(_addRow()); return r;}
718 ///\brief Add several new rows
719 ///(i.e a constraints) at once
721 ///This magic function takes a container as its argument
722 ///and fills its elements
723 ///with new row (i.e. variables)
725 ///- a standard STL compatible iterable container with
726 ///\ref Row as its \c values_type
729 ///std::vector<LpSolverBase::Row>
730 ///std::list<LpSolverBase::Row>
732 ///- a standard STL compatible iterable container with
733 ///\ref Row as its \c mapped_type
736 ///std::map<AnyType,LpSolverBase::Row>
738 ///- an iterable lemon \ref concept::WriteMap "write map" like
740 ///ListGraph::NodeMap<LpSolverBase::Row>
741 ///ListGraph::EdgeMap<LpSolverBase::Row>
743 ///\return The number of rows created.
746 int addRowSet(T &t) { return 0;}
749 typename enable_if<typename T::value_type::LpSolverRow,int>::type
750 addRowSet(T &t,dummy<0> = 0) {
752 for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addRow();s++;}
756 typename enable_if<typename T::value_type::second_type::LpSolverRow,
758 addRowSet(T &t,dummy<1> = 1) {
760 for(typename T::iterator i=t.begin();i!=t.end();++i) {
767 typename enable_if<typename T::ValueSet::value_type::LpSolverRow,
769 addRowSet(T &t,dummy<2> = 2) {
770 ///\bug <tt>return addRowSet(t.valueSet());</tt> should also work.
772 for(typename T::ValueSet::iterator i=t.valueSet().begin();
773 i!=t.valueSet().end();
783 ///Set a row (i.e a constraint) of the LP
785 ///\param r is the row to be modified
786 ///\param l is lower bound (-\ref INF means no bound)
787 ///\param e is a linear expression (see \ref Expr)
788 ///\param u is the upper bound (\ref INF means no bound)
789 ///\bug This is a temportary function. The interface will change to
791 ///\todo Option to control whether a constraint with a single variable is
793 void setRow(Row r, Value l,const Expr &e, Value u) {
794 std::vector<int> indices;
795 std::vector<Value> values;
796 indices.push_back(0);
798 for(Expr::const_iterator i=e.begin(); i!=e.end(); ++i)
799 if((*i).second!=0) { ///\bug EPSILON would be necessary here!!!
800 indices.push_back(cols.floatingId((*i).first.id));
801 values.push_back((*i).second);
803 _setRowCoeffs(rows.floatingId(r.id),indices.size()-1,
804 &indices[0],&values[0]);
805 // _setRowLowerBound(rows.floatingId(r.id),l-e.constComp());
806 // _setRowUpperBound(rows.floatingId(r.id),u-e.constComp());
807 _setRowBounds(rows.floatingId(r.id),l-e.constComp(),u-e.constComp());
810 ///Set a row (i.e a constraint) of the LP
812 ///\param r is the row to be modified
813 ///\param c is a linear expression (see \ref Constr)
814 void setRow(Row r, const Constr &c) {
816 c.lowerBounded()?c.lowerBound():-INF,
818 c.upperBounded()?c.upperBound():INF);
821 ///Add a new row (i.e a new constraint) to the LP
823 ///\param l is the lower bound (-\ref INF means no bound)
824 ///\param e is a linear expression (see \ref Expr)
825 ///\param u is the upper bound (\ref INF means no bound)
826 ///\return The created row.
827 ///\bug This is a temportary function. The interface will change to
829 Row addRow(Value l,const Expr &e, Value u) {
835 ///Add a new row (i.e a new constraint) to the LP
837 ///\param c is a linear expression (see \ref Constr)
838 ///\return The created row.
839 Row addRow(const Constr &c) {
844 ///Erase a coloumn (i.e a variable) from the LP
846 ///\param c is the coloumn to be deleted
847 ///\todo Please check this
848 void eraseCol(Col c) {
849 _eraseCol(cols.floatingId(c.id));
852 ///Erase a row (i.e a constraint) from the LP
854 ///\param r is the row to be deleted
855 ///\todo Please check this
856 void eraseRow(Row r) {
857 _eraseRow(rows.floatingId(r.id));
861 ///Set an element of the coefficient matrix of the LP
863 ///\param r is the row of the element to be modified
864 ///\param c is the coloumn of the element to be modified
865 ///\param val is the new value of the coefficient
866 void setCoeff(Row r, Col c, Value val){
867 _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
870 /// Set the lower bound of a column (i.e a variable)
872 /// The upper bound of a variable (column) has to be given by an
873 /// extended number of type Value, i.e. a finite number of type
874 /// Value or -\ref INF.
875 void colLowerBound(Col c, Value value) {
876 _setColLowerBound(cols.floatingId(c.id),value);
878 /// Set the upper bound of a column (i.e a variable)
880 /// The upper bound of a variable (column) has to be given by an
881 /// extended number of type Value, i.e. a finite number of type
882 /// Value or \ref INF.
883 void colUpperBound(Col c, Value value) {
884 _setColUpperBound(cols.floatingId(c.id),value);
886 /// Set the lower and the upper bounds of a column (i.e a variable)
888 /// The lower and the upper bounds of
889 /// a variable (column) have to be given by an
890 /// extended number of type Value, i.e. a finite number of type
891 /// Value, -\ref INF or \ref INF.
892 void colBounds(Col c, Value lower, Value upper) {
893 _setColLowerBound(cols.floatingId(c.id),lower);
894 _setColUpperBound(cols.floatingId(c.id),upper);
897 // /// Set the lower bound of a row (i.e a constraint)
899 // /// The lower bound of a linear expression (row) has to be given by an
900 // /// extended number of type Value, i.e. a finite number of type
901 // /// Value or -\ref INF.
902 // void rowLowerBound(Row r, Value value) {
903 // _setRowLowerBound(rows.floatingId(r.id),value);
905 // /// Set the upper bound of a row (i.e a constraint)
907 // /// The upper bound of a linear expression (row) has to be given by an
908 // /// extended number of type Value, i.e. a finite number of type
909 // /// Value or \ref INF.
910 // void rowUpperBound(Row r, Value value) {
911 // _setRowUpperBound(rows.floatingId(r.id),value);
914 /// Set the lower and the upper bounds of a row (i.e a constraint)
916 /// The lower and the upper bounds of
917 /// a constraint (row) have to be given by an
918 /// extended number of type Value, i.e. a finite number of type
919 /// Value, -\ref INF or \ref INF.
920 void rowBounds(Row c, Value lower, Value upper) {
921 _setRowBounds(rows.floatingId(c.id),lower, upper);
922 // _setRowUpperBound(rows.floatingId(c.id),upper);
925 ///Set an element of the objective function
926 void objCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); };
927 ///Set the objective function
929 ///\param e is a linear expression of type \ref Expr.
930 ///\bug The previous objective function is not cleared!
931 void setObj(Expr e) {
933 for (Expr::iterator i=e.begin(); i!=e.end(); ++i)
934 objCoeff((*i).first,(*i).second);
935 obj_const_comp=e.constComp();
939 void max() { _setMax(); }
941 void min() { _setMin(); }
947 ///\name Solve the LP
951 ///\e Solve the LP problem at hand
953 ///\return The result of the optimization procedure. Possible values and their meanings can be found in the documentation of \ref SolveExitStatus.
955 ///\todo Which method is used to solve the problem
956 SolveExitStatus solve() { return _solve(); }
960 ///\name Obtain the solution
964 /// The status of the primal problem (the original LP problem)
965 SolutionStatus primalStatus() {
966 return _getPrimalStatus();
969 /// The status of the dual (of the original LP) problem
970 SolutionStatus dualStatus() {
971 return _getDualStatus();
974 ///The type of the original LP problem
975 ProblemTypes problemType() {
976 return _getProblemType();
980 Value primal(Col c) { return _getPrimal(cols.floatingId(c.id)); }
985 ///- \ref INF or -\ref INF means either infeasibility or unboundedness
986 /// of the primal problem, depending on whether we minimize or maximize.
987 ///- \ref NaN if no primal solution is found.
988 ///- The (finite) objective value if an optimal solution is found.
989 Value primalValue() { return _getPrimalValue()+obj_const_comp;}
996 ///\relates LpSolverBase::Expr
998 inline LpSolverBase::Expr operator+(const LpSolverBase::Expr &a,
999 const LpSolverBase::Expr &b)
1001 LpSolverBase::Expr tmp(a);
1007 ///\relates LpSolverBase::Expr
1009 inline LpSolverBase::Expr operator-(const LpSolverBase::Expr &a,
1010 const LpSolverBase::Expr &b)
1012 LpSolverBase::Expr tmp(a);
1018 ///\relates LpSolverBase::Expr
1020 inline LpSolverBase::Expr operator*(const LpSolverBase::Expr &a,
1021 const LpSolverBase::Value &b)
1023 LpSolverBase::Expr tmp(a);
1030 ///\relates LpSolverBase::Expr
1032 inline LpSolverBase::Expr operator*(const LpSolverBase::Value &a,
1033 const LpSolverBase::Expr &b)
1035 LpSolverBase::Expr tmp(b);
1041 ///\relates LpSolverBase::Expr
1043 inline LpSolverBase::Expr operator/(const LpSolverBase::Expr &a,
1044 const LpSolverBase::Value &b)
1046 LpSolverBase::Expr tmp(a);
1053 ///\relates LpSolverBase::Constr
1055 inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e,
1056 const LpSolverBase::Expr &f)
1058 return LpSolverBase::Constr(-LpSolverBase::INF,e-f,0);
1063 ///\relates LpSolverBase::Constr
1065 inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &e,
1066 const LpSolverBase::Expr &f)
1068 return LpSolverBase::Constr(e,f);
1073 ///\relates LpSolverBase::Constr
1075 inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e,
1076 const LpSolverBase::Value &f)
1078 return LpSolverBase::Constr(e,f);
1083 ///\relates LpSolverBase::Constr
1085 inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e,
1086 const LpSolverBase::Expr &f)
1088 return LpSolverBase::Constr(-LpSolverBase::INF,f-e,0);
1094 ///\relates LpSolverBase::Constr
1096 inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &e,
1097 const LpSolverBase::Expr &f)
1099 return LpSolverBase::Constr(f,e);
1105 ///\relates LpSolverBase::Constr
1107 inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e,
1108 const LpSolverBase::Value &f)
1110 return LpSolverBase::Constr(f,e);
1115 ///\relates LpSolverBase::Constr
1117 inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e,
1118 const LpSolverBase::Expr &f)
1120 return LpSolverBase::Constr(0,e-f,0);
1125 ///\relates LpSolverBase::Constr
1127 inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &n,
1128 const LpSolverBase::Constr&c)
1130 LpSolverBase::Constr tmp(c);
1131 ///\todo Create an own exception type.
1132 if(!isnan(tmp.lowerBound())) throw LogicError();
1133 else tmp.lowerBound()=n;
1138 ///\relates LpSolverBase::Constr
1140 inline LpSolverBase::Constr operator<=(const LpSolverBase::Constr& c,
1141 const LpSolverBase::Value &n)
1143 LpSolverBase::Constr tmp(c);
1144 ///\todo Create an own exception type.
1145 if(!isnan(tmp.upperBound())) throw LogicError();
1146 else tmp.upperBound()=n;
1152 ///\relates LpSolverBase::Constr
1154 inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &n,
1155 const LpSolverBase::Constr&c)
1157 LpSolverBase::Constr tmp(c);
1158 ///\todo Create an own exception type.
1159 if(!isnan(tmp.upperBound())) throw LogicError();
1160 else tmp.upperBound()=n;
1165 ///\relates LpSolverBase::Constr
1167 inline LpSolverBase::Constr operator>=(const LpSolverBase::Constr& c,
1168 const LpSolverBase::Value &n)
1170 LpSolverBase::Constr tmp(c);
1171 ///\todo Create an own exception type.
1172 if(!isnan(tmp.lowerBound())) throw LogicError();
1173 else tmp.lowerBound()=n;
1179 ///\relates LpSolverBase::DualExpr
1181 inline LpSolverBase::DualExpr operator+(const LpSolverBase::DualExpr &a,
1182 const LpSolverBase::DualExpr &b)
1184 LpSolverBase::DualExpr tmp(a);
1190 ///\relates LpSolverBase::DualExpr
1192 inline LpSolverBase::DualExpr operator-(const LpSolverBase::DualExpr &a,
1193 const LpSolverBase::DualExpr &b)
1195 LpSolverBase::DualExpr tmp(a);
1201 ///\relates LpSolverBase::DualExpr
1203 inline LpSolverBase::DualExpr operator*(const LpSolverBase::DualExpr &a,
1204 const LpSolverBase::Value &b)
1206 LpSolverBase::DualExpr tmp(a);
1213 ///\relates LpSolverBase::DualExpr
1215 inline LpSolverBase::DualExpr operator*(const LpSolverBase::Value &a,
1216 const LpSolverBase::DualExpr &b)
1218 LpSolverBase::DualExpr tmp(b);
1224 ///\relates LpSolverBase::DualExpr
1226 inline LpSolverBase::DualExpr operator/(const LpSolverBase::DualExpr &a,
1227 const LpSolverBase::Value &b)
1229 LpSolverBase::DualExpr tmp(a);
1237 #endif //LEMON_LP_BASE_H