lemon/lp_base.h
author athos
Thu, 26 May 2005 15:33:16 +0000
changeset 1438 826bdac3525a
parent 1435 8e85e6bbefdf
child 1439 2c43106bef85
permissions -rw-r--r--
Some documentation got revised.
athos@1247
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * lemon/lp_base.h - Part of LEMON, a generic C++ optimization library
athos@1247
     3
 *
athos@1247
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
athos@1247
     6
 *
athos@1247
     7
 * Permission to use, modify and distribute this software is granted
athos@1247
     8
 * provided that this copyright notice appears in all copies. For
athos@1247
     9
 * precise terms see the accompanying LICENSE file.
athos@1247
    10
 *
athos@1247
    11
 * This software is provided "AS IS" with no warranty of any kind,
athos@1247
    12
 * express or implied, and with no claim as to its suitability for any
athos@1247
    13
 * purpose.
athos@1247
    14
 *
athos@1247
    15
 */
athos@1247
    16
athos@1246
    17
#ifndef LEMON_LP_BASE_H
athos@1246
    18
#define LEMON_LP_BASE_H
athos@1246
    19
alpar@1253
    20
#include<vector>
alpar@1272
    21
#include<map>
alpar@1256
    22
#include<limits>
alpar@1397
    23
#include<cmath>
alpar@1253
    24
alpar@1256
    25
#include<lemon/utility.h>
alpar@1253
    26
#include<lemon/error.h>
alpar@1256
    27
#include<lemon/invalid.h>
alpar@1253
    28
alpar@1272
    29
//#include"lin_expr.h"
alpar@1272
    30
athos@1246
    31
///\file
athos@1246
    32
///\brief The interface of the LP solver interface.
alpar@1328
    33
///\ingroup gen_opt_group
athos@1246
    34
