src/work/marci/lp/lp_solver_base.h
author alpar
Tue, 15 Feb 2005 15:00:31 +0000
changeset 1150 c20bcf71efe3
parent 1143 4fb22cfa5759
child 1152 1765ff9fefa1
permissions -rw-r--r--
Minor changes.
marci@1031
     1
// -*- c++ -*-
marci@1031
     2
#ifndef LEMON_LP_SOLVER_WRAPPER_H
marci@1031
     3
#define LEMON_LP_SOLVER_WRAPPER_H
marci@1031
     4
marci@1031
     5
///\ingroup misc
marci@1031
     6
///\file
marci@1031
     7
///\brief Dijkstra algorithm.
marci@1031
     8
marci@1031
     9
// #include <stdio.h>
marci@1031
    10
#include <stdlib.h>
marci@1097
    11
#include <iostream>
marci@1097
    12
#include <map>
marci@1104
    13
#include <limits>
marci@1031
    14
// #include <stdio>
marci@1031
    15
//#include <stdlib>
marci@1031
    16
extern "C" {
marci@1031
    17
#include "glpk.h"
marci@1031
    18
}
marci@1031
    19
marci@1031
    20
#include <iostream>
marci@1031
    21
#include <vector>
marci@1031
    22
#include <string>
marci@1031
    23
#include <list>
marci@1031
    24
#include <memory>
marci@1031
    25
#include <utility>
marci@1031
    26
marci@1031
    27
//#include <lemon/list_graph.h>
marci@1031
    28
#include <lemon/invalid.h>
marci@1099
    29
#include <expression.h>
marci@1031
    30
//#include <bfs_dfs.h>
marci@1031
    31
//#include <stp.h>
marci@1031
    32
//#include <lemon/max_flow.h>
marci@1031
    33
//#include <augmenting_flow.h>
marci@1031
    34
//#include <iter_map.h>
marci@1031
    35
marci@1031
    36
using std::cout;
marci@1031
    37
using std::cin;
marci@1031
    38
using std::endl;
marci@1031
    39
marci@1031
    40
