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