COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/lp_base.h @ 2363:2aabce558574

Last change on this file since 2363:2aabce558574 was 2363:2aabce558574, checked in by Balazs Dezso, 13 years ago

Changes on the LP interface

_FixId => LpId?

  • handling of not common ids soplex

LpGlpk? row and col erase bug fix

  • calling lpx_std_basis before simplex

LpSoplex?

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