namespace lemon {
alpar@1253
    35
  
alpar@1253
    36
  ///Internal data structure to convert floating id's to fix one's
alpar@1253
    37
    
alpar@1279
    38
  ///\todo This might be implemented to be also usable in other places.
alpar@1253
    39
  class _FixId 
alpar@1253
    40
  {
alpar@1253
    41
    std::vector<int> index;
alpar@1253
    42
    std::vector<int> cross;
alpar@1253
    43
    int first_free;
alpar@1253
    44
  public:
alpar@1253
    45
    _FixId() : first_free(-1) {};
alpar@1253
    46
    ///Convert a floating id to a fix one
alpar@1253
    47
alpar@1253
    48
    ///\param n is a floating id
alpar@1253
    49
    ///\return the corresponding fix id
alpar@1253
    50
    int fixId(int n) {return cross[n];}
alpar@1253
    51
    ///Convert a fix id to a floating one
alpar@1253
    52
alpar@1253
    53
    ///\param n is a fix id
alpar@1253
    54
    ///\return the corresponding floating id
alpar@1253
    55
    int floatingId(int n) { return index[n];}
alpar@1253
    56
    ///Add a new floating id.
alpar@1253
    57
alpar@1253
    58
    ///\param n is a floating id
alpar@1253
    59
    ///\return the fix id of the new value
alpar@1253
    60
    ///\todo Multiple additions should also be handled.
alpar@1253
    61
    int insert(int n)
alpar@1253
    62
    {
alpar@1253
    63
      if(n>=int(cross.size())) {
alpar@1253
    64
	cross.resize(n+1);
alpar@1253
    65
	if(first_free==-1) {
alpar@1253
    66
	  cross[n]=index.size();
alpar@1253
    67
	  index.push_back(n);
alpar@1253
    68
	}
alpar@1253
    69
	else {
alpar@1253
    70
	  cross[n]=first_free;
alpar@1253
    71
	  int next=index[first_free];
alpar@1253
    72
	  index[first_free]=n;
alpar@1253
    73
	  first_free=next;
alpar@1253
    74
	}
alpar@1256
    75
	return cross[n];
alpar@1253
    76
      }
alpar@1273
    77
      ///\todo Create an own exception type.
alpar@1253
    78
      else throw LogicError(); //floatingId-s must form a continuous range;
alpar@1253
    79
    }
alpar@1253
    80
    ///Remove a fix id.
alpar@1253
    81
alpar@1253
    82
    ///\param n is a fix id
alpar@1253
    83
    ///
alpar@1253
    84
    void erase(int n) 
alpar@1253
    85
    {
alpar@1253
    86
      int fl=index[n];
alpar@1253
    87
      index[n]=first_free;
alpar@1253
    88
      first_free=n;
alpar@1253
    89
      for(int i=fl+1;i<int(cross.size());++i) {
alpar@1253
    90
	cross[i-1]=cross[i];
alpar@1253
    91
	index[cross[i]]--;
alpar@1253
    92
      }
alpar@1253
    93
      cross.pop_back();
alpar@1253
    94
    }
alpar@1253
    95
    ///An upper bound on the largest fix id.
alpar@1253
    96
alpar@1253
    97
    ///\todo Do we need this?
alpar@1253
    98
    ///
alpar@1253
    99
    std::size_t maxFixId() { return cross.size()-1; }
alpar@1253
   100
  
alpar@1253
   101
  };
alpar@1253
   102
    
alpar@1253
   103
  ///Common base class for LP solvers
alpar@1328
   104
  
alpar@1328
   105
  ///\todo Much more docs
alpar@1328
   106
  ///\ingroup gen_opt_group
athos@1246
   107
  class LpSolverBase {
alpar@1323
   108
athos@1247
   109
  public:
athos@1247
   110
alpar@1263
   111
    ///\e
alpar@1303
   112
    enum SolveExitStatus {
alpar@1263
   113
      ///\e
alpar@1293
   114
      SOLVED = 0,
alpar@1263
   115
      ///\e
alpar@1293
   116
      UNSOLVED = 1
athos@1291
   117
    };
athos@1291
   118
      
athos@1291
   119
    ///\e
alpar@1303
   120
    enum SolutionStatus {
alpar@1295
   121
      ///Feasible solution has'n been found (but may exist).
alpar@1295
   122
alpar@1295
   123
      ///\todo NOTFOUND might be a better name.
alpar@1295
   124
      ///
alpar@1293
   125
      UNDEFINED = 0,
alpar@1295
   126
      ///The problem has no feasible solution
alpar@1293
   127
      INFEASIBLE = 1,
alpar@1295
   128
      ///Feasible solution found
alpar@1293
   129
      FEASIBLE = 2,
alpar@1295
   130
      ///Optimal solution exists and found
alpar@1295
   131
      OPTIMAL = 3,
alpar@1295
   132
      ///The cost function is unbounded
alpar@1295
   133
alpar@1295
   134
      ///\todo Give a feasible solution and an infinite ray (and the
alpar@1295
   135
      ///corresponding bases)
alpar@1295
   136
      INFINITE = 4
alpar@1263
   137
    };
alpar@1263
   138
      
alpar@1256
   139
    ///The floating point type used by the solver
athos@1247
   140
    typedef double Value;
alpar@1256
   141
    ///The infinity constant
athos@1247
   142
    static const Value INF;
alpar@1264
   143
    ///The not a number constant
alpar@1264
   144
    static const Value NaN;
alpar@1253
   145
    
alpar@1256
   146
    ///Refer to a column of the LP.
alpar@1256
   147
alpar@1256
   148
    ///This type is used to refer to a column of the LP.
alpar@1256
   149
    ///
alpar@1256
   150
    ///Its value remains valid and correct even after the addition or erase of
alpar@1273
   151
    ///other columns.
alpar@1256
   152
    ///
alpar@1256
   153
    ///\todo Document what can one do with a Col (INVALID, comparing,
alpar@1256
   154
    ///it is similar to Node/Edge)
alpar@1256
   155
    class Col {
alpar@1256
   156
    protected:
alpar@1256
   157
      int id;
alpar@1256
   158
      friend class LpSolverBase;
alpar@1256
   159
    public:
alpar@1259
   160
      typedef Value ExprValue;
alpar@1256
   161
      typedef True LpSolverCol;
alpar@1256
   162
      Col() {}
alpar@1256
   163
      Col(const Invalid&) : id(-1) {}
alpar@1256
   164
      bool operator<(Col c) const  {return id<c.id;}
alpar@1256
   165
      bool operator==(Col c) const  {return id==c.id;}
alpar@1256
   166
      bool operator!=(Col c) const  {return id==c.id;}
alpar@1256
   167
    };
alpar@1256
   168
alpar@1256
   169
    ///Refer to a row of the LP.
alpar@1256
   170
alpar@1256
   171
    ///This type is used to refer to a row of the LP.
alpar@1256
   172
    ///
alpar@1256
   173
    ///Its value remains valid and correct even after the addition or erase of
alpar@1273
   174
    ///other rows.
alpar@1256
   175
    ///
alpar@1256
   176
    ///\todo Document what can one do with a Row (INVALID, comparing,
alpar@1256
   177
    ///it is similar to Node/Edge)
alpar@1256
   178
    class Row {
alpar@1256
   179
    protected:
alpar@1256
   180
      int id;
alpar@1256
   181
      friend class LpSolverBase;
alpar@1256
   182
    public:
alpar@1259
   183
      typedef Value ExprValue;
alpar@1256
   184
      typedef True LpSolverRow;
alpar@1256
   185
      Row() {}
alpar@1256
   186
      Row(const Invalid&) : id(-1) {}
alpar@1256
   187
      typedef True LpSolverRow;
alpar@1256
   188
      bool operator<(Row c) const  {return id<c.id;}
alpar@1256
   189
      bool operator==(Row c) const  {return id==c.id;}
alpar@1256
   190
      bool operator!=(Row c) const  {return id==c.id;} 
alpar@1256
   191
   };
alpar@1259
   192
    
alpar@1279
   193
    ///Linear expression of variables and a constant component
alpar@1279
   194
    
alpar@1279
   195
    ///This data structure strores a linear expression of the variables
alpar@1279
   196
    ///(\ref Col "Col"s) and also has a constant component.
alpar@1279
   197
    ///
alpar@1279
   198
    ///There are several ways to access and modify the contents of this
alpar@1279
   199
    ///container.
alpar@1279
   200
    ///- Its it fully compatible with \c std::map<Col,double>, so for expamle
alpar@1364
   201
    ///if \c e is an Expr and \c v and \c w are of type \ref Col, then you can
alpar@1279
   202
    ///read and modify the coefficients like
alpar@1279
   203
    ///these.
alpar@1279
   204
    ///\code
alpar@1279
   205
    ///e[v]=5;
alpar@1279
   206
    ///e[v]+=12;
alpar@1279
   207
    ///e.erase(v);
alpar@1279
   208
    ///\endcode
alpar@1279
   209
    ///or you can also iterate through its elements.
alpar@1279
   210
    ///\code
alpar@1279
   211
    ///double s=0;
alpar@1279
   212
    ///for(LpSolverBase::Expr::iterator i=e.begin();i!=e.end();++i)
alpar@1279
   213
    ///  s+=i->second;
alpar@1279
   214
    ///\endcode
alpar@1279
   215
    ///(This code computes the sum of all coefficients).
alpar@1279
   216
    ///- Numbers (<tt>double</tt>'s)
alpar@1279
   217
    ///and variables (\ref Col "Col"s) directly convert to an
alpar@1279
   218
    ///\ref Expr and the usual linear operations are defined so  
alpar@1279
   219
    ///\code
alpar@1279
   220
    ///v+w
alpar@1279
   221
    ///2*v-3.12*(v-w/2)+2
alpar@1279
   222
    ///v*2.1+(3*v+(v*12+w+6)*3)/2
alpar@1279
   223
    ///\endcode
alpar@1328
   224
    ///are valid \ref Expr "Expr"essions.
alpar@1328
   225
    ///The usual assignment operations are also defined.
alpar@1279
   226
    ///\code
alpar@1279
   227
    ///e=v+w;
alpar@1279
   228
    ///e+=2*v-3.12*(v-w/2)+2;
alpar@1279
   229
    ///e*=3.4;
alpar@1279
   230
    ///e/=5;
alpar@1279
   231
    ///\endcode
alpar@1279
   232
    ///- The constant member can be set and read by \ref constComp()
alpar@1279
   233
    ///\code
alpar@1279
   234
    ///e.constComp()=12;
alpar@1279
   235
    ///double c=e.constComp();
alpar@1279
   236
    ///\endcode
alpar@1279
   237
    ///
alpar@1328
   238
    ///\note \ref clear() not only sets all coefficients to 0 but also
alpar@1279
   239
    ///clears the constant components.
alpar@1328
   240
    ///
alpar@1328
   241
    ///\sa Constr
alpar@1328
   242
    ///
alpar@1273
   243
    class Expr : public std::map<Col,Value>
alpar@1272
   244
    {
alpar@1272
   245
    public:
alpar@1273
   246
      typedef LpSolverBase::Col Key; 
alpar@1273
   247
      typedef LpSolverBase::Value Value;
alpar@1272
   248
      
alpar@1272
   249
    protected:
alpar@1273
   250
      typedef std::map<Col,Value> Base;
alpar@1272
   251
      
alpar@1273
   252
      Value const_comp;
alpar@1272
   253
  public:
alpar@1272
   254
      typedef True IsLinExpression;
alpar@1272
   255
      ///\e
alpar@1272
   256
      Expr() : Base(), const_comp(0) { }
alpar@1272
   257
      ///\e
alpar@1273
   258
      Expr(const Key &v) : const_comp(0) {
alpar@1272
   259
	Base::insert(std::make_pair(v, 1));
alpar@1272
   260
      }
alpar@1272
   261
      ///\e
alpar@1273
   262
      Expr(const Value &v) : const_comp(v) {}
alpar@1272
   263
      ///\e
alpar@1273
   264
      void set(const Key &v,const Value &c) {
alpar@1272
   265
	Base::insert(std::make_pair(v, c));
alpar@1272
   266
      }
alpar@1272
   267
      ///\e
alpar@1273
   268
      Value &constComp() { return const_comp; }
alpar@1272
   269
      ///\e
alpar@1273
   270
      const Value &constComp() const { return const_comp; }
alpar@1272
   271
      
alpar@1272
   272
      ///Removes the components with zero coefficient.
alpar@1272
   273
      void simplify() {
alpar@1272
   274
	for (Base::iterator i=Base::begin(); i!=Base::end();) {
alpar@1272
   275
	  Base::iterator j=i;
alpar@1272
   276
	  ++j;
alpar@1272
   277
	  if ((*i).second==0) Base::erase(i);
alpar@1272
   278
	  j=i;
alpar@1272
   279
	}
alpar@1272
   280
      }
alpar@1273
   281
alpar@1273
   282
      ///Sets all coefficients and the constant component to 0.
alpar@1273
   283
      void clear() {
alpar@1273
   284
	Base::clear();
alpar@1273
   285
	const_comp=0;
alpar@1273
   286
      }
alpar@1273
   287
alpar@1272
   288
      ///\e
alpar@1272
   289
      Expr &operator+=(const Expr &e) {
alpar@1272
   290
	for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
alpar@1272
   291
	  (*this)[j->first]+=j->second;
alpar@1272
   292
	///\todo it might be speeded up using "hints"
alpar@1272
   293
	const_comp+=e.const_comp;
alpar@1272
   294
	return *this;
alpar@1272
   295
      }
alpar@1272
   296
      ///\e
alpar@1272
   297
      Expr &operator-=(const Expr &e) {
alpar@1272
   298
	for (Base::const_iterator j=e.begin(); j!=e.end(); ++j)
alpar@1272
   299
	  (*this)[j->first]-=j->second;
alpar@1272
   300
	const_comp-=e.const_comp;
alpar@1272
   301
	return *this;
alpar@1272
   302
      }
alpar@1272
   303
      ///\e
alpar@1273
   304
      Expr &operator*=(const Value &c) {
alpar@1272
   305
	for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
alpar@1272
   306
	  j->second*=c;
alpar@1272
   307
	const_comp*=c;
alpar@1272
   308
	return *this;
alpar@1272
   309
      }
alpar@1272
   310
      ///\e
alpar@1273
   311
      Expr &operator/=(const Value &c) {
alpar@1272
   312
	for (Base::iterator j=Base::begin(); j!=Base::end(); ++j)
alpar@1272
   313
	  j->second/=c;
alpar@1272
   314
	const_comp/=c;
alpar@1272
   315
	return *this;
alpar@1272
   316
      }
alpar@1272
   317
    };
alpar@1272
   318
    
alpar@1264
   319
    ///Linear constraint
alpar@1328
   320
alpar@1364
   321
    ///This data stucture represents a linear constraint in the LP.
alpar@1364
   322
    ///Basically it is a linear expression with a lower or an upper bound
alpar@1364
   323
    ///(or both). These parts of the constraint can be obtained by the member
alpar@1364
   324
    ///functions \ref expr(), \ref lowerBound() and \ref upperBound(),
alpar@1364
   325
    ///respectively.
alpar@1364
   326
    ///There are two ways to construct a constraint.
alpar@1364
   327
    ///- You can set the linear expression and the bounds directly
alpar@1364
   328
    ///  by the functions above.
alpar@1364
   329
    ///- The operators <tt>\<=</tt>, <tt>==</tt> and  <tt>\>=</tt>
alpar@1364
   330
    ///  are defined between expressions, or even between constraints whenever
alpar@1364
   331
    ///  it makes sense. Therefore if \c e and \c f are linear expressions and
alpar@1364
   332
    ///  \c s and \c t are numbers, then the followings are valid expressions
alpar@1364
   333
    ///  and thus they can be used directly e.g. in \ref addRow() whenever
alpar@1364
   334
    ///  it makes sense.
alpar@1364
   335
    ///  \code
alpar@1364
   336
    ///  e<=s
alpar@1364
   337
    ///  e<=f
alpar@1364
   338
    ///  s<=e<=t
alpar@1364
   339
    ///  e>=t
alpar@1364
   340
    ///  \endcode
alpar@1364
   341
    ///\warning The validity of a constraint is checked only at run time, so
alpar@1364
   342
    ///e.g. \ref addRow(<tt>x[1]\<=x[2]<=5</tt>) will compile, but will throw a
alpar@1364
   343
    ///\ref LogicError exception.
alpar@1272
   344
    class Constr
alpar@1272
   345
    {
alpar@1272
   346
    public:
alpar@1272
   347
      typedef LpSolverBase::Expr Expr;
alpar@1273
   348
      typedef Expr::Key Key;
alpar@1273
   349
      typedef Expr::Value Value;
alpar@1272
   350
      
alpar@1364
   351
//       static const Value INF;
alpar@1364
   352
//       static const Value NaN;
alpar@1364
   353
alpar@1273
   354
    protected:
alpar@1273
   355
      Expr _expr;
alpar@1273
   356
      Value _lb,_ub;
alpar@1273
   357
    public:
alpar@1273
   358
      ///\e
alpar@1273
   359
      Constr() : _expr(), _lb(NaN), _ub(NaN) {}
alpar@1273
   360
      ///\e
alpar@1273
   361
      Constr(Value lb,const Expr &e,Value ub) :
alpar@1273
   362
	_expr(e), _lb(lb), _ub(ub) {}
alpar@1273
   363
      ///\e
alpar@1273
   364
      Constr(const Expr &e,Value ub) : 
alpar@1273
   365
	_expr(e), _lb(NaN), _ub(ub) {}
alpar@1273
   366
      ///\e
alpar@1273
   367
      Constr(Value lb,const Expr &e) :
alpar@1273
   368
	_expr(e), _lb(lb), _ub(NaN) {}
alpar@1273
   369
      ///\e
alpar@1272
   370
      Constr(const Expr &e) : 
alpar@1273
   371
	_expr(e), _lb(NaN), _ub(NaN) {}
alpar@1273
   372
      ///\e
alpar@1273
   373
      void clear() 
alpar@1273
   374
      {
alpar@1273
   375
	_expr.clear();
alpar@1273
   376
	_lb=_ub=NaN;
alpar@1273
   377
      }
alpar@1364
   378
alpar@1364
   379
      ///Reference to the linear expression 
alpar@1273
   380
      Expr &expr() { return _expr; }
alpar@1364
   381
      ///Cont reference to the linear expression 
alpar@1273
   382
      const Expr &expr() const { return _expr; }
alpar@1364
   383
      ///Reference to the lower bound.
alpar@1364
   384
alpar@1364
   385
      ///\return
alpar@1364
   386
      ///- -\ref INF: the constraint is lower unbounded.
alpar@1364
   387
      ///- -\ref NaN: lower bound has not been set.
alpar@1364
   388
      ///- finite number: the lower bound
alpar@1273
   389
      Value &lowerBound() { return _lb; }
alpar@1364
   390
      ///The const version of \ref lowerBound()
alpar@1273
   391
      const Value &lowerBound() const { return _lb; }
alpar@1364
   392
      ///Reference to the upper bound.
alpar@1364
   393
alpar@1364
   394
      ///\return
alpar@1364
   395
      ///- -\ref INF: the constraint is upper unbounded.
alpar@1364
   396
      ///- -\ref NaN: upper bound has not been set.
alpar@1364
   397
      ///- finite number: the upper bound
alpar@1273
   398
      Value &upperBound() { return _ub; }
alpar@1364
   399
      ///The const version of \ref upperBound()
alpar@1273
   400
      const Value &upperBound() const { return _ub; }
alpar@1364
   401
      ///Is the constraint lower bounded?
alpar@1295
   402
      bool lowerBounded() const { 
alpar@1295
   403
	using namespace std;
alpar@1397
   404
	return finite(_lb);
alpar@1295
   405
      }
alpar@1364
   406
      ///Is the constraint upper bounded?
alpar@1295
   407
      bool upperBounded() const {
alpar@1295
   408
	using namespace std;
alpar@1397
   409
	return finite(_ub);
alpar@1295
   410
      }
alpar@1272
   411
    };
alpar@1272
   412
    
alpar@1253
   413
alpar@1253
   414
  protected:
alpar@1253
   415
    _FixId rows;
alpar@1253
   416
    _FixId cols;
athos@1246
   417
alpar@1323
   418
    //Abstract virtual functions
alpar@1364
   419
    virtual LpSolverBase &_newLp() = 0;
athos@1436
   420
    virtual LpSolverBase &_copyLp(){
athos@1436
   421
      ///\todo This should be implemented here, too,  when we have problem retrieving routines. It can be overriden.
athos@1436
   422
athos@1436
   423
      //Starting:
athos@1436
   424
      LpSolverBase & newlp(_newLp());
athos@1436
   425
      return newlp;
athos@1436
   426
      //return *(LpSolverBase*)0;
athos@1436
   427
    };
alpar@1364
   428
athos@1246
   429
    virtual int _addCol() = 0;
athos@1246
   430
    virtual int _addRow() = 0;
athos@1246
   431
    virtual void _setRowCoeffs(int i, 
athos@1251
   432
			       int length,
athos@1247
   433
                               int  const * indices, 
athos@1247
   434
                               Value  const * values ) = 0;
athos@1246
   435
    virtual void _setColCoeffs(int i, 
athos@1251
   436
			       int length,
athos@1247
   437
                               int  const * indices, 
athos@1247
   438
                               Value  const * values ) = 0;
athos@1431
   439
    virtual void _setCoeff(int row, int col, Value value) = 0;
alpar@1294
   440
    virtual void _setColLowerBound(int i, Value value) = 0;
alpar@1294
   441
    virtual void _setColUpperBound(int i, Value value) = 0;
athos@1405
   442
//     virtual void _setRowLowerBound(int i, Value value) = 0;
athos@1405
   443
//     virtual void _setRowUpperBound(int i, Value value) = 0;
athos@1379
   444
    virtual void _setRowBounds(int i, Value lower, Value upper) = 0;
alpar@1294
   445
    virtual void _setObjCoeff(int i, Value obj_coef) = 0;
athos@1377
   446
    virtual void _clearObj()=0;
athos@1377
   447
//     virtual void _setObj(int length,
athos@1377
   448
//                          int  const * indices, 
athos@1377
   449
//                          Value  const * values ) = 0;
alpar@1303
   450
    virtual SolveExitStatus _solve() = 0;
alpar@1294
   451
    virtual Value _getPrimal(int i) = 0;
alpar@1312
   452
    virtual Value _getPrimalValue() = 0;
alpar@1312
   453
    virtual SolutionStatus _getPrimalStatus() = 0;
alpar@1312
   454
    virtual void _setMax() = 0;
alpar@1312
   455
    virtual void _setMin() = 0;
alpar@1312
   456
    
alpar@1323
   457
    //Own protected stuff
alpar@1323
   458
    
alpar@1323
   459
    //Constant component of the objective function
alpar@1323
   460
    Value obj_const_comp;
alpar@1323
   461
    
athos@1377
   462
athos@1377
   463
alpar@1323
   464
    
alpar@1253
   465
  public:
alpar@1253
   466
alpar@1323
   467
    ///\e
alpar@1323
   468
    LpSolverBase() : obj_const_comp(0) {}
alpar@1253
   469
alpar@1253
   470
    ///\e
alpar@1253
   471
    virtual ~LpSolverBase() {}
alpar@1253
   472
alpar@1364
   473
    ///Creates a new LP problem
alpar@1364
   474
    LpSolverBase &newLp() {return _newLp();}
alpar@1381
   475
    ///Makes a copy of the LP problem
alpar@1364
   476
    LpSolverBase &copyLp() {return _copyLp();}
alpar@1364
   477
    
alpar@1294
   478
    ///\name Build up and modify of the LP
alpar@1263
   479
alpar@1263
   480
    ///@{
alpar@1263
   481
alpar@1253
   482
    ///Add a new empty column (i.e a new variable) to the LP
alpar@1253
   483
    Col addCol() { Col c; c.id=cols.insert(_addCol()); return c;}
alpar@1263
   484
alpar@1294
   485
    ///\brief Adds several new columns
alpar@1294
   486
    ///(i.e a variables) at once
alpar@1256
   487
    ///
alpar@1273
   488
    ///This magic function takes a container as its argument
alpar@1256
   489
    ///and fills its elements
alpar@1256
   490
    ///with new columns (i.e. variables)
alpar@1273
   491
    ///\param t can be
alpar@1273
   492
    ///- a standard STL compatible iterable container with
alpar@1273
   493
    ///\ref Col as its \c values_type
alpar@1273
   494
    ///like
alpar@1273
   495
    ///\code
alpar@1273
   496
    ///std::vector<LpSolverBase::Col>
alpar@1273
   497
    ///std::list<LpSolverBase::Col>
alpar@1273
   498
    ///\endcode
alpar@1273
   499
    ///- a standard STL compatible iterable container with
alpar@1273
   500
    ///\ref Col as its \c mapped_type
alpar@1273
   501
    ///like
alpar@1273
   502
    ///\code
alpar@1364
   503
    ///std::map<AnyType,LpSolverBase::Col>
alpar@1273
   504
    ///\endcode
alpar@1273
   505
    ///- an iterable lemon \ref concept::WriteMap "write map" like 
alpar@1273
   506
    ///\code
alpar@1273
   507
    ///ListGraph::NodeMap<LpSolverBase::Col>
alpar@1273
   508
    ///ListGraph::EdgeMap<LpSolverBase::Col>
alpar@1273
   509
    ///\endcode
alpar@1256
   510
    ///\return The number of the created column.
alpar@1256
   511
#ifdef DOXYGEN
alpar@1256
   512
    template<class T>
alpar@1256
   513
    int addColSet(T &t) { return 0;} 
alpar@1256
   514
#else
alpar@1256
   515
    template<class T>
alpar@1256
   516
    typename enable_if<typename T::value_type::LpSolverCol,int>::type
alpar@1256
   517
    addColSet(T &t,dummy<0> = 0) {
alpar@1256
   518
      int s=0;
alpar@1256
   519
      for(typename T::iterator i=t.begin();i!=t.end();++i) {*i=addCol();s++;}
alpar@1256
   520
      return s;
alpar@1256
   521
    }
alpar@1256
   522
    template<class T>
alpar@1256
   523
    typename enable_if<typename T::value_type::second_type::LpSolverCol,
alpar@1256
   524
		       int>::type
alpar@1256
   525
    addColSet(T &t,dummy<1> = 1) { 
alpar@1256
   526
      int s=0;
alpar@1256
   527
      for(typename T::iterator i=t.begin();i!=t.end();++i) {
alpar@1256
   528
	i->second=addCol();
alpar@1256
   529
	s++;
alpar@1256
   530
      }
alpar@1256
   531
      return s;
alpar@1256
   532
    }
alpar@1272
   533
    template<class T>
alpar@1272
   534
    typename enable_if<typename T::ValueSet::value_type::LpSolverCol,
alpar@1272
   535
		       int>::type
alpar@1272
   536
    addColSet(T &t,dummy<2> = 2) { 
alpar@1272
   537
      ///\bug <tt>return addColSet(t.valueSet());</tt> should also work.
alpar@1272
   538
      int s=0;
alpar@1272
   539
      for(typename T::ValueSet::iterator i=t.valueSet().begin();
alpar@1272
   540
	  i!=t.valueSet().end();
alpar@1272
   541
	  ++i)
alpar@1272
   542
	{
alpar@1272
   543
	  *i=addCol();
alpar@1272
   544
	  s++;
alpar@1272
   545
	}
alpar@1272
   546
      return s;
alpar@1272
   547
    }
alpar@1256
   548
#endif
alpar@1263
   549
alpar@1253
   550
    ///Add a new empty row (i.e a new constaint) to the LP
alpar@1258
   551
alpar@1258
   552
    ///This function adds a new empty row (i.e a new constaint) to the LP.
alpar@1258
   553
    ///\return The created row
alpar@1253
   554
    Row addRow() { Row r; r.id=rows.insert(_addRow()); return r;}
alpar@1253
   555
alpar@1258
   556
    ///Set a row (i.e a constaint) of the LP
alpar@1253
   557
alpar@1258
   558
    ///\param r is the row to be modified
alpar@1259
   559
    ///\param l is lower bound (-\ref INF means no bound)
alpar@1258
   560
    ///\param e is a linear expression (see \ref Expr)
alpar@1259
   561
    ///\param u is the upper bound (\ref INF means no bound)
alpar@1253
   562
    ///\bug This is a temportary function. The interface will change to
alpar@1253
   563
    ///a better one.
alpar@1328
   564
    ///\todo Option to control whether a constraint with a single variable is
alpar@1328
   565
    ///added or not.
alpar@1258
   566
    void setRow(Row r, Value l,const Expr &e, Value u) {
alpar@1253
   567
      std::vector<int> indices;
alpar@1253
   568
      std::vector<Value> values;
alpar@1253
   569
      indices.push_back(0);
alpar@1253
   570
      values.push_back(0);
alpar@1258
   571
      for(Expr::const_iterator i=e.begin(); i!=e.end(); ++i)
alpar@1256
   572
	if((*i).second!=0) { ///\bug EPSILON would be necessary here!!!
alpar@1256
   573
	  indices.push_back(cols.floatingId((*i).first.id));
alpar@1256
   574
	  values.push_back((*i).second);
alpar@1256
   575
	}
alpar@1253
   576
      _setRowCoeffs(rows.floatingId(r.id),indices.size()-1,
alpar@1253
   577
		    &indices[0],&values[0]);
athos@1405
   578
//       _setRowLowerBound(rows.floatingId(r.id),l-e.constComp());
athos@1405
   579
//       _setRowUpperBound(rows.floatingId(r.id),u-e.constComp());
athos@1405
   580
       _setRowBounds(rows.floatingId(r.id),l-e.constComp(),u-e.constComp());
alpar@1258
   581
    }
alpar@1258
   582
alpar@1264
   583
    ///Set a row (i.e a constaint) of the LP
alpar@1264
   584
alpar@1264
   585
    ///\param r is the row to be modified
alpar@1264
   586
    ///\param c is a linear expression (see \ref Constr)
alpar@1264
   587
    void setRow(Row r, const Constr &c) {
alpar@1273
   588
      setRow(r,
alpar@1275
   589
	     c.lowerBounded()?c.lowerBound():-INF,
alpar@1273
   590
	     c.expr(),
alpar@1275
   591
	     c.upperBounded()?c.upperBound():INF);
alpar@1264
   592
    }
alpar@1264
   593
alpar@1258
   594
    ///Add a new row (i.e a new constaint) to the LP
alpar@1258
   595
alpar@1259
   596
    ///\param l is the lower bound (-\ref INF means no bound)
alpar@1258
   597
    ///\param e is a linear expression (see \ref Expr)
alpar@1259
   598
    ///\param u is the upper bound (\ref INF means no bound)
alpar@1258
   599
    ///\return The created row.
alpar@1258
   600
    ///\bug This is a temportary function. The interface will change to
alpar@1258
   601
    ///a better one.
alpar@1258
   602
    Row addRow(Value l,const Expr &e, Value u) {
alpar@1258
   603
      Row r=addRow();
alpar@1258
   604
      setRow(r,l,e,u);
alpar@1253
   605
      return r;
alpar@1253
   606
    }
alpar@1253
   607
alpar@1264
   608
    ///Add a new row (i.e a new constaint) to the LP
alpar@1264
   609
alpar@1264
   610
    ///\param c is a linear expression (see \ref Constr)
alpar@1264
   611
    ///\return The created row.
alpar@1264
   612
    Row addRow(const Constr &c) {
alpar@1264
   613
      Row r=addRow();
alpar@1264
   614
      setRow(r,c);
alpar@1264
   615
      return r;
alpar@1264
   616
    }
alpar@1264
   617
athos@1436
   618
    ///Set an element of the coefficient matrix of the LP
athos@1436
   619
athos@1436
   620
    ///\param r is the row of the element to be modified
athos@1436
   621
    ///\param c is the coloumn of the element to be modified
athos@1436
   622
    ///\param val is the new value of the coefficient
athos@1436
   623
    void setCoeff(Row r, Col c, Value val){
athos@1436
   624
      _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
athos@1436
   625
    }
athos@1436
   626
alpar@1253
   627
    /// Set the lower bound of a column (i.e a variable)
alpar@1253
   628
alpar@1293
   629
    /// The upper bound of a variable (column) has to be given by an 
alpar@1253
   630
    /// extended number of type Value, i.e. a finite number of type 
alpar@1259
   631
    /// Value or -\ref INF.
alpar@1293
   632
    void colLowerBound(Col c, Value value) {
alpar@1253
   633
      _setColLowerBound(cols.floatingId(c.id),value);
alpar@1253
   634
    }
alpar@1253
   635
    /// Set the upper bound of a column (i.e a variable)
alpar@1253
   636
alpar@1293
   637
    /// The upper bound of a variable (column) has to be given by an 
alpar@1253
   638
    /// extended number of type Value, i.e. a finite number of type 
alpar@1259
   639
    /// Value or \ref INF.
alpar@1293
   640
    void colUpperBound(Col c, Value value) {
alpar@1253
   641
      _setColUpperBound(cols.floatingId(c.id),value);
alpar@1253
   642
    };
alpar@1293
   643
    /// Set the lower and the upper bounds of a column (i.e a variable)
alpar@1293
   644
alpar@1293
   645
    /// The lower and the upper bounds of
alpar@1293
   646
    /// a variable (column) have to be given by an 
alpar@1293
   647
    /// extended number of type Value, i.e. a finite number of type 
alpar@1293
   648
    /// Value, -\ref INF or \ref INF.
alpar@1293
   649
    void colBounds(Col c, Value lower, Value upper) {
alpar@1293
   650
      _setColLowerBound(cols.floatingId(c.id),lower);
alpar@1293
   651
      _setColUpperBound(cols.floatingId(c.id),upper);
alpar@1293
   652
    }
alpar@1293
   653
    
athos@1405
   654
//     /// Set the lower bound of a row (i.e a constraint)
alpar@1253
   655
athos@1405
   656
//     /// The lower bound of a linear expression (row) has to be given by an 
athos@1405
   657
//     /// extended number of type Value, i.e. a finite number of type 
athos@1405
   658
//     /// Value or -\ref INF.
athos@1405
   659
//     void rowLowerBound(Row r, Value value) {
athos@1405
   660
//       _setRowLowerBound(rows.floatingId(r.id),value);
athos@1405
   661
//     };
athos@1405
   662
//     /// Set the upper bound of a row (i.e a constraint)
alpar@1253
   663
athos@1405
   664
//     /// The upper bound of a linear expression (row) has to be given by an 
athos@1405
   665
//     /// extended number of type Value, i.e. a finite number of type 
athos@1405
   666
//     /// Value or \ref INF.
athos@1405
   667
//     void rowUpperBound(Row r, Value value) {
athos@1405
   668
//       _setRowUpperBound(rows.floatingId(r.id),value);
athos@1405
   669
//     };
athos@1405
   670
athos@1405
   671
    /// Set the lower and the upper bounds of a row (i.e a constraint)
alpar@1293
   672
alpar@1293
   673
    /// The lower and the upper bounds of
alpar@1293
   674
    /// a constraint (row) have to be given by an 
alpar@1293
   675
    /// extended number of type Value, i.e. a finite number of type 
alpar@1293
   676
    /// Value, -\ref INF or \ref INF.
alpar@1293
   677
    void rowBounds(Row c, Value lower, Value upper) {
athos@1379
   678
      _setRowBounds(rows.floatingId(c.id),lower, upper);
athos@1379
   679
      // _setRowUpperBound(rows.floatingId(c.id),upper);
alpar@1293
   680
    }
alpar@1293
   681
    
alpar@1253
   682
    ///Set an element of the objective function
alpar@1293
   683
    void objCoeff(Col c, Value v) {_setObjCoeff(cols.floatingId(c.id),v); };
alpar@1253
   684
    ///Set the objective function
alpar@1253
   685
    
alpar@1253
   686
    ///\param e is a linear expression of type \ref Expr.
alpar@1323
   687
    ///\bug The previous objective function is not cleared!
alpar@1253
   688
    void setObj(Expr e) {
athos@1377
   689
      _clearObj();
alpar@1253
   690
      for (Expr::iterator i=e.begin(); i!=e.end(); ++i)
alpar@1293
   691
	objCoeff((*i).first,(*i).second);
alpar@1323
   692
      obj_const_comp=e.constComp();
alpar@1253
   693
    }
alpar@1263
   694
alpar@1312
   695
    ///Maximize
alpar@1312
   696
    void max() { _setMax(); }
alpar@1312
   697
    ///Minimize
alpar@1312
   698
    void min() { _setMin(); }
alpar@1312
   699
alpar@1312
   700
    
alpar@1263
   701
    ///@}
alpar@1263
   702
alpar@1263
   703
alpar@1294
   704
    ///\name Solve the LP
alpar@1263
   705
alpar@1263
   706
    ///@{
alpar@1263
   707
alpar@1263
   708
    ///\e
alpar@1303
   709
    SolveExitStatus solve() { return _solve(); }
alpar@1263
   710
    
alpar@1263
   711
    ///@}
alpar@1263
   712
    
alpar@1294
   713
    ///\name Obtain the solution
alpar@1263
   714
alpar@1263
   715
    ///@{
alpar@1263
   716
alpar@1263
   717
    ///\e
alpar@1312
   718
    SolutionStatus primalStatus() {
alpar@1312
   719
      return _getPrimalStatus();
alpar@1294
   720
    }
alpar@1294
   721
alpar@1294
   722
    ///\e
alpar@1293
   723
    Value primal(Col c) { return _getPrimal(cols.floatingId(c.id)); }
alpar@1263
   724
alpar@1312
   725
    ///\e
alpar@1312
   726
alpar@1312
   727
    ///\return
alpar@1312
   728
    ///- \ref INF or -\ref INF means either infeasibility or unboundedness
alpar@1312
   729
    /// of the primal problem, depending on whether we minimize or maximize.
alpar@1364
   730
    ///- \ref NaN if no primal solution is found.
alpar@1312
   731
    ///- The (finite) objective value if an optimal solution is found.
alpar@1323
   732
    Value primalValue() { return _getPrimalValue()+obj_const_comp;}
alpar@1263
   733
    ///@}
alpar@1253
   734
    
athos@1248
   735
  };  
athos@1246
   736
alpar@1272
   737
  ///\e
alpar@1272
   738
  
alpar@1272
   739
  ///\relates LpSolverBase::Expr
alpar@1272
   740
  ///
alpar@1272
   741
  inline LpSolverBase::Expr operator+(const LpSolverBase::Expr &a,
alpar@1272
   742
				      const LpSolverBase::Expr &b) 
alpar@1272
   743
  {
alpar@1272
   744
    LpSolverBase::Expr tmp(a);
alpar@1364
   745
    tmp+=b; ///\todo Doesn't STL have some special 'merge' algorithm?
alpar@1272
   746
    return tmp;
alpar@1272
   747
  }
alpar@1272
   748
  ///\e
alpar@1272
   749
  
alpar@1272
   750
  ///\relates LpSolverBase::Expr
alpar@1272
   751
  ///
alpar@1272
   752
  inline LpSolverBase::Expr operator-(const LpSolverBase::Expr &a,
alpar@1272
   753
				      const LpSolverBase::Expr &b) 
alpar@1272
   754
  {
alpar@1272
   755
    LpSolverBase::Expr tmp(a);
alpar@1364
   756
    tmp-=b; ///\todo Doesn't STL have some special 'merge' algorithm?
alpar@1272
   757
    return tmp;
alpar@1272
   758
  }
alpar@1272
   759
  ///\e
alpar@1272
   760
  
alpar@1272
   761
  ///\relates LpSolverBase::Expr
alpar@1272
   762
  ///
alpar@1272
   763
  inline LpSolverBase::Expr operator*(const LpSolverBase::Expr &a,
alpar@1273
   764
				      const LpSolverBase::Value &b) 
alpar@1272
   765
  {
alpar@1272
   766
    LpSolverBase::Expr tmp(a);
alpar@1364
   767
    tmp*=b; ///\todo Doesn't STL have some special 'merge' algorithm?
alpar@1272
   768
    return tmp;
alpar@1272
   769
  }
alpar@1272
   770
  
alpar@1272
   771
  ///\e
alpar@1272
   772
  
alpar@1272
   773
  ///\relates LpSolverBase::Expr
alpar@1272
   774
  ///
alpar@1273
   775
  inline LpSolverBase::Expr operator*(const LpSolverBase::Value &a,
alpar@1272
   776
				      const LpSolverBase::Expr &b) 
alpar@1272
   777
  {
alpar@1272
   778
    LpSolverBase::Expr tmp(b);
alpar@1364
   779
    tmp*=a; ///\todo Doesn't STL have some special 'merge' algorithm?
alpar@1272
   780
    return tmp;
alpar@1272
   781
  }
alpar@1272
   782
  ///\e
alpar@1272
   783
  
alpar@1272
   784
  ///\relates LpSolverBase::Expr
alpar@1272
   785
  ///
alpar@1272
   786
  inline LpSolverBase::Expr operator/(const LpSolverBase::Expr &a,
alpar@1273
   787
				      const LpSolverBase::Value &b) 
alpar@1272
   788
  {
alpar@1272
   789
    LpSolverBase::Expr tmp(a);
alpar@1364
   790
    tmp/=b; ///\todo Doesn't STL have some special 'merge' algorithm?
alpar@1272
   791
    return tmp;
alpar@1272
   792
  }
alpar@1272
   793
  
alpar@1272
   794
  ///\e
alpar@1272
   795
  
alpar@1272
   796
  ///\relates LpSolverBase::Constr
alpar@1272
   797
  ///
alpar@1272
   798
  inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e,
alpar@1272
   799
					 const LpSolverBase::Expr &f) 
