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