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