alpar@1272
   800
  {
alpar@1272
   801
    return LpSolverBase::Constr(-LpSolverBase::INF,e-f,0);
alpar@1272
   802
  }
alpar@1272
   803
alpar@1272
   804
  ///\e
alpar@1272
   805
  
alpar@1272
   806
  ///\relates LpSolverBase::Constr
alpar@1272
   807
  ///
alpar@1273
   808
  inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &e,
alpar@1272
   809
					 const LpSolverBase::Expr &f) 
alpar@1272
   810
  {
alpar@1272
   811
    return LpSolverBase::Constr(e,f);
alpar@1272
   812
  }
alpar@1272
   813
alpar@1272
   814
  ///\e
alpar@1272
   815
  
alpar@1272
   816
  ///\relates LpSolverBase::Constr
alpar@1272
   817
  ///
alpar@1272
   818
  inline LpSolverBase::Constr operator<=(const LpSolverBase::Expr &e,
alpar@1273
   819
					 const LpSolverBase::Value &f) 
alpar@1272
   820
  {
alpar@1272
   821
    return LpSolverBase::Constr(e,f);
alpar@1272
   822
  }
alpar@1272
   823
alpar@1272
   824
  ///\e
alpar@1272
   825
  
alpar@1272
   826
  ///\relates LpSolverBase::Constr