namespace lemon {
marci@1031
    41
  
marci@1031
    42
  /// \addtogroup misc
marci@1031
    43
  /// @{
marci@1031
    44
marci@1031
    45
  /// \brief A partitioned vector with iterable classes.
marci@1031
    46
  ///
marci@1031
    47
  /// This class implements a container in which the data is stored in an 
marci@1031
    48
  /// stl vector, the range is partitioned into sets and each set is 
marci@1031
    49
  /// doubly linked in a list. 
marci@1031
    50
  /// That is, each class is iterable by lemon iterators, and any member of 
marci@1031
    51
  /// the vector can bo moved to an other class.
marci@1031
    52
  template <typename T>
marci@1031
    53
  class IterablePartition {
marci@1031
    54
  protected:
marci@1031
    55
    struct Node {
marci@1031
    56
      T data;
marci@1031
    57
      int prev; //invalid az -1
marci@1031
    58
      int next; 
marci@1031
    59
    };
marci@1031
    60
    std::vector<Node> nodes;
marci@1031
    61
    struct Tip {
marci@1031
    62
      int first;
marci@1031
    63
      int last;
marci@1031
    64
    };
marci@1031
    65
    std::vector<Tip> tips;
marci@1031
    66
  public:
marci@1031
    67
    /// The classes are indexed by integers from \c 0 to \c classNum()-1.
marci@1031
    68
    int classNum() const { return tips.size(); }
marci@1031
    69
    /// This lemon style iterator iterates through a class. 
marci@1031
    70
    class ClassIt;
marci@1031
    71
    /// Constructor. The number of classes is to be given which is fixed 
marci@1031
    72
    /// over the life of the container. 
marci@1031
    73
    /// The partition classes are indexed from 0 to class_num-1. 
marci@1031
    74
    IterablePartition(int class_num) { 
marci@1031
    75
      for (int i=0; i<class_num; ++i) {
marci@1031
    76
	Tip t;
marci@1031
    77
	t.first=t.last=-1;
marci@1031
    78
	tips.push_back(t);
marci@1031
    79
      }
marci@1031
    80
    }
marci@1031
    81
  protected:
marci@1031
    82
    void befuz(ClassIt it, int class_id) {
marci@1031
    83
      if (tips[class_id].first==-1) {
marci@1031
    84
	if (tips[class_id].last==-1) {
marci@1031
    85
	  nodes[it.i].prev=nodes[it.i].next=-1;
marci@1031
    86
	  tips[class_id].first=tips[class_id].last=it.i;
marci@1031
    87
	}
marci@1031
    88
      } else {
marci@1031
    89
	nodes[it.i].prev=tips[class_id].last;
marci@1031
    90
	nodes[it.i].next=-1;
marci@1031
    91
	nodes[tips[class_id].last].next=it.i;
marci@1031
    92
	tips[class_id].last=it.i;
marci@1031
    93
      }
marci@1031
    94
    }
marci@1031
    95
    void kifuz(ClassIt it, int class_id) {
marci@1031
    96
      if (tips[class_id].first==it.i) {
marci@1031
    97
	if (tips[class_id].last==it.i) {
marci@1031
    98
	  tips[class_id].first=tips[class_id].last=-1;
marci@1031
    99
	} else {
marci@1031
   100
	  tips[class_id].first=nodes[it.i].next;
marci@1031
   101
	  nodes[nodes[it.i].next].prev=-1;
marci@1031
   102
	}
marci@1031
   103
      } else {
marci@1031
   104
	if (tips[class_id].last==it.i) {
marci@1031
   105
	  tips[class_id].last=nodes[it.i].prev;
marci@1031
   106
	  nodes[nodes[it.i].prev].next=-1;
marci@1031
   107
	} else {
marci@1031
   108
	  nodes[nodes[it.i].next].prev=nodes[it.i].prev;
marci@1031
   109
	  nodes[nodes[it.i].prev].next=nodes[it.i].next;
marci@1031
   110
	}
marci@1031
   111
      }
marci@1031
   112
    }
marci@1031
   113
  public:
marci@1031
   114
    /// A new element with data \c t is pushed into the vector and into class 
marci@1031
   115
    /// \c class_id.
marci@1031
   116
    ClassIt push_back(const T& t, int class_id) { 
marci@1031
   117
      Node n;
marci@1031
   118
      n.data=t;
marci@1031
   119
      nodes.push_back(n);
marci@1031
   120
      int i=nodes.size()-1;
marci@1031
   121
      befuz(i, class_id);
marci@1031
   122
      return i;
marci@1031
   123
    }
marci@1031
   124
    /// A member is moved to an other class.
marci@1031
   125
    void set(ClassIt it, int old_class_id, int new_class_id) {
marci@1031
   126
      kifuz(it.i, old_class_id);
marci@1031
   127
      befuz(it.i, new_class_id);
marci@1031
   128
    }
marci@1031
   129
    /// Returns the data pointed by \c it.
marci@1031
   130
    T& operator[](ClassIt it) { return nodes[it.i].data; }
marci@1031
   131
    /// Returns the data pointed by \c it.
marci@1031
   132
    const T& operator[](ClassIt it) const { return nodes[it.i].data; }
marci@1031
   133
    ///.
marci@1031
   134
    class ClassIt {
marci@1031
   135
      friend class IterablePartition;
marci@1031
   136
    protected:
marci@1031
   137
      int i;
marci@1031
   138
    public:
marci@1031
   139
      /// Default constructor.
marci@1031
   140
      ClassIt() { }
marci@1031
   141
      /// This constructor constructs an iterator which points
marci@1031
   142
      /// to the member of th container indexed by the integer _i.
marci@1031
   143
      ClassIt(const int& _i) : i(_i) { }
marci@1031
   144
      /// Invalid constructor.
marci@1031
   145
      ClassIt(const Invalid&) : i(-1) { }
marci@1099
   146
      friend bool operator<(const ClassIt& x, const ClassIt& y);
marci@1099
   147
      friend std::ostream& operator<<(std::ostream& os, 
marci@1099
   148
				      const ClassIt& it);
marci@1031
   149
    };
marci@1099
   150
    friend bool operator<(const ClassIt& x, const ClassIt& y) {
marci@1099
   151
      return (x.i < y.i);
marci@1099
   152
    }
marci@1099
   153
    friend std::ostream& operator<<(std::ostream& os, 
marci@1099
   154
				    const ClassIt& it) {
marci@1099
   155
      os << it.i;
marci@1099
   156
      return os;
marci@1099
   157
    }
marci@1031
   158
    /// First member of class \c class_id.
marci@1031
   159
    ClassIt& first(ClassIt& it, int class_id) const {
marci@1031
   160
      it.i=tips[class_id].first;
marci@1031
   161
      return it;
marci@1031
   162
    }
marci@1031
   163
    /// Next member.
marci@1031
   164
    ClassIt& next(ClassIt& it) const {
marci@1031
   165
      it.i=nodes[it.i].next;
marci@1031
   166
      return it;
marci@1031
   167
    }
marci@1031
   168
    /// True iff the iterator is valid.
marci@1031
   169
    bool valid(const ClassIt& it) const { return it.i!=-1; }
marci@1031
   170
  };
marci@1031
   171
marci@1097
   172
marci@1031
   173
  /*! \e
marci@1143
   174
    \todo kellenene uj iterable structure bele, mert ez nem az igazi
marci@1111
   175
    \todo A[x,y]-t cserel. Jobboldal, baloldal csere.
marci@1111
   176
    \todo LEKERDEZESEK!!!
marci@1111
   177
    \todo DOKSI!!!! Doxygen group!!!
marci@1111
   178
    The aim of this class is to give a general surface to different 
marci@1111
   179
    solvers, i.e. it makes possible to write algorithms using LP's, 
marci@1111
   180
    in which the solver can be changed to an other one easily.
marci@1112
   181
    \nosubgrouping
marci@1111
   182
  */
marci@1048
   183
  template <typename _Value>
marci@1031
   184
  class LPSolverBase {
marci@1112
   185
    
marci@1113
   186
    /*! @name Uncategorized functions and types (public members)
marci@1112
   187
    */
marci@1112
   188
    //@{
marci@1031
   189
  public:
marci@1112
   190
marci@1112
   191
    //UNCATEGORIZED
marci@1112
   192
marci@1031
   193
    /// \e
marci@1048
   194
    typedef _Value Value;
marci@1048
   195
    /// \e
marci@1144
   196
    typedef IterablePartition<int>::ClassIt Row;
marci@1031
   197
    /// \e
marci@1144
   198
    typedef IterablePartition<int>::ClassIt Col;
marci@1074
   199
  public:
marci@1031
   200
    /// \e
marci@1031
   201
    IterablePartition<int> row_iter_map;
marci@1031
   202
    /// \e
marci@1031
   203
    IterablePartition<int> col_iter_map;
marci@1031
   204
    /// \e
marci@1144
   205
    std::vector<Row> int_row_map;
marci@1143
   206
    /// \e
marci@1144
   207
    std::vector<Col> int_col_map;
marci@1143
   208
    /// \e
marci@1074
   209
    const int VALID_CLASS;
marci@1031
   210
    /// \e
marci@1074
   211
    const int INVALID_CLASS;
marci@1104
   212
    /// \e 
marci@1104
   213
    static const _Value INF;
marci@1031
   214
  public:
marci@1031
   215
    /// \e
marci@1031
   216
    LPSolverBase() : row_iter_map(2), 
marci@1031
   217
		     col_iter_map(2), 
marci@1074
   218
		     VALID_CLASS(0), INVALID_CLASS(1) { }
marci@1031
   219
    /// \e
marci@1031
   220
    virtual ~LPSolverBase() { }
marci@1112
   221
    //@}
marci@1081
   222
marci@1112
   223
    /*! @name Medium level interface (public members)
marci@1112
   224
      These functions appear in the low level and also in the high level 
marci@1112
   225
      interfaces thus these each of these functions have to be implemented 
marci@1112
   226
      only once in the different interfaces.
marci@1112
   227
      This means that these functions have to be reimplemented for all of the 
marci@1112
   228
      different lp solvers. These are basic functions, and have the same 
marci@1112
   229
      parameter lists in the low and high level interfaces. 
marci@1112
   230
    */
marci@1112
   231
    //@{
marci@1112
   232
  public:
marci@1081
   233
marci@1112
   234
    //UNCATEGORIZED FUNCTIONS
marci@1112
   235
marci@1031
   236
    /// \e
marci@1031
   237
    virtual void setMinimize() = 0;
marci@1031
   238
    /// \e
marci@1031
   239
    virtual void setMaximize() = 0;
marci@1081
   240
marci@1112
   241
    //SOLVER FUNCTIONS
marci@1081
   242
marci@1112
   243
    /// \e
marci@1112
   244
    virtual void solveSimplex() = 0;
marci@1112
   245
    /// \e
marci@1112
   246
    virtual void solvePrimalSimplex() = 0;
marci@1112
   247
    /// \e
marci@1112
   248
    virtual void solveDualSimplex() = 0;
marci@1112
   249
    /// \e
marci@1112
   250
marci@1112
   251
    //SOLUTION RETRIEVING
marci@1112
   252
marci@1112
   253
    /// \e
marci@1112
   254
    virtual _Value getObjVal() = 0;
marci@1112
   255
marci@1112
   256
    //OTHER FUNCTIONS
marci@1112
   257
marci@1112
   258
    /// \e
marci@1112
   259
    virtual int rowNum() const = 0;
marci@1112
   260
    /// \e
marci@1112
   261
    virtual int colNum() const = 0;
marci@1112
   262
    /// \e
marci@1112
   263
    virtual int warmUp() = 0;
marci@1112
   264
    /// \e
marci@1112
   265
    virtual void printWarmUpStatus(int i) = 0;
marci@1112
   266
    /// \e
marci@1112
   267
    virtual int getPrimalStatus() = 0;
marci@1112
   268
    /// \e
marci@1112
   269
    virtual void printPrimalStatus(int i) = 0;
marci@1112
   270
    /// \e
marci@1112
   271
    virtual int getDualStatus() = 0;
marci@1112
   272
    /// \e
marci@1112
   273
    virtual void printDualStatus(int i) = 0;
marci@1144
   274
    /// Returns the status of the slack variable assigned to row \c row.
marci@1144
   275
    virtual int getRowStat(const Row& row) = 0;
marci@1112
   276
    /// \e
marci@1112
   277
    virtual void printRowStatus(int i) = 0;
marci@1144
   278
    /// Returns the status of the variable assigned to column \c col.
marci@1144
   279
    virtual int getColStat(const Col& col) = 0;
marci@1112
   280
    /// \e
marci@1112
   281
    virtual void printColStatus(int i) = 0;
marci@1112
   282
marci@1112
   283
    //@}
marci@1112
   284
marci@1112
   285
    /*! @name Low level interface (protected members)
marci@1112
   286
      Problem manipulating functions in the low level interface
marci@1112
   287
    */
marci@1112
   288
    //@{
marci@1074
   289
  protected:
marci@1112
   290
marci@1112
   291
    //MATRIX MANIPULATING FUNCTIONS
marci@1112
   292
marci@1031
   293
    /// \e
marci@1111
   294
    virtual int _addCol() = 0;
marci@1111
   295
    /// \e
marci@1074
   296
    virtual int _addRow() = 0;
marci@1031
   297
    /// \e
marci@1111
   298
    virtual void _eraseCol(int i) = 0;
marci@1111
   299
    /// \e
marci@1111
   300
    virtual void _eraseRow(int i) = 0;
marci@1081
   301
    /// \e
marci@1081
   302
    virtual void _setRowCoeffs(int i, 
marci@1104
   303
			       const std::vector<std::pair<int, _Value> >& coeffs) = 0;
marci@1081
   304
    /// \e
marci@1143
   305
    /// This routine modifies \c coeffs only by the \c push_back method.
marci@1143
   306
    virtual void _getRowCoeffs(int i, 
marci@1143
   307
			       std::vector<std::pair<int, _Value> >& coeffs) = 0;
marci@1081
   308
    virtual void _setColCoeffs(int i, 
marci@1104
   309
			       const std::vector<std::pair<int, _Value> >& coeffs) = 0;
marci@1143
   310
    /// \e
marci@1143
   311
    /// This routine modifies \c coeffs only by the \c push_back method.
marci@1143
   312
    virtual void _getColCoeffs(int i, 
marci@1143
   313
			       std::vector<std::pair<int, _Value> >& coeffs) = 0;
marci@1081
   314
  public:
marci@1081
   315
    /// \e
marci@1081
   316
    enum Bound { FREE, LOWER, UPPER, DOUBLE, FIXED };
marci@1081
   317
  protected:
marci@1081
   318
    /// \e
marci@1110
   319
    /// The lower bound of a variable (column) have to be given by an 
marci@1110
   320
    /// extended number of type _Value, i.e. a finite number of type 
marci@1110
   321
    /// _Value or -INF.
marci@1110
   322
    virtual void _setColLowerBound(int i, _Value value) = 0;
marci@1110
   323
    /// \e
marci@1111
   324
    /// The lower bound of a variable (column) is an 
marci@1111
   325
    /// extended number of type _Value, i.e. a finite number of type 
marci@1111
   326
    /// _Value or -INF.
marci@1111
   327
    virtual _Value _getColLowerBound(int i) = 0;
marci@1111
   328
    /// \e
marci@1110
   329
    /// The upper bound of a variable (column) have to be given by an 
marci@1110
   330
    /// extended number of type _Value, i.e. a finite number of type 
marci@1110
   331
    /// _Value or INF.
marci@1110
   332
    virtual void _setColUpperBound(int i, _Value value) = 0;
marci@1110
   333
    /// \e
marci@1110
   334
    /// The upper bound of a variable (column) is an 
marci@1110
   335
    /// extended number of type _Value, i.e. a finite number of type 
marci@1110
   336
    /// _Value or INF.
marci@1110
   337
    virtual _Value _getColUpperBound(int i) = 0;
marci@1110
   338
    /// \e
marci@1111
   339
    /// The lower bound of a linear expression (row) have to be given by an 
marci@1111
   340
    /// extended number of type _Value, i.e. a finite number of type 
marci@1111
   341
    /// _Value or -INF.
marci@1111
   342
    virtual void _setRowLowerBound(int i, _Value value) = 0;
marci@1081
   343
    /// \e
marci@1111
   344
    /// The lower bound of a linear expression (row) is an 
marci@1111
   345
    /// extended number of type _Value, i.e. a finite number of type 
marci@1111
   346
    /// _Value or -INF.
marci@1111
   347
    virtual _Value _getRowLowerBound(int i) = 0;
marci@1111
   348
    /// \e
marci@1111
   349
    /// The upper bound of a linear expression (row) have to be given by an 
marci@1111
   350
    /// extended number of type _Value, i.e. a finite number of type 
marci@1111
   351
    /// _Value or INF.
marci@1111
   352
    virtual void _setRowUpperBound(int i, _Value value) = 0;
marci@1111
   353
    /// \e
marci@1111
   354
    /// The upper bound of a linear expression (row) is an 
marci@1111
   355
    /// extended number of type _Value, i.e. a finite number of type 
marci@1111
   356
    /// _Value or INF.
marci@1111
   357
    virtual _Value _getRowUpperBound(int i) = 0;
marci@1081
   358
    /// \e
marci@1081
   359
    virtual void _setObjCoef(int i, _Value obj_coef) = 0;
marci@1081
   360
    /// \e
marci@1081
   361
    virtual _Value _getObjCoef(int i) = 0;
marci@1112
   362
    
marci@1112
   363
    //SOLUTION RETRIEVING
marci@1081
   364
marci@1111
   365
    /// \e
marci@1081
   366
    virtual _Value _getPrimal(int i) = 0;
marci@1112
   367
    //@}
marci@1112
   368
    
marci@1112
   369
    /*! @name High level interface (public members)
marci@1112
   370
      Problem manipulating functions in the high level interface
marci@1112
   371
    */
marci@1112
   372
    //@{
marci@1112
   373
  public:
marci@1081
   374
marci@1112
   375
    //MATRIX MANIPULATING FUNCTIONS
marci@1081
   376
marci@1074
   377
    /// \e
marci@1144
   378
    Col addCol() {
marci@1074
   379
      int i=_addCol();  
marci@1144
   380
      Col col;
marci@1144
   381
      col_iter_map.first(col, INVALID_CLASS);
marci@1144
   382
      if (col_iter_map.valid(col)) { //van hasznalhato hely
marci@1144
   383
	col_iter_map.set(col, INVALID_CLASS, VALID_CLASS);
marci@1144
   384
	col_iter_map[col]=i;
marci@1074
   385
      } else { //a cucc vegere kell inzertalni mert nincs szabad hely
marci@1144
   386
	col=col_iter_map.push_back(i, VALID_CLASS);
marci@1074
   387
      }
marci@1144
   388
      int_col_map.push_back(col);
marci@1144
   389
      return col;
marci@1074
   390
    }
marci@1074
   391
    /// \e
marci@1144
   392
    Row addRow() {
marci@1111
   393
      int i=_addRow();
marci@1144
   394
      Row row;
marci@1144
   395
      row_iter_map.first(row, INVALID_CLASS);
marci@1144
   396
      if (row_iter_map.valid(row)) { //van hasznalhato hely
marci@1144
   397
	row_iter_map.set(row, INVALID_CLASS, VALID_CLASS);
marci@1144
   398
	row_iter_map[row]=i;
marci@1111
   399
      } else { //a cucc vegere kell inzertalni mert nincs szabad hely
marci@1144
   400
	row=row_iter_map.push_back(i, VALID_CLASS);
marci@1031
   401
      }
marci@1144
   402
      int_row_map.push_back(row);
marci@1144
   403
      return row;
marci@1074
   404
    }
marci@1074
   405
    /// \e
marci@1144
   406
    void eraseCol(const Col& col) {
marci@1144
   407
      col_iter_map.set(col, VALID_CLASS, INVALID_CLASS);
marci@1074
   408
      int cols[2];
marci@1144
   409
      cols[1]=col_iter_map[col];
marci@1074
   410
      _eraseCol(cols[1]);
marci@1144
   411
      col_iter_map[col]=0; //glpk specifikus, de kell ez??
marci@1144
   412
      Col it;
marci@1074
   413
      for (col_iter_map.first(it, VALID_CLASS); 
marci@1074
   414
	   col_iter_map.valid(it); col_iter_map.next(it)) {
marci@1074
   415
	if (col_iter_map[it]>cols[1]) --col_iter_map[it];
marci@1074
   416
      }
marci@1143
   417
      int_col_map.erase(int_col_map.begin()+cols[1]);
marci@1031
   418
    }
marci@1031
   419
    /// \e
marci@1144
   420
    void eraseRow(const Row& row) {
marci@1144
   421
      row_iter_map.set(row, VALID_CLASS, INVALID_CLASS);
marci@1074
   422
      int rows[2];
marci@1144
   423
      rows[1]=row_iter_map[row];
marci@1074
   424
      _eraseRow(rows[1]);
marci@1144
   425
      row_iter_map[row]=0; //glpk specifikus, de kell ez??
marci@1144
   426
      Row it;
marci@1074
   427
      for (row_iter_map.first(it, VALID_CLASS); 
marci@1074
   428
	   row_iter_map.valid(it); row_iter_map.next(it)) {
marci@1074
   429
	if (row_iter_map[it]>rows[1]) --row_iter_map[it];
marci@1074
   430
      }
marci@1143
   431
      int_row_map.erase(int_row_map.begin()+rows[1]);
marci@1074
   432
    }
marci@1031
   433
    /// \e
marci@1144
   434
    void setColLowerBound(Col col, _Value lo) {
marci@1144
   435
      _setColLowerBound(col_iter_map[col], lo);
marci@1111
   436
    }
marci@1111
   437
    /// \e
marci@1144
   438
    _Value getColLowerBound(Col col) {
marci@1144
   439
      return _getColLowerBound(col_iter_map[col]);
marci@1111
   440
    }
marci@1111
   441
    /// \e
marci@1144
   442
    void setColUpperBound(Col col, _Value up) {
marci@1144
   443
      _setColUpperBound(col_iter_map[col], up);
marci@1110
   444
    }
marci@1110
   445
    /// \e
marci@1144
   446
    _Value getColUpperBound(Col col) {      
marci@1144
   447
      return _getColUpperBound(col_iter_map[col]);
marci@1111
   448
    }
marci@1111
   449
    /// \e
marci@1144
   450
    void setRowLowerBound(Row row, _Value lo) {
marci@1144
   451
      _setRowLowerBound(row_iter_map[row], lo);
marci@1110
   452
    }
marci@1110
   453
    /// \e
marci@1144
   454
    _Value getRowLowerBound(Row row) {
marci@1144
   455
      return _getRowLowerBound(row_iter_map[row]);
marci@1110
   456
    }
marci@1110
   457
    /// \e
marci@1144
   458
    void setRowUpperBound(Row row, _Value up) {
marci@1144
   459
      _setRowUpperBound(row_iter_map[row], up);
marci@1081
   460
    }
marci@1031
   461
    /// \e
marci@1144
   462
    _Value getRowUpperBound(Row row) {      
marci@1144
   463
      return _getRowUpperBound(row_iter_map[row]);
marci@1111
   464
    }
marci@1111
   465
    /// \e
marci@1144
   466
    void setObjCoef(const Col& col, _Value obj_coef) {
marci@1144
   467
      _setObjCoef(col_iter_map[col], obj_coef);
marci@1111
   468
    }
marci@1111
   469
    /// \e
marci@1144
   470
    _Value getObjCoef(const Col& col) {
marci@1144
   471
      return _getObjCoef(col_iter_map[col]);
marci@1081
   472
    }
marci@1081
   473
marci@1112
   474
    //SOLUTION RETRIEVING FUNCTIONS
marci@1112
   475
marci@1112
   476
    /// \e
marci@1144
   477
    _Value getPrimal(const Col& col) {
marci@1144
   478
      return _getPrimal(col_iter_map[col]);
marci@1112
   479
    }    
marci@1112
   480
marci@1112
   481
    //@}
marci@1112
   482
marci@1112
   483
    /*! @name User friend interface
marci@1112
   484
      Problem manipulating functions in the user friend interface
marci@1112
   485
    */
marci@1112
   486
    //@{
marci@1112
   487
marci@1112
   488
    //EXPRESSION TYPES
marci@1099
   489
marci@1099
   490
    /// \e
marci@1144
   491
    typedef Expr<Col, _Value> Expression;
marci@1099
   492
    /// \e
marci@1144
   493
    typedef Expr<Row, _Value> DualExpression;
marci@1144
   494
    /// \e
marci@1144
   495
    typedef Constr<Col, _Value> Constraint;
marci@1112
   496
marci@1112
   497
    //MATRIX MANIPULATING FUNCTIONS
marci@1112
   498
marci@1099
   499
    /// \e
marci@1144
   500
    void setRowCoeffs(Row row, const Expression& expr) {
marci@1099
   501
      std::vector<std::pair<int, _Value> > row_coeffs;
marci@1099
   502
      for(typename Expression::Data::const_iterator i=expr.data.begin(); 
marci@1099
   503
	  i!=expr.data.end(); ++i) {
marci@1099
   504
	row_coeffs.push_back(std::make_pair
marci@1099
   505
			     (col_iter_map[(*i).first], (*i).second));
marci@1099
   506
      }
marci@1144
   507
      _setRowCoeffs(row_iter_map[row], row_coeffs);
marci@1144
   508
    }
marci@1144
   509
    /// \e 
marci@1144
   510
    void setRow(Row row, const Constraint& constr) {
marci@1144
   511
      setRowCoeffs(row, constr.expr);
marci@1144
   512
      setRowLowerBound(row, constr.lo);
marci@1144
   513
      setRowUpperBound(row, constr.up);
marci@1144
   514
    }
marci@1144
   515
    /// \e 
marci@1144
   516
    Row addRow(const Constraint& constr) {
marci@1144
   517
      Row row=addRow();
marci@1144
   518
      setRowCoeffs(row, constr.expr);
marci@1144
   519
      setRowLowerBound(row, constr.lo);
marci@1144
   520
      setRowUpperBound(row, constr.up);
marci@1144
   521
      return row;
marci@1099
   522
    }
marci@1099
   523
    /// \e
marci@1143
   524
    /// This routine modifies \c expr by only adding to it.
marci@1144
   525
    void getRowCoeffs(Row row, Expression& expr) {
marci@1143
   526
      std::vector<std::pair<int, _Value> > row_coeffs;
marci@1144
   527
      _getRowCoeffs(row_iter_map[row], row_coeffs);
marci@1143
   528
      for(typename std::vector<std::pair<int, _Value> >::const_iterator 
marci@1143
   529
 	    i=row_coeffs.begin(); i!=row_coeffs.end(); ++i) {
marci@1143
   530
 	expr+= (*i).second*int_col_map[(*i).first];
marci@1143
   531
      }
marci@1143
   532
    }
marci@1143
   533
    /// \e
marci@1144
   534
    void setColCoeffs(Col col, const DualExpression& expr) {
marci@1099
   535
      std::vector<std::pair<int, _Value> > col_coeffs;
marci@1099
   536
      for(typename DualExpression::Data::const_iterator i=expr.data.begin(); 
marci@1099
   537
	  i!=expr.data.end(); ++i) {
marci@1099
   538
	col_coeffs.push_back(std::make_pair
marci@1099
   539
			     (row_iter_map[(*i).first], (*i).second));
marci@1099
   540
      }
marci@1144
   541
      _setColCoeffs(col_iter_map[col], col_coeffs);
marci@1099
   542
    }
marci@1099
   543
    /// \e
marci@1143
   544
    /// This routine modifies \c expr by only adding to it.
marci@1144
   545
    void getColCoeffs(Col col, DualExpression& expr) {
marci@1143
   546
      std::vector<std::pair<int, _Value> > col_coeffs;
marci@1144
   547
      _getColCoeffs(col_iter_map[col], col_coeffs);
marci@1143
   548
      for(typename std::vector<std::pair<int, _Value> >::const_iterator 
marci@1143
   549
 	    i=col_coeffs.begin(); i!=col_coeffs.end(); ++i) {
marci@1143
   550
 	expr+= (*i).second*int_row_map[(*i).first];
marci@1143
   551
      }
marci@1143
   552
    }
marci@1143
   553
    /// \e
marci@1143
   554
    /// \bug ez igy nem jo
marci@1099
   555
    void setObjCoeffs(const Expression& expr) {
marci@1099
   556
      for(typename Expression::Data::const_iterator i=expr.data.begin(); 
marci@1099
   557
	  i!=expr.data.end(); ++i) {
marci@1099
   558
	setObjCoef((*i).first, (*i).second);
marci@1099
   559
      }
marci@1099
   560
    }
marci@1143
   561
    /// \e
marci@1143
   562
    /// This routine modifies \c expr by only adding to it.
marci@1143
   563
    void getObjCoeffs(Expression& expr) {
marci@1143
   564
      /// FIXME not yet implemented
marci@1143
   565
    }
marci@1112
   566
    //@}
marci@1031
   567
  };
marci@1031
   568
  
marci@1104
   569
  template <typename _Value>
marci@1104
   570
  const _Value LPSolverBase<_Value>::INF=std::numeric_limits<_Value>::infinity();
marci@1104
   571
marci@1048
   572
marci@1111
   573
  /// \brief Wrapper for GLPK solver
marci@1031
   574
  /// 
marci@1111
   575
  /// This class implements a lemon wrapper for GLPK.
marci@1081
   576
  class LPGLPK : public LPSolverBase<double> {
marci@1031
   577
  public:
marci@1048
   578
    typedef LPSolverBase<double> Parent;
marci@1031
   579
marci@1031
   580
  public:
marci@1031
   581
    /// \e
marci@1031
   582
    LPX* lp;
marci@1031
   583
marci@1031
   584
  public:
marci@1031
   585
    /// \e
marci@1081
   586
    LPGLPK() : Parent(), 
marci@1031
   587
			lp(lpx_create_prob()) {
marci@1144
   588
      int_row_map.push_back(Row());
marci@1144
   589
      int_col_map.push_back(Col());
marci@1031
   590
      lpx_set_int_parm(lp, LPX_K_DUAL, 1);
marci@1031
   591
    }
marci@1031
   592
    /// \e
marci@1081
   593
    ~LPGLPK() {
marci@1031
   594
      lpx_delete_prob(lp);
marci@1031
   595
    }
marci@1081
   596
marci@1081
   597
    //MATRIX INDEPEDENT MANIPULATING FUNCTIONS
marci@1081
   598
marci@1031
   599
    /// \e
marci@1031
   600
    void setMinimize() { 
marci@1031
   601
      lpx_set_obj_dir(lp, LPX_MIN);
marci@1031
   602
    }
marci@1031
   603
    /// \e
marci@1031
   604
    void setMaximize() { 
marci@1031
   605
      lpx_set_obj_dir(lp, LPX_MAX);
marci@1031
   606
    }
marci@1081
   607
marci@1081
   608
    //LOW LEVEL INTERFACE, MATRIX MANIPULATING FUNCTIONS
marci@1081
   609
marci@1074
   610
  protected:
marci@1031
   611
    /// \e
marci@1074
   612
    int _addCol() { 
marci@1110
   613
      int i=lpx_add_cols(lp, 1);
marci@1110
   614
      _setColLowerBound(i, -INF);
marci@1110
   615
      _setColUpperBound(i, INF);
marci@1110
   616
      return i;
marci@1031
   617
    }
marci@1031
   618
    /// \e
marci@1074
   619
    int _addRow() { 
marci@1110
   620
      int i=lpx_add_rows(lp, 1);
marci@1110
   621
      return i;
marci@1074
   622
    }
marci@1074
   623
    /// \e
marci@1081
   624
    virtual void _setRowCoeffs(int i, 
marci@1104
   625
			       const std::vector<std::pair<int, double> >& coeffs) {
marci@1074
   626
      int mem_length=1+colNum();
marci@1074
   627
      int* indices = new int[mem_length];
marci@1074
   628
      double* doubles = new double[mem_length];
marci@1074
   629
      int length=0;
marci@1074
   630
      for (std::vector<std::pair<int, double> >::
marci@1074
   631
	     const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
marci@1074
   632
	++length;
marci@1074
   633
	indices[length]=it->first;
marci@1074
   634
	doubles[length]=it->second;
marci@1031
   635
      }
marci@1074
   636
      lpx_set_mat_row(lp, i, length, indices, doubles);
marci@1074
   637
      delete [] indices;
marci@1074
   638
      delete [] doubles;
marci@1031
   639
    }
marci@1074
   640
    /// \e
marci@1143
   641
    virtual void _getRowCoeffs(int i, 
marci@1143
   642
			       std::vector<std::pair<int, double> >& coeffs) {
marci@1143
   643
      int mem_length=1+colNum();
marci@1143
   644
      int* indices = new int[mem_length];
marci@1143
   645
      double* doubles = new double[mem_length];
marci@1143
   646
      int length=lpx_get_mat_row(lp, i, indices, doubles);
marci@1143
   647
      for (int i=1; i<=length; ++i) {
marci@1143
   648
	coeffs.push_back(std::make_pair(indices[i], doubles[i]));
marci@1143
   649
      }
marci@1143
   650
      delete [] indices;
marci@1143
   651
      delete [] doubles;
marci@1143
   652
    }
marci@1143
   653
    /// \e
marci@1081
   654
    virtual void _setColCoeffs(int i, 
marci@1104
   655
			       const std::vector<std::pair<int, double> >& coeffs) {
marci@1074
   656
      int mem_length=1+rowNum();
marci@1074
   657
      int* indices = new int[mem_length];
marci@1074
   658
      double* doubles = new double[mem_length];
marci@1074
   659
      int length=0;
marci@1074
   660
      for (std::vector<std::pair<int, double> >::
marci@1074
   661
	     const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
marci@1074
   662
	++length;
marci@1074
   663
	indices[length]=it->first;
marci@1074
   664
	doubles[length]=it->second;
marci@1074
   665
      }
marci@1074
   666
      lpx_set_mat_col(lp, i, length, indices, doubles);
marci@1074
   667
      delete [] indices;
marci@1074
   668
      delete [] doubles;
marci@1031
   669
    }
marci@1031
   670
    /// \e
marci@1143
   671
    virtual void _getColCoeffs(int i, 
marci@1143
   672
			       std::vector<std::pair<int, double> >& coeffs) {
marci@1143
   673
      int mem_length=1+rowNum();
marci@1143
   674
      int* indices = new int[mem_length];
marci@1143
   675
      double* doubles = new double[mem_length];
marci@1143
   676
      int length=lpx_get_mat_col(lp, i, indices, doubles);
marci@1143
   677
      for (int i=1; i<=length; ++i) {
marci@1143
   678
	coeffs.push_back(std::make_pair(indices[i], doubles[i]));
marci@1143
   679
      }
marci@1143
   680
      delete [] indices;
marci@1143
   681
      delete [] doubles;
marci@1143
   682
    }
marci@1143
   683
    /// \e
marci@1074
   684
    virtual void _eraseCol(int i) {
marci@1031
   685
      int cols[2];
marci@1074
   686
      cols[1]=i;
marci@1031
   687
      lpx_del_cols(lp, 1, cols);
marci@1031
   688
    }
marci@1074
   689
    virtual void _eraseRow(int i) {
marci@1031
   690
      int rows[2];
marci@1074
   691
      rows[1]=i;
marci@1031
   692
      lpx_del_rows(lp, 1, rows);
marci@1031
   693
    }
marci@1110
   694
    virtual void _setColLowerBound(int i, double lo) {
marci@1110
   695
      if (lo==INF) {
marci@1110
   696
	//FIXME error
marci@1110
   697
      }
marci@1110
   698
      int b=lpx_get_col_type(lp, i);
marci@1110
   699
      double up=lpx_get_col_ub(lp, i);	
marci@1110
   700
      if (lo==-INF) {
marci@1110
   701
	switch (b) {
marci@1110
   702
	case LPX_FR:
marci@1110
   703
	case LPX_LO:
marci@1110
   704
	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
marci@1110
   705
	  break;
marci@1110
   706
	case LPX_UP:
marci@1110
   707
	  break;
marci@1110
   708
	case LPX_DB:
marci@1110
   709
	case LPX_FX:
marci@1110
   710
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
marci@1110
   711
	  break;
marci@1110
   712
	default: ;
marci@1110
   713
	  //FIXME error
marci@1110
   714
	}
marci@1110
   715
      } else {
marci@1110
   716
	switch (b) {
marci@1110
   717
	case LPX_FR:
marci@1110
   718
	case LPX_LO:
marci@1110
   719
	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
marci@1110
   720
	  break;
marci@1110
   721
	case LPX_UP:	  
marci@1110
   722
	case LPX_DB:
marci@1110
   723
	case LPX_FX:
marci@1110
   724
	  if (lo==up) 
marci@1110
   725
	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
marci@1110
   726
	  else 
marci@1110
   727
	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
marci@1110
   728
	  break;
marci@1110
   729
	default: ;
marci@1110
   730
	  //FIXME error
marci@1110
   731
	}
marci@1110
   732
      }
marci@1110
   733
    }
marci@1111
   734
    virtual double _getColLowerBound(int i) {
marci@1111
   735
      int b=lpx_get_col_type(lp, i);
marci@1111
   736
      switch (b) {
marci@1111
   737
      case LPX_FR:
marci@1111
   738
	return -INF;
marci@1111
   739
      case LPX_LO:
marci@1111
   740
	return lpx_get_col_lb(lp, i);
marci@1111
   741
      case LPX_UP:
marci@1111
   742
	return -INF;
marci@1111
   743
      case LPX_DB:
marci@1111
   744
      case LPX_FX:
marci@1111
   745
	return lpx_get_col_lb(lp, i);
marci@1111
   746
      default: ;
marci@1111
   747
	//FIXME error
marci@1111
   748
	return 0.0;
marci@1111
   749
      }
marci@1111
   750
    }
marci@1110
   751
    virtual void _setColUpperBound(int i, double up) {
marci@1110
   752
      if (up==-INF) {
marci@1110
   753
	//FIXME error
marci@1110
   754
      }
marci@1110
   755
      int b=lpx_get_col_type(lp, i);
marci@1110
   756
      double lo=lpx_get_col_lb(lp, i);
marci@1110
   757
      if (up==INF) {
marci@1110
   758
	switch (b) {
marci@1110
   759
	case LPX_FR:
marci@1110
   760
	case LPX_LO:
marci@1110
   761
	  break;
marci@1110
   762
	case LPX_UP:
marci@1110
   763
	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
marci@1110
   764
	  break;
marci@1110
   765
	case LPX_DB:
marci@1110
   766
	case LPX_FX:
marci@1110
   767
	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
marci@1110
   768
	  break;
marci@1110
   769
	default: ;
marci@1110
   770
	  //FIXME error
marci@1110
   771
	}
marci@1110
   772
      } else {
marci@1110
   773
	switch (b) {
marci@1110
   774
	case LPX_FR:
marci@1110
   775
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
marci@1110
   776
	case LPX_LO:
marci@1110
   777
	  if (lo==up) 
marci@1110
   778
	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
marci@1110
   779
	  else
marci@1110
   780
	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
marci@1110
   781
	  break;
marci@1110
   782
	case LPX_UP:
marci@1110
   783
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
marci@1110
   784
	  break;
marci@1110
   785
	case LPX_DB:
marci@1110
   786
	case LPX_FX:
marci@1110
   787
	  if (lo==up) 
marci@1110
   788
	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
marci@1110
   789
	  else 
marci@1110
   790
	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
marci@1110
   791
	  break;
marci@1110
   792
	default: ;
marci@1110
   793
	  //FIXME error
marci@1110
   794
	}
marci@1110
   795
      }
marci@1110
   796
    }
marci@1110
   797
    virtual double _getColUpperBound(int i) {
marci@1110
   798
      int b=lpx_get_col_type(lp, i);
marci@1110
   799
      switch (b) {
marci@1110
   800
      case LPX_FR:
marci@1110
   801
      case LPX_LO:
marci@1110
   802
	return INF;
marci@1110
   803
      case LPX_UP:
marci@1110
   804
      case LPX_DB:
marci@1110
   805
      case LPX_FX:
marci@1110
   806
	return lpx_get_col_ub(lp, i);
marci@1110
   807
      default: ;
marci@1110
   808
	//FIXME error
marci@1110
   809
	return 0.0;
marci@1110
   810
      }
marci@1110
   811
    }
marci@1111
   812
    virtual void _setRowLowerBound(int i, double lo) {
marci@1111
   813
      if (lo==INF) {
marci@1111
   814
	//FIXME error
marci@1081
   815
      }
marci@1111
   816
      int b=lpx_get_row_type(lp, i);
marci@1111
   817
      double up=lpx_get_row_ub(lp, i);	
marci@1111
   818
      if (lo==-INF) {
marci@1111
   819
	switch (b) {
marci@1111
   820
	case LPX_FR:
marci@1111
   821
	case LPX_LO:
marci@1111
   822
	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
marci@1111
   823
	  break;
marci@1111
   824
	case LPX_UP:
marci@1111
   825
	  break;
marci@1111
   826
	case LPX_DB:
marci@1111
   827
	case LPX_FX:
marci@1111
   828
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
marci@1111
   829
	  break;
marci@1111
   830
	default: ;
marci@1111
   831
	  //FIXME error
marci@1111
   832
	}
marci@1111
   833
      } else {
marci@1111
   834
	switch (b) {
marci@1111
   835
	case LPX_FR:
marci@1111
   836
	case LPX_LO:
marci@1111
   837
	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
marci@1111
   838
	  break;
marci@1111
   839
	case LPX_UP:	  
marci@1111
   840
	case LPX_DB:
marci@1111
   841
	case LPX_FX:
marci@1111
   842
	  if (lo==up) 
marci@1111
   843
	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
marci@1111
   844
	  else 
marci@1111
   845
	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
marci@1111
   846
	  break;
marci@1111
   847
	default: ;
marci@1111
   848
	  //FIXME error
marci@1111
   849
	}
marci@1081
   850
      }
marci@1111
   851
    }
marci@1111
   852
    virtual double _getRowLowerBound(int i) {
marci@1111
   853
      int b=lpx_get_row_type(lp, i);
marci@1111
   854
      switch (b) {
marci@1111
   855
      case LPX_FR:
marci@1111
   856
	return -INF;
marci@1111
   857
      case LPX_LO:
marci@1111
   858
	return lpx_get_row_lb(lp, i);
marci@1111
   859
      case LPX_UP:
marci@1111
   860
	return -INF;
marci@1111
   861
      case LPX_DB:
marci@1111
   862
      case LPX_FX:
marci@1111
   863
	return lpx_get_row_lb(lp, i);
marci@1111
   864
      default: ;
marci@1111
   865
	//FIXME error
marci@1111
   866
	return 0.0;
marci@1111
   867
      }
marci@1111
   868
    }
marci@1111
   869
    virtual void _setRowUpperBound(int i, double up) {
marci@1111
   870
      if (up==-INF) {
marci@1111
   871
	//FIXME error
marci@1111
   872
      }
marci@1111
   873
      int b=lpx_get_row_type(lp, i);
marci@1111
   874
      double lo=lpx_get_row_lb(lp, i);
marci@1111
   875
      if (up==INF) {
marci@1111
   876
	switch (b) {
marci@1111
   877
	case LPX_FR:
marci@1111
   878
	case LPX_LO:
marci@1111
   879
	  break;
marci@1111
   880
	case LPX_UP:
marci@1111
   881
	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
marci@1111
   882
	  break;
marci@1111
   883
	case LPX_DB:
marci@1111
   884
	case LPX_FX:
marci@1111
   885
	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
marci@1111
   886
	  break;
marci@1111
   887
	default: ;
marci@1111
   888
	  //FIXME error
marci@1111
   889
	}
marci@1111
   890
      } else {
marci@1111
   891
	switch (b) {
marci@1111
   892
	case LPX_FR:
marci@1111
   893
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
marci@1111
   894
	case LPX_LO:
marci@1111
   895
	  if (lo==up) 
marci@1111
   896
	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
marci@1111
   897
	  else
marci@1111
   898
	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
marci@1111
   899
	  break;
marci@1111
   900
	case LPX_UP:
marci@1111
   901
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
marci@1111
   902
	  break;
marci@1111
   903
	case LPX_DB:
marci@1111
   904
	case LPX_FX:
marci@1111
   905
	  if (lo==up) 
marci@1111
   906
	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
marci@1111
   907
	  else 
marci@1111
   908
	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
marci@1111
   909
	  break;
marci@1111
   910
	default: ;
marci@1111
   911
	  //FIXME error
marci@1111
   912
	}
marci@1111
   913
      }
marci@1111
   914
    }
marci@1111
   915
    virtual double _getRowUpperBound(int i) {
marci@1111
   916
      int b=lpx_get_row_type(lp, i);
marci@1111
   917
      switch (b) {
marci@1111
   918
      case LPX_FR:
marci@1111
   919
      case LPX_LO:
marci@1111
   920
	return INF;
marci@1111
   921
      case LPX_UP:
marci@1111
   922
      case LPX_DB:
marci@1111
   923
      case LPX_FX:
marci@1111
   924
	return lpx_get_row_ub(lp, i);
marci@1111
   925
      default: ;
marci@1111
   926
	//FIXME error
marci@1111
   927
	return 0.0;
marci@1111
   928
      }
marci@1111
   929
    }
marci@1031
   930
    /// \e
marci@1081
   931
    virtual double _getObjCoef(int i) { 
marci@1081
   932
      return lpx_get_obj_coef(lp, i);
marci@1031
   933
    }
marci@1031
   934
    /// \e
marci@1081
   935
    virtual void _setObjCoef(int i, double obj_coef) { 
marci@1081
   936
      lpx_set_obj_coef(lp, i, obj_coef);
marci@1031
   937
    }
marci@1081
   938
  public:
marci@1031
   939
    /// \e
marci@1031
   940
    void solveSimplex() { lpx_simplex(lp); }
marci@1031
   941
    /// \e
marci@1031
   942
    void solvePrimalSimplex() { lpx_simplex(lp); }
marci@1031
   943
    /// \e
marci@1031
   944
    void solveDualSimplex() { lpx_simplex(lp); }
marci@1031
   945
    /// \e
marci@1081
   946
  protected:
marci@1081
   947
    virtual double _getPrimal(int i) {
marci@1081
   948
      return lpx_get_col_prim(lp, i);
marci@1031
   949
    }
marci@1081
   950
  public:
marci@1031
   951
    /// \e
marci@1031
   952
    double getObjVal() { return lpx_get_obj_val(lp); }
marci@1031
   953
    /// \e
marci@1031
   954
    int rowNum() const { return lpx_get_num_rows(lp); }
marci@1031
   955
    /// \e
marci@1031
   956
    int colNum() const { return lpx_get_num_cols(lp); }
marci@1031
   957
    /// \e
marci@1031
   958
    int warmUp() { return lpx_warm_up(lp); }
marci@1031
   959
    /// \e
marci@1031
   960
    void printWarmUpStatus(int i) {
marci@1031
   961
      switch (i) {
marci@1031
   962
      case LPX_E_OK: cout << "LPX_E_OK" << endl; break;
marci@1031
   963
      case LPX_E_EMPTY: cout << "LPX_E_EMPTY" << endl; break;	
marci@1031
   964
      case LPX_E_BADB: cout << "LPX_E_BADB" << endl; break;
marci@1031
   965
      case LPX_E_SING: cout << "LPX_E_SING" << endl; break;
marci@1031
   966
      }
marci@1031
   967
    }
marci@1031
   968
    /// \e
marci@1031
   969
    int getPrimalStatus() { return lpx_get_prim_stat(lp); }
marci@1031
   970
    /// \e
marci@1031
   971
    void printPrimalStatus(int i) {
marci@1031
   972
      switch (i) {
marci@1031
   973
      case LPX_P_UNDEF: cout << "LPX_P_UNDEF" << endl; break;
marci@1031
   974
      case LPX_P_FEAS: cout << "LPX_P_FEAS" << endl; break;	
marci@1031
   975
      case LPX_P_INFEAS: cout << "LPX_P_INFEAS" << endl; break;
marci@1031
   976
      case LPX_P_NOFEAS: cout << "LPX_P_NOFEAS" << endl; break;
marci@1031
   977
      }
marci@1031
   978
    }
marci@1031
   979
    /// \e
marci@1031
   980
    int getDualStatus() { return lpx_get_dual_stat(lp); }
marci@1031
   981
    /// \e
marci@1031
   982
    void printDualStatus(int i) {
marci@1031
   983
      switch (i) {
marci@1031
   984
      case LPX_D_UNDEF: cout << "LPX_D_UNDEF" << endl; break;
marci@1031
   985
      case LPX_D_FEAS: cout << "LPX_D_FEAS" << endl; break;	
marci@1031
   986
      case LPX_D_INFEAS: cout << "LPX_D_INFEAS" << endl; break;
marci@1031
   987
      case LPX_D_NOFEAS: cout << "LPX_D_NOFEAS" << endl; break;
marci@1031
   988
      }
marci@1031
   989
    }
marci@1144
   990
    /// Returns the status of the slack variable assigned to row \c row.
marci@1144
   991
    int getRowStat(const Row& row) { 
marci@1144
   992
      return lpx_get_row_stat(lp, row_iter_map[row]); 
marci@1031
   993
    }
marci@1031
   994
    /// \e
marci@1031
   995
    void printRowStatus(int i) {
marci@1031
   996
      switch (i) {
marci@1031
   997
      case LPX_BS: cout << "LPX_BS" << endl; break;
marci@1031
   998
      case LPX_NL: cout << "LPX_NL" << endl; break;	
marci@1031
   999
      case LPX_NU: cout << "LPX_NU" << endl; break;
marci@1031
  1000
      case LPX_NF: cout << "LPX_NF" << endl; break;
marci@1031
  1001
      case LPX_NS: cout << "LPX_NS" << endl; break;
marci@1031
  1002
      }
marci@1031
  1003
    }
marci@1144
  1004
    /// Returns the status of the variable assigned to column \c col.
marci@1144
  1005
    int getColStat(const Col& col) { 
marci@1144
  1006
      return lpx_get_col_stat(lp, col_iter_map[col]); 
marci@1031
  1007
    }
marci@1031
  1008
    /// \e
marci@1031
  1009
    void printColStatus(int i) {
marci@1031
  1010
      switch (i) {
marci@1031
  1011
      case LPX_BS: cout << "LPX_BS" << endl; break;
marci@1031
  1012
      case LPX_NL: cout << "LPX_NL" << endl; break;	
marci@1031
  1013
      case LPX_NU: cout << "LPX_NU" << endl; break;
marci@1031
  1014
      case LPX_NF: cout << "LPX_NF" << endl; break;
marci@1031
  1015
      case LPX_NS: cout << "LPX_NS" << endl; break;
marci@1031
  1016
      }
marci@1031
  1017
    }
marci@1031
  1018
  };
marci@1031
  1019
  
marci@1031
  1020
  /// @}
marci@1031
  1021
marci@1031
  1022
} //namespace lemon
marci@1031
  1023
marci@1031
  1024
#endif //LEMON_LP_SOLVER_WRAPPER_H