src/work/athos/lp_old/lp_solver_glpk.h
author hegyi
Fri, 01 Apr 2005 09:44:29 +0000
changeset 1289 142633fc5014
parent 1243 41caee260bd4
permissions -rw-r--r--
Graph displayer is now displaying nodes. Edges remain still undisplayed yet.
athos@1241
     1
// -*- c++ -*-
athos@1241
     2
#ifndef LEMON_LP_SOLVER_GLPK_H
athos@1241
     3
#define LEMON_LP_SOLVER_GLPK_H
athos@1241
     4
athos@1241
     5
///\ingroup misc
athos@1241
     6
///\file
athos@1241
     7
athos@1241
     8
// #include <stdio.h>
athos@1241
     9
/* #include <stdlib.h> */
athos@1241
    10
/* #include <iostream> */
athos@1241
    11
/* #include <map> */
athos@1241
    12
/* #include <limits> */
athos@1241
    13
// #include <stdio>
athos@1241
    14
//#include <stdlib>
athos@1241
    15
extern "C" {
athos@1241
    16
#include "glpk.h"
athos@1241
    17
}
athos@1241
    18
athos@1241
    19
/* #include <iostream> */
athos@1241
    20
/* #include <vector> */
athos@1241
    21
/* #include <string> */
athos@1241
    22
/* #include <list> */
athos@1241
    23
/* #include <memory> */
athos@1241
    24
/* #include <utility> */
athos@1241
    25
athos@1241
    26
//#include <lemon/invalid.h>
athos@1241
    27
//#include <expression.h>
athos@1241
    28
#include <lp_solver_base.h>
athos@1241
    29
//#include <stp.h>
athos@1241
    30
//#include <lemon/max_flow.h>
athos@1241
    31
//#include <augmenting_flow.h>
athos@1241
    32
//#include <iter_map.h>
athos@1241
    33
athos@1241
    34
using std::cout;
athos@1241
    35
using std::cin;
athos@1241
    36
using std::endl;
athos@1241
    37
athos@1241
    38
namespace lemon {
athos@1241
    39
  
athos@1241
    40
  
athos@1241
    41
  template <typename Value>
athos@1241
    42
  const Value LpSolverBase<Value>::INF=std::numeric_limits<Value>::infinity();
athos@1241
    43
athos@1241
    44
athos@1241
    45
  /// \brief Wrapper for GLPK solver
athos@1241
    46
  /// 
athos@1241
    47
  /// This class implements a lemon wrapper for GLPK.
athos@1241
    48
  class LpGlpk : public LpSolverBase<double> {
athos@1241
    49
  public:
athos@1241
    50
    typedef LpSolverBase<double> Parent;
athos@1241
    51
athos@1241
    52
  public:
athos@1241
    53
    /// \e
athos@1241
    54
    LPX* lp;
athos@1241
    55
athos@1241
    56
  public:
athos@1241
    57
    /// \e
athos@1241
    58
    LpGlpk() : Parent(), 
athos@1241
    59
			lp(lpx_create_prob()) {
athos@1241
    60
      int_row_map.push_back(Row());
athos@1241
    61
      int_col_map.push_back(Col());
athos@1241
    62
      lpx_set_int_parm(lp, LPX_K_DUAL, 1);
athos@1241
    63
    }
athos@1241
    64
    /// \e
athos@1241
    65
    ~LpGlpk() {
athos@1241
    66
      lpx_delete_prob(lp);
athos@1241
    67
    }
athos@1241
    68
athos@1241
    69
    //MATRIX INDEPEDENT MANIPULATING FUNCTIONS
athos@1241
    70
athos@1241
    71
    /// \e
athos@1241
    72
    void setMinimize() { 
athos@1241
    73
      lpx_set_obj_dir(lp, LPX_MIN);
athos@1241
    74
    }
athos@1241
    75
    /// \e
athos@1241
    76
    void setMaximize() { 
athos@1241
    77
      lpx_set_obj_dir(lp, LPX_MAX);
athos@1241
    78
    }
athos@1241
    79
athos@1241
    80
    //LOW LEVEL INTERFACE, MATRIX MANIPULATING FUNCTIONS
athos@1241
    81
athos@1241
    82
  protected:
athos@1241
    83
    /// \e
athos@1241
    84
    int _addCol() { 
athos@1241
    85
      int i=lpx_add_cols(lp, 1);
athos@1241
    86
      _setColLowerBound(i, -INF);
athos@1241
    87
      _setColUpperBound(i, INF);
athos@1241
    88
      return i;
athos@1241
    89
    }
athos@1241
    90
    /// \e
athos@1241
    91
    int _addRow() { 
athos@1241
    92
      int i=lpx_add_rows(lp, 1);
athos@1241
    93
      return i;
athos@1241
    94
    }
athos@1241
    95
    /// \e
athos@1241
    96
    virtual void _setRowCoeffs(int i, 
athos@1241
    97
			       const std::vector<std::pair<int, double> >& coeffs) {
athos@1241
    98
      int mem_length=1+colNum();
athos@1241
    99
      int* indices = new int[mem_length];
athos@1241
   100
      double* doubles = new double[mem_length];
athos@1241
   101
      int length=0;
athos@1241
   102
      for (std::vector<std::pair<int, double> >::
athos@1241
   103
	     const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
athos@1241
   104
	++length;
athos@1241
   105
	indices[length]=it->first;
athos@1241
   106
	doubles[length]=it->second;
athos@1241
   107
      }
athos@1241
   108
      lpx_set_mat_row(lp, i, length, indices, doubles);
athos@1241
   109
      delete [] indices;
athos@1241
   110
      delete [] doubles;
athos@1241
   111
    }
athos@1241
   112
    /// \e
athos@1241
   113
    virtual void _getRowCoeffs(int i, 
athos@1241
   114
			       std::vector<std::pair<int, double> >& coeffs) {
athos@1241
   115
      int mem_length=1+colNum();
athos@1241
   116
      int* indices = new int[mem_length];
athos@1241
   117
      double* doubles = new double[mem_length];
athos@1241
   118
      int length=lpx_get_mat_row(lp, i, indices, doubles);
athos@1241
   119
      for (int i=1; i<=length; ++i) {
athos@1241
   120
	coeffs.push_back(std::make_pair(indices[i], doubles[i]));
athos@1241
   121
      }
athos@1241
   122
      delete [] indices;
athos@1241
   123
      delete [] doubles;
athos@1241
   124
    }
athos@1241
   125
    /// \e
athos@1241
   126
    virtual void _setColCoeffs(int i, 
athos@1241
   127
			       const std::vector<std::pair<int, double> >& coeffs) {
athos@1241
   128
      int mem_length=1+rowNum();
athos@1241
   129
      int* indices = new int[mem_length];
athos@1241
   130
      double* doubles = new double[mem_length];
athos@1241
   131
      int length=0;
athos@1241
   132
      for (std::vector<std::pair<int, double> >::
athos@1241
   133
	     const_iterator it=coeffs.begin(); it!=coeffs.end(); ++it) {
athos@1241
   134
	++length;
athos@1241
   135
	indices[length]=it->first;
athos@1241
   136
	doubles[length]=it->second;
athos@1241
   137
      }
athos@1241
   138
      lpx_set_mat_col(lp, i, length, indices, doubles);
athos@1241
   139
      delete [] indices;
athos@1241
   140
      delete [] doubles;
athos@1241
   141
    }
athos@1241
   142
    /// \e
athos@1241
   143
    virtual void _getColCoeffs(int i, 
athos@1241
   144
			       std::vector<std::pair<int, double> >& coeffs) {
athos@1241
   145
      int mem_length=1+rowNum();
athos@1241
   146
      int* indices = new int[mem_length];
athos@1241
   147
      double* doubles = new double[mem_length];
athos@1241
   148
      int length=lpx_get_mat_col(lp, i, indices, doubles);
athos@1241
   149
      for (int i=1; i<=length; ++i) {
athos@1241
   150
	coeffs.push_back(std::make_pair(indices[i], doubles[i]));
athos@1241
   151
      }
athos@1241
   152
      delete [] indices;
athos@1241
   153
      delete [] doubles;
athos@1241
   154
    }
athos@1241
   155
    /// \e
athos@1241
   156
    virtual void _eraseCol(int i) {
athos@1241
   157
      int cols[2];
athos@1241
   158
      cols[1]=i;
athos@1241
   159
      lpx_del_cols(lp, 1, cols);
athos@1241
   160
    }
athos@1241
   161
    virtual void _eraseRow(int i) {
athos@1241
   162
      int rows[2];
athos@1241
   163
      rows[1]=i;
athos@1241
   164
      lpx_del_rows(lp, 1, rows);
athos@1241
   165
    }
athos@1241
   166
    void _setCoeff(int col, int row, double value) {
athos@1243
   167
      ///FIXME Of course this is not efficient at all, but GLPK knows not more.
athos@1243
   168
      int change_this;
athos@1243
   169
      bool get_set_row;
athos@1243
   170
      //The only thing we can do is optimize on whether working with a row 
athos@1243
   171
      //or a coloumn
athos@1243
   172
      int row_num = rowNum();
athos@1243
   173
      int col_num = colNum();
athos@1243
   174
      if (col_num<row_num){
athos@1243
   175
	//There are more rows than coloumns
athos@1243
   176
	get_set_row=true;
athos@1243
   177
	int mem_length=1+row_num;
athos@1243
   178
	int* indices = new int[mem_length];
athos@1243
   179
	double* doubles = new double[mem_length];
athos@1243
   180
	int length=lpx_get_mat_col(lp, i, indices, doubles);
athos@1243
   181
      }else{
athos@1243
   182
	get_set_row=false;
athos@1243
   183
	int mem_length=1+col_num;
athos@1243
   184
	int* indices = new int[mem_length];
athos@1243
   185
	double* doubles = new double[mem_length];
athos@1243
   186
	int length=lpx_get_mat_row(lp, i, indices, doubles);
athos@1243
   187
      }
athos@1243
   188
      //Itten      
athos@1243
   189
int* indices = new int[mem_length];
athos@1243
   190
      double* doubles = new double[mem_length];
athos@1243
   191
      int length=lpx_get_mat_col(lp, i, indices, doubles);
athos@1243
   192
 
athos@1243
   193
      delete [] indices;
athos@1243
   194
      delete [] doubles;
athos@1243
   195
athos@1241
   196
    }
athos@1241
   197
    double _getCoeff(int col, int row) {
athos@1241
   198
      /// FIXME not yet implemented
athos@1241
   199
      return 0.0;
athos@1241
   200
    }
athos@1241
   201
    virtual void _setColLowerBound(int i, double lo) {
athos@1241
   202
      if (lo==INF) {
athos@1241
   203
	//FIXME error
athos@1241
   204
      }
athos@1241
   205
      int b=lpx_get_col_type(lp, i);
athos@1241
   206
      double up=lpx_get_col_ub(lp, i);	
athos@1241
   207
      if (lo==-INF) {
athos@1241
   208
	switch (b) {
athos@1241
   209
	case LPX_FR:
athos@1241
   210
	case LPX_LO:
athos@1241
   211
	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
athos@1241
   212
	  break;
athos@1241
   213
	case LPX_UP:
athos@1241
   214
	  break;
athos@1241
   215
	case LPX_DB:
athos@1241
   216
	case LPX_FX:
athos@1241
   217
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
athos@1241
   218
	  break;
athos@1241
   219
	default: ;
athos@1241
   220
	  //FIXME error
athos@1241
   221
	}
athos@1241
   222
      } else {
athos@1241
   223
	switch (b) {
athos@1241
   224
	case LPX_FR:
athos@1241
   225
	case LPX_LO:
athos@1241
   226
	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
athos@1241
   227
	  break;
athos@1241
   228
	case LPX_UP:	  
athos@1241
   229
	case LPX_DB:
athos@1241
   230
	case LPX_FX:
athos@1241
   231
	  if (lo==up) 
athos@1241
   232
	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
athos@1241
   233
	  else 
athos@1241
   234
	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
athos@1241
   235
	  break;
athos@1241
   236
	default: ;
athos@1241
   237
	  //FIXME error
athos@1241
   238
	}
athos@1241
   239
      }
athos@1241
   240
    }
athos@1241
   241
    virtual double _getColLowerBound(int i) {
athos@1241
   242
      int b=lpx_get_col_type(lp, i);
athos@1241
   243
      switch (b) {
athos@1241
   244
      case LPX_FR:
athos@1241
   245
	return -INF;
athos@1241
   246
      case LPX_LO:
athos@1241
   247
	return lpx_get_col_lb(lp, i);
athos@1241
   248
      case LPX_UP:
athos@1241
   249
	return -INF;
athos@1241
   250
      case LPX_DB:
athos@1241
   251
      case LPX_FX:
athos@1241
   252
	return lpx_get_col_lb(lp, i);
athos@1241
   253
      default: ;
athos@1241
   254
	//FIXME error
athos@1241
   255
	return 0.0;
athos@1241
   256
      }
athos@1241
   257
    }
athos@1241
   258
    virtual void _setColUpperBound(int i, double up) {
athos@1241
   259
      if (up==-INF) {
athos@1241
   260
	//FIXME error
athos@1241
   261
      }
athos@1241
   262
      int b=lpx_get_col_type(lp, i);
athos@1241
   263
      double lo=lpx_get_col_lb(lp, i);
athos@1241
   264
      if (up==INF) {
athos@1241
   265
	switch (b) {
athos@1241
   266
	case LPX_FR:
athos@1241
   267
	case LPX_LO:
athos@1241
   268
	  break;
athos@1241
   269
	case LPX_UP:
athos@1241
   270
	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
athos@1241
   271
	  break;
athos@1241
   272
	case LPX_DB:
athos@1241
   273
	case LPX_FX:
athos@1241
   274
	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
athos@1241
   275
	  break;
athos@1241
   276
	default: ;
athos@1241
   277
	  //FIXME error
athos@1241
   278
	}
athos@1241
   279
      } else {
athos@1241
   280
	switch (b) {
athos@1241
   281
	case LPX_FR:
athos@1241
   282
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
athos@1241
   283
	case LPX_LO:
athos@1241
   284
	  if (lo==up) 
athos@1241
   285
	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
athos@1241
   286
	  else
athos@1241
   287
	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
athos@1241
   288
	  break;
athos@1241
   289
	case LPX_UP:
athos@1241
   290
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
athos@1241
   291
	  break;
athos@1241
   292
	case LPX_DB:
athos@1241
   293
	case LPX_FX:
athos@1241
   294
	  if (lo==up) 
athos@1241
   295
	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
athos@1241
   296
	  else 
athos@1241
   297
	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
athos@1241
   298
	  break;
athos@1241
   299
	default: ;
athos@1241
   300
	  //FIXME error
athos@1241
   301
	}
athos@1241
   302
      }
athos@1241
   303
    }
athos@1241
   304
    virtual double _getColUpperBound(int i) {
athos@1241
   305
      int b=lpx_get_col_type(lp, i);
athos@1241
   306
      switch (b) {
athos@1241
   307
      case LPX_FR:
athos@1241
   308
      case LPX_LO:
athos@1241
   309
	return INF;
athos@1241
   310
      case LPX_UP:
athos@1241
   311
      case LPX_DB:
athos@1241
   312
      case LPX_FX:
athos@1241
   313
	return lpx_get_col_ub(lp, i);
athos@1241
   314
      default: ;
athos@1241
   315
	//FIXME error
athos@1241
   316
	return 0.0;
athos@1241
   317
      }
athos@1241
   318
    }
athos@1241
   319
    virtual void _setRowLowerBound(int i, double lo) {
athos@1241
   320
      if (lo==INF) {
athos@1241
   321
	//FIXME error
athos@1241
   322
      }
athos@1241
   323
      int b=lpx_get_row_type(lp, i);
athos@1241
   324
      double up=lpx_get_row_ub(lp, i);	
athos@1241
   325
      if (lo==-INF) {
athos@1241
   326
	switch (b) {
athos@1241
   327
	case LPX_FR:
athos@1241
   328
	case LPX_LO:
athos@1241
   329
	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
athos@1241
   330
	  break;
athos@1241
   331
	case LPX_UP:
athos@1241
   332
	  break;
athos@1241
   333
	case LPX_DB:
athos@1241
   334
	case LPX_FX:
athos@1241
   335
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1241
   336
	  break;
athos@1241
   337
	default: ;
athos@1241
   338
	  //FIXME error
athos@1241
   339
	}
athos@1241
   340
      } else {
athos@1241
   341
	switch (b) {
athos@1241
   342
	case LPX_FR:
athos@1241
   343
	case LPX_LO:
athos@1241
   344
	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
athos@1241
   345
	  break;
athos@1241
   346
	case LPX_UP:	  
athos@1241
   347
	case LPX_DB:
athos@1241
   348
	case LPX_FX:
athos@1241
   349
	  if (lo==up) 
athos@1241
   350
	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1241
   351
	  else 
athos@1241
   352
	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1241
   353
	  break;
athos@1241
   354
	default: ;
athos@1241
   355
	  //FIXME error
athos@1241
   356
	}
athos@1241
   357
      }
athos@1241
   358
    }
athos@1241
   359
    virtual double _getRowLowerBound(int i) {
athos@1241
   360
      int b=lpx_get_row_type(lp, i);
athos@1241
   361
      switch (b) {
athos@1241
   362
      case LPX_FR:
athos@1241
   363
	return -INF;
athos@1241
   364
      case LPX_LO:
athos@1241
   365
	return lpx_get_row_lb(lp, i);
athos@1241
   366
      case LPX_UP:
athos@1241
   367
	return -INF;
athos@1241
   368
      case LPX_DB:
athos@1241
   369
      case LPX_FX:
athos@1241
   370
	return lpx_get_row_lb(lp, i);
athos@1241
   371
      default: ;
athos@1241
   372
	//FIXME error
athos@1241
   373
	return 0.0;
athos@1241
   374
      }
athos@1241
   375
    }
athos@1241
   376
    virtual void _setRowUpperBound(int i, double up) {
athos@1241
   377
      if (up==-INF) {
athos@1241
   378
	//FIXME error
athos@1241
   379
      }
athos@1241
   380
      int b=lpx_get_row_type(lp, i);
athos@1241
   381
      double lo=lpx_get_row_lb(lp, i);
athos@1241
   382
      if (up==INF) {
athos@1241
   383
	switch (b) {
athos@1241
   384
	case LPX_FR:
athos@1241
   385
	case LPX_LO:
athos@1241
   386
	  break;
athos@1241
   387
	case LPX_UP:
athos@1241
   388
	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
athos@1241
   389
	  break;
athos@1241
   390
	case LPX_DB:
athos@1241
   391
	case LPX_FX:
athos@1241
   392
	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
athos@1241
   393
	  break;
athos@1241
   394
	default: ;
athos@1241
   395
	  //FIXME error
athos@1241
   396
	}
athos@1241
   397
      } else {
athos@1241
   398
	switch (b) {
athos@1241
   399
	case LPX_FR:
athos@1241
   400
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1241
   401
	case LPX_LO:
athos@1241
   402
	  if (lo==up) 
athos@1241
   403
	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1241
   404
	  else
athos@1241
   405
	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1241
   406
	  break;
athos@1241
   407
	case LPX_UP:
athos@1241
   408
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1241
   409
	  break;
athos@1241
   410
	case LPX_DB:
athos@1241
   411
	case LPX_FX:
athos@1241
   412
	  if (lo==up) 
athos@1241
   413
	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1241
   414
	  else 
athos@1241
   415
	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1241
   416
	  break;
athos@1241
   417
	default: ;
athos@1241
   418
	  //FIXME error
athos@1241
   419
	}
athos@1241
   420
      }
athos@1241
   421
    }
athos@1241
   422
    virtual double _getRowUpperBound(int i) {
athos@1241
   423
      int b=lpx_get_row_type(lp, i);
athos@1241
   424
      switch (b) {
athos@1241
   425
      case LPX_FR:
athos@1241
   426
      case LPX_LO:
athos@1241
   427
	return INF;
athos@1241
   428
      case LPX_UP:
athos@1241
   429
      case LPX_DB:
athos@1241
   430
      case LPX_FX:
athos@1241
   431
	return lpx_get_row_ub(lp, i);
athos@1241
   432
      default: ;
athos@1241
   433
	//FIXME error
athos@1241
   434
	return 0.0;
athos@1241
   435
      }
athos@1241
   436
    }
athos@1241
   437
    /// \e
athos@1241
   438
    virtual double _getObjCoeff(int i) { 
athos@1241
   439
      return lpx_get_obj_coef(lp, i);
athos@1241
   440
    }
athos@1241
   441
    /// \e
athos@1241
   442
    virtual void _setObjCoeff(int i, double obj_coef) { 
athos@1241
   443
      lpx_set_obj_coef(lp, i, obj_coef);
athos@1241
   444
    }
athos@1241
   445
  public:
athos@1241
   446
    /// \e
athos@1241
   447
    void solveSimplex() { lpx_simplex(lp); }
athos@1241
   448
    /// \e
athos@1241
   449
    void solvePrimalSimplex() { lpx_simplex(lp); }
athos@1241
   450
    /// \e
athos@1241
   451
    void solveDualSimplex() { lpx_simplex(lp); }
athos@1241
   452
  protected:
athos@1241
   453
    virtual double _getPrimal(int i) {
athos@1241
   454
      return lpx_get_col_prim(lp, i);
athos@1241
   455
    }
athos@1241
   456
  public:
athos@1241
   457
    /// \e
athos@1241
   458
    double getObjVal() { return lpx_get_obj_val(lp); }
athos@1241
   459
    /// \e
athos@1241
   460
    int rowNum() const { return lpx_get_num_rows(lp); }
athos@1241
   461
    /// \e
athos@1241
   462
    int colNum() const { return lpx_get_num_cols(lp); }
athos@1241
   463
    /// \e
athos@1241
   464
    int warmUp() { return lpx_warm_up(lp); }
athos@1241
   465
    /// \e
athos@1241
   466
    void printWarmUpStatus(int i) {
athos@1241
   467
      switch (i) {
athos@1241
   468
      case LPX_E_OK: cout << "LPX_E_OK" << endl; break;
athos@1241
   469
      case LPX_E_EMPTY: cout << "LPX_E_EMPTY" << endl; break;	
athos@1241
   470
      case LPX_E_BADB: cout << "LPX_E_BADB" << endl; break;
athos@1241
   471
      case LPX_E_SING: cout << "LPX_E_SING" << endl; break;
athos@1241
   472
      }
athos@1241
   473
    }
athos@1241
   474
    /// \e
athos@1241
   475
    int getPrimalStatus() { return lpx_get_prim_stat(lp); }
athos@1241
   476
    /// \e
athos@1241
   477
    void printPrimalStatus(int i) {
athos@1241
   478
      switch (i) {
athos@1241
   479
      case LPX_P_UNDEF: cout << "LPX_P_UNDEF" << endl; break;
athos@1241
   480
      case LPX_P_FEAS: cout << "LPX_P_FEAS" << endl; break;	
athos@1241
   481
      case LPX_P_INFEAS: cout << "LPX_P_INFEAS" << endl; break;
athos@1241
   482
      case LPX_P_NOFEAS: cout << "LPX_P_NOFEAS" << endl; break;
athos@1241
   483
      }
athos@1241
   484
    }
athos@1241
   485
    /// \e
athos@1241
   486
    int getDualStatus() { return lpx_get_dual_stat(lp); }
athos@1241
   487
    /// \e
athos@1241
   488
    void printDualStatus(int i) {
athos@1241
   489
      switch (i) {
athos@1241
   490
      case LPX_D_UNDEF: cout << "LPX_D_UNDEF" << endl; break;
athos@1241
   491
      case LPX_D_FEAS: cout << "LPX_D_FEAS" << endl; break;	
athos@1241
   492
      case LPX_D_INFEAS: cout << "LPX_D_INFEAS" << endl; break;
athos@1241
   493
      case LPX_D_NOFEAS: cout << "LPX_D_NOFEAS" << endl; break;
athos@1241
   494
      }
athos@1241
   495
    }
athos@1241
   496
    /// Returns the status of the slack variable assigned to row \c row.
athos@1241
   497
    int getRowStat(const Row& row) { 
athos@1241
   498
      return lpx_get_row_stat(lp, row_iter_map[row]); 
athos@1241
   499
    }
athos@1241
   500
    /// \e
athos@1241
   501
    void printRowStatus(int i) {
athos@1241
   502
      switch (i) {
athos@1241
   503
      case LPX_BS: cout << "LPX_BS" << endl; break;
athos@1241
   504
      case LPX_NL: cout << "LPX_NL" << endl; break;	
athos@1241
   505
      case LPX_NU: cout << "LPX_NU" << endl; break;
athos@1241
   506
      case LPX_NF: cout << "LPX_NF" << endl; break;
athos@1241
   507
      case LPX_NS: cout << "LPX_NS" << endl; break;
athos@1241
   508
      }
athos@1241
   509
    }
athos@1241
   510
    /// Returns the status of the variable assigned to column \c col.
athos@1241
   511
    int getColStat(const Col& col) { 
athos@1241
   512
      return lpx_get_col_stat(lp, col_iter_map[col]); 
athos@1241
   513
    }
athos@1241
   514
    /// \e
athos@1241
   515
    void printColStatus(int i) {
athos@1241
   516
      switch (i) {
athos@1241
   517
      case LPX_BS: cout << "LPX_BS" << endl; break;
athos@1241
   518
      case LPX_NL: cout << "LPX_NL" << endl; break;	
athos@1241
   519
      case LPX_NU: cout << "LPX_NU" << endl; break;
athos@1241
   520
      case LPX_NF: cout << "LPX_NF" << endl; break;
athos@1241
   521
      case LPX_NS: cout << "LPX_NS" << endl; break;
athos@1241
   522
      }
athos@1241
   523
    }
athos@1241
   524
athos@1241
   525
    // MIP
athos@1241
   526
    /// \e
athos@1241
   527
    void solveBandB() { lpx_integer(lp); }
athos@1241
   528
    /// \e
athos@1241
   529
    void setLP() { lpx_set_class(lp, LPX_LP); }
athos@1241
   530
    /// \e
athos@1241
   531
    void setMIP() { lpx_set_class(lp, LPX_MIP); }
athos@1241
   532
  protected:
athos@1241
   533
    /// \e
athos@1241
   534
    void _setColCont(int i) { lpx_set_col_kind(lp, i, LPX_CV); }
athos@1241
   535
    /// \e
athos@1241
   536
    void _setColInt(int i) { lpx_set_col_kind(lp, i, LPX_IV); }
athos@1241
   537
    /// \e
athos@1241
   538
    double _getMIPPrimal(int i) { return lpx_mip_col_val(lp, i); }
athos@1241
   539
  };
athos@1241
   540
  
athos@1241
   541
  /// @}
athos@1241
   542
athos@1241
   543
} //namespace lemon
athos@1241
   544
athos@1241
   545
#endif //LEMON_LP_SOLVER_GLPK_H