alpar@1272
   827
  ///
alpar@1272
   828
  inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e,
alpar@1272
   829
					 const LpSolverBase::Expr &f) 
alpar@1272
   830
  {
alpar@1272
   831
    return LpSolverBase::Constr(-LpSolverBase::INF,f-e,0);
alpar@1272
   832
  }
alpar@1272
   833
alpar@1272
   834
alpar@1272
   835
  ///\e
alpar@1272
   836
  
alpar@1272
   837
  ///\relates LpSolverBase::Constr
alpar@1272
   838
  ///
alpar@1273
   839
  inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &e,
alpar@1272
   840
					 const LpSolverBase::Expr &f) 
alpar@1272
   841
  {
alpar@1272
   842
    return LpSolverBase::Constr(f,e);
alpar@1272
   843
  }
alpar@1272
   844
alpar@1272
   845
alpar@1272
   846
  ///\e
alpar@1272
   847
  
alpar@1272
   848
  ///\relates LpSolverBase::Constr
alpar@1272
   849
  ///
alpar@1272
   850
  inline LpSolverBase::Constr operator>=(const LpSolverBase::Expr &e,
alpar@1273
   851
					 const LpSolverBase::Value &f) 
alpar@1272
   852
  {
alpar@1272
   853
    return LpSolverBase::Constr(f,e);
alpar@1272
   854
  }
alpar@1272
   855
alpar@1272
   856
  ///\e
alpar@1272
   857
  
alpar@1272
   858
  ///\relates LpSolverBase::Constr
alpar@1272
   859
  ///
alpar@1272
   860
  inline LpSolverBase::Constr operator==(const LpSolverBase::Expr &e,
alpar@1272
   861
					 const LpSolverBase::Expr &f) 
alpar@1272
   862
  {
alpar@1272
   863
    return LpSolverBase::Constr(0,e-f,0);
alpar@1272
   864
  }
alpar@1272
   865
alpar@1272
   866
  ///\e
alpar@1272
   867
  
alpar@1272
   868
  ///\relates LpSolverBase::Constr
alpar@1272
   869
  ///
alpar@1273
   870
  inline LpSolverBase::Constr operator<=(const LpSolverBase::Value &n,
alpar@1272
   871
					 const LpSolverBase::Constr&c) 
alpar@1272
   872
  {
alpar@1272
   873
    LpSolverBase::Constr tmp(c);
alpar@1273
   874
    ///\todo Create an own exception type.
alpar@1273
   875
    if(!isnan(tmp.lowerBound())) throw LogicError();
alpar@1273
   876
    else tmp.lowerBound()=n;
alpar@1272
   877
    return tmp;
alpar@1272
   878
  }
alpar@1272
   879
  ///\e
alpar@1272
   880
  
alpar@1272
   881
  ///\relates LpSolverBase::Constr
alpar@1272
   882
  ///
alpar@1272
   883
  inline LpSolverBase::Constr operator<=(const LpSolverBase::Constr& c,
alpar@1273
   884
					 const LpSolverBase::Value &n)
alpar@1272
   885
  {
alpar@1272
   886
    LpSolverBase::Constr tmp(c);
alpar@1273
   887
    ///\todo Create an own exception type.
alpar@1273
   888
    if(!isnan(tmp.upperBound())) throw LogicError();
alpar@1273
   889
    else tmp.upperBound()=n;
alpar@1272
   890
    return tmp;
alpar@1272
   891
  }
alpar@1272
   892
alpar@1272
   893
  ///\e
alpar@1272
   894
  
alpar@1272
   895
  ///\relates LpSolverBase::Constr
alpar@1272
   896
  ///
alpar@1273
   897
  inline LpSolverBase::Constr operator>=(const LpSolverBase::Value &n,
alpar@1272
   898
					 const LpSolverBase::Constr&c) 
alpar@1272
   899
  {
alpar@1272
   900
    LpSolverBase::Constr tmp(c);
alpar@1273
   901
    ///\todo Create an own exception type.
alpar@1273
   902
    if(!isnan(tmp.upperBound())) throw LogicError();
alpar@1273
   903
    else tmp.upperBound()=n;
alpar@1272
   904
    return tmp;
alpar@1272
   905
  }
alpar@1272
   906
  ///\e
alpar@1272
   907
  
alpar@1272
   908
  ///\relates LpSolverBase::Constr
alpar@1272
   909
  ///
alpar@1272
   910
  inline LpSolverBase::Constr operator>=(const LpSolverBase::Constr& c,
alpar@1273
   911
					 const LpSolverBase::Value &n)
alpar@1272
   912
  {
alpar@1272
   913
    LpSolverBase::Constr tmp(c);
alpar@1273
   914
    ///\todo Create an own exception type.
alpar@1273
   915
    if(!isnan(tmp.lowerBound())) throw LogicError();
alpar@1273
   916
    else tmp.lowerBound()=n;
alpar@1272
   917
    return tmp;
alpar@1272
   918
  }
alpar@1272
   919
alpar@1272
   920
athos@1246
   921
} //namespace lemon
athos@1246
   922
athos@1246
   923
#endif //LEMON_LP_BASE_H