lemon/lp_glpk.cc
author deba
Wed, 29 Nov 2006 15:01:13 +0000
changeset 2312 07e46cbb7d85
parent 2253 1645f6cc9667
child 2321 e23a610bed51
permissions -rw-r--r--
modified _setColCoeff and _setRowCoeff parameters
const simplify() for expressions
athos@1261
     1
/* -*- C++ -*-
athos@1261
     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@1261
     8
 *
athos@1261
     9
 * Permission to use, modify and distribute this software is granted
athos@1261
    10
 * provided that this copyright notice appears in all copies. For
athos@1261
    11
 * precise terms see the accompanying LICENSE file.
athos@1261
    12
 *
athos@1261
    13
 * This software is provided "AS IS" with no warranty of any kind,
athos@1261
    14
 * express or implied, and with no claim as to its suitability for any
athos@1261
    15
 * purpose.
athos@1261
    16
 *
athos@1261
    17
 */
athos@1261
    18
athos@1261
    19
///\file
athos@1261
    20
///\brief Implementation of the LEMON-GLPK lp solver interface.
athos@1261
    21
ladanyi@1305
    22
#include <lemon/lp_glpk.h>
athos@1473
    23
//#include <iostream>
athos@1261
    24
namespace lemon {
athos@1261
    25
alpar@1364
    26
alpar@1321
    27
  LpGlpk::LpGlpk() : Parent(), 
alpar@1321
    28
		     lp(lpx_create_prob()) {
alpar@1321
    29
    ///\todo constrol function for this:
alpar@1321
    30
    lpx_set_int_parm(lp, LPX_K_DUAL, 1);
alpar@1321
    31
    messageLevel(0);
alpar@1321
    32
  }
alpar@1321
    33
  
alpar@1321
    34
  LpGlpk::~LpGlpk() {
alpar@1321
    35
    lpx_delete_prob(lp);
alpar@1321
    36
  }
alpar@1321
    37
  
alpar@1321
    38
  int LpGlpk::_addCol() { 
alpar@1321
    39
    int i=lpx_add_cols(lp, 1);
alpar@1321
    40
    _setColLowerBound(i, -INF);
alpar@1321
    41
    _setColUpperBound(i, INF);
alpar@1321
    42
    return i;
alpar@1321
    43
  }
alpar@1321
    44
athos@1436
    45
  ///\e
athos@1436
    46
athos@1436
    47
athos@1436
    48
  LpSolverBase &LpGlpk::_newLp()
athos@1436
    49
  {
athos@1436
    50
    LpGlpk* newlp=new LpGlpk();
athos@1436
    51
    return *newlp;
athos@1436
    52
  }
athos@1436
    53
  
athos@1436
    54
  ///\e
athos@1436
    55
athos@1436
    56
  LpSolverBase &LpGlpk::_copyLp()
athos@1436
    57
  {
athos@1436
    58
    LpGlpk* newlp=new LpGlpk();
athos@1436
    59
athos@1436
    60
    //Coefficient matrix, row bounds
athos@1436
    61
    lpx_add_rows(newlp->lp, lpx_get_num_rows(lp));
athos@1436
    62
    lpx_add_cols(newlp->lp, lpx_get_num_cols(lp));
athos@1436
    63
    int len;
athos@1436
    64
    int ind[1+lpx_get_num_cols(lp)];
athos@1436
    65
    Value val[1+lpx_get_num_cols(lp)];
athos@1436
    66
    for (int i=1;i<=lpx_get_num_rows(lp);++i){
athos@1436
    67
      len=lpx_get_mat_row(lp,i,ind,val);
athos@1436
    68
      lpx_set_mat_row(newlp->lp, i,len,ind,val);
athos@1436
    69
      lpx_set_row_bnds(newlp->lp,i,lpx_get_row_type(lp,i),
athos@1436
    70
		       lpx_get_row_lb(lp,i),lpx_get_row_ub(lp,i));
athos@1436
    71
    }
athos@1436
    72
athos@1436
    73
    //Objective function, coloumn bounds
athos@1436
    74
    lpx_set_obj_dir(newlp->lp, lpx_get_obj_dir(lp));
athos@1436
    75
    //Objectif function's constant term treated separately
athos@1436
    76
    lpx_set_obj_coef(newlp->lp,0,lpx_get_obj_coef(lp,0));
athos@1436
    77
    for (int i=1;i<=lpx_get_num_cols(lp);++i){
athos@1436
    78
      lpx_set_obj_coef(newlp->lp,i,lpx_get_obj_coef(lp,i));
athos@1436
    79
      lpx_set_col_bnds(newlp->lp,i,lpx_get_col_type(lp,i),
athos@1436
    80
		       lpx_get_col_lb(lp,i),lpx_get_col_ub(lp,i));
athos@1436
    81
      
athos@1436
    82
      
athos@1436
    83
    }
athos@1436
    84
athos@1436
    85
    return *newlp;
athos@1436
    86
  }
athos@1436
    87
alpar@1321
    88
  int LpGlpk::_addRow() { 
alpar@1321
    89
    int i=lpx_add_rows(lp, 1);
alpar@1321
    90
    return i;
alpar@1321
    91
  }
alpar@1321
    92
alpar@1321
    93
  
athos@1432
    94
  void LpGlpk::_eraseCol(int i) {
athos@1432
    95
    int cols[2];
athos@1432
    96
    cols[1]=i;
athos@1432
    97
    lpx_del_cols(lp, 1, cols);
athos@1432
    98
  }
athos@1432
    99
  
athos@1432
   100
  void LpGlpk::_eraseRow(int i) {
athos@1432
   101
    int rows[2];
athos@1432
   102
    rows[1]=i;
athos@1432
   103
    lpx_del_rows(lp, 1, rows);
athos@1432
   104
  }
athos@1432
   105
alpar@1895
   106
  void LpGlpk::_getColName(int col, std::string & name)
alpar@1895
   107
  {
alpar@1895
   108
    
alpar@1895
   109
    char *n = lpx_get_col_name(lp,col);
alpar@1895
   110
    name = n?n:"";
alpar@1895
   111
  }
alpar@1895
   112
  
alpar@1895
   113
  
alpar@1895
   114
  void LpGlpk::_setColName(int col, const std::string & name)
alpar@1895
   115
  {
alpar@1895
   116
    lpx_set_col_name(lp,col,const_cast<char*>(name.c_str()));
alpar@1895
   117
  }
alpar@1895
   118
  
deba@2312
   119
  void LpGlpk::_setRowCoeffs(int i, LpRowIterator b, LpRowIterator e) 
alpar@1321
   120
  {
deba@2312
   121
    std::vector<int> indices;
deba@2312
   122
    std::vector<Value> values;
deba@2312
   123
deba@2312
   124
    indices.push_back(0);
deba@2312
   125
    values.push_back(0);
deba@2312
   126
deba@2312
   127
    for(LpRowIterator it=b; it!=e; ++it) {
deba@2312
   128
      indices.push_back(it->first);
deba@2312
   129
      values.push_back(it->second);
deba@2312
   130
    }
deba@2312
   131
deba@2312
   132
    lpx_set_mat_row(lp, i, values.size() - 1, &indices[0], &values[0]);
alpar@1321
   133
  }
alpar@1321
   134
  
deba@2312
   135
  void LpGlpk::_setColCoeffs(int i, LpColIterator b, LpColIterator e) {
deba@2312
   136
deba@2312
   137
    std::vector<int> indices;
deba@2312
   138
    std::vector<Value> values;
deba@2312
   139
deba@2312
   140
    indices.push_back(0);
deba@2312
   141
    values.push_back(0);
deba@2312
   142
deba@2312
   143
    for(LpColIterator it=b; it!=e; ++it) {
deba@2312
   144
      indices.push_back(it->first);
deba@2312
   145
      values.push_back(it->second);
deba@2312
   146
    }
deba@2312
   147
    
deba@2312
   148
    lpx_set_mat_col(lp, i, values.size() - 1, &indices[0], &values[0]);
alpar@1321
   149
  }
athos@1431
   150
athos@1431
   151
athos@1431
   152
  void LpGlpk::_setCoeff(int row, int col, Value value) 
athos@1431
   153
  {
deba@2312
   154
deba@2312
   155
    if (lpx_get_num_cols(lp) < lpx_get_num_rows(lp)) {
deba@2312
   156
deba@2312
   157
      int length=lpx_get_mat_row(lp, row, 0, 0);
deba@2312
   158
      
deba@2312
   159
      std::vector<int> indices(length + 2);
deba@2312
   160
      std::vector<Value> values(length + 2);
deba@2312
   161
      
deba@2312
   162
      lpx_get_mat_row(lp, row, &indices[0], &values[0]);
deba@2312
   163
      
deba@2312
   164
      //The following code does not suppose that the elements of the
deba@2312
   165
      //array indices are sorted
deba@2312
   166
      bool found=false;
deba@2312
   167
      for (int i = 1; i <= length; ++i) {
deba@2312
   168
        if (indices[i]==col){
deba@2312
   169
          found=true;
deba@2312
   170
          values[i]=value;
deba@2312
   171
          break;
deba@2312
   172
        }
deba@2312
   173
      }
deba@2312
   174
      if (!found){
deba@2312
   175
        ++length;
deba@2312
   176
        indices[length]=col;
deba@2312
   177
        values[length]=value;
deba@2312
   178
      }
athos@1431
   179
    
deba@2312
   180
      lpx_set_mat_row(lp, row, length, &indices[0], &values[0]);
deba@2312
   181
deba@2312
   182
    } else {
deba@2312
   183
deba@2312
   184
      int length=lpx_get_mat_col(lp, col, 0, 0);
deba@2312
   185
      
deba@2312
   186
      std::vector<int> indices(length + 2);
deba@2312
   187
      std::vector<Value> values(length + 2);
deba@2312
   188
      
deba@2312
   189
      lpx_get_mat_col(lp, col, &indices[0], &values[0]);
deba@2312
   190
      
deba@2312
   191
      //The following code does not suppose that the elements of the
deba@2312
   192
      //array indices are sorted
deba@2312
   193
      bool found=false;
deba@2312
   194
      for (int i = 1; i <= length; ++i) {
deba@2312
   195
        if (indices[i]==col){
deba@2312
   196
          found=true;
deba@2312
   197
          values[i]=value;
deba@2312
   198
          break;
deba@2312
   199
        }
deba@2312
   200
      }
deba@2312
   201
      if (!found){
deba@2312
   202
        ++length;
deba@2312
   203
        indices[length]=row;
deba@2312
   204
        values[length]=value;
deba@2312
   205
      }
athos@1431
   206
    
deba@2312
   207
      lpx_set_mat_col(lp, col, length, &indices[0], &values[0]);
athos@1431
   208
    }
athos@1431
   209
  }
athos@1431
   210
alpar@1321
   211
  void LpGlpk::_setColLowerBound(int i, Value lo)
alpar@1321
   212
  {
alpar@1321
   213
    if (lo==INF) {
alpar@1321
   214
      //FIXME error
alpar@1321
   215
    }
alpar@1321
   216
    int b=lpx_get_col_type(lp, i);
alpar@1321
   217
    double up=lpx_get_col_ub(lp, i);	
alpar@1321
   218
    if (lo==-INF) {
alpar@1321
   219
      switch (b) {
alpar@1321
   220
      case LPX_FR:
alpar@1321
   221
      case LPX_LO:
alpar@1321
   222
	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
alpar@1321
   223
	break;
alpar@1321
   224
      case LPX_UP:
alpar@1321
   225
	break;
alpar@1321
   226
      case LPX_DB:
alpar@1321
   227
      case LPX_FX:
alpar@1321
   228
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   229
	break;
alpar@1321
   230
      default: ;
alpar@1321
   231
	//FIXME error
alpar@1321
   232
      }
alpar@1321
   233
    } else {
alpar@1321
   234
      switch (b) {
alpar@1321
   235
      case LPX_FR:
alpar@1321
   236
      case LPX_LO:
alpar@1321
   237
	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
alpar@1321
   238
	break;
alpar@1321
   239
      case LPX_UP:	  
alpar@1321
   240
      case LPX_DB:
alpar@1321
   241
      case LPX_FX:
alpar@1321
   242
	if (lo==up) 
alpar@1321
   243
	  lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
alpar@1321
   244
	else 
alpar@1321
   245
	  lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
alpar@1321
   246
	break;
alpar@1321
   247
      default: ;
alpar@1321
   248
	//FIXME error
alpar@1321
   249
      }
athos@1261
   250
    }
athos@1261
   251
alpar@1321
   252
  }
alpar@1321
   253
  
alpar@1321
   254
  void LpGlpk::_setColUpperBound(int i, Value up)
alpar@1321
   255
  {
alpar@1321
   256
    if (up==-INF) {
alpar@1321
   257
      //FIXME error
athos@1261
   258
    }
alpar@1321
   259
    int b=lpx_get_col_type(lp, i);
alpar@1321
   260
    double lo=lpx_get_col_lb(lp, i);
alpar@1321
   261
    if (up==INF) {
alpar@1321
   262
      switch (b) {
alpar@1321
   263
      case LPX_FR:
alpar@1321
   264
      case LPX_LO:
alpar@1321
   265
	break;
alpar@1321
   266
      case LPX_UP:
alpar@1321
   267
	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
alpar@1321
   268
	break;
alpar@1321
   269
      case LPX_DB:
alpar@1321
   270
      case LPX_FX:
alpar@1321
   271
	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
alpar@1321
   272
	break;
alpar@1321
   273
      default: ;
athos@1261
   274
	//FIXME error
athos@1261
   275
      }
alpar@1321
   276
    } else {
alpar@1321
   277
      switch (b) {
alpar@1321
   278
      case LPX_FR:
alpar@1321
   279
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   280
	break;
alpar@1321
   281
      case LPX_UP:
alpar@1321
   282
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   283
	break;
alpar@1321
   284
      case LPX_LO:
alpar@1321
   285
      case LPX_DB:
alpar@1321
   286
      case LPX_FX:
alpar@1321
   287
	if (lo==up) 
alpar@1321
   288
	  lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
alpar@1321
   289
	else 
alpar@1321
   290
	  lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
alpar@1321
   291
	break;
alpar@1321
   292
      default: ;
athos@1261
   293
	//FIXME error
athos@1261
   294
      }
alpar@1321
   295
    }
alpar@1321
   296
  }
alpar@1321
   297
  
athos@1405
   298
//   void LpGlpk::_setRowLowerBound(int i, Value lo)
athos@1405
   299
//   {
athos@1405
   300
//     if (lo==INF) {
athos@1405
   301
//       //FIXME error
athos@1405
   302
//     }
athos@1405
   303
//     int b=lpx_get_row_type(lp, i);
athos@1405
   304
//     double up=lpx_get_row_ub(lp, i);	
athos@1405
   305
//     if (lo==-INF) {
athos@1405
   306
//       switch (b) {
athos@1405
   307
//       case LPX_FR:
athos@1405
   308
//       case LPX_LO:
athos@1405
   309
// 	lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
athos@1405
   310
// 	break;
athos@1405
   311
//       case LPX_UP:
athos@1405
   312
// 	break;
athos@1405
   313
//       case LPX_DB:
athos@1405
   314
//       case LPX_FX:
athos@1405
   315
// 	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1405
   316
// 	break;
athos@1405
   317
//       default: ;
athos@1405
   318
// 	//FIXME error
athos@1405
   319
//       }
athos@1405
   320
//     } else {
athos@1405
   321
//       switch (b) {
athos@1405
   322
//       case LPX_FR:
athos@1405
   323
//       case LPX_LO:
athos@1405
   324
// 	lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
athos@1405
   325
// 	break;
athos@1405
   326
//       case LPX_UP:	  
athos@1405
   327
//       case LPX_DB:
athos@1405
   328
//       case LPX_FX:
athos@1405
   329
// 	if (lo==up) 
athos@1405
   330
// 	  lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1405
   331
// 	else 
athos@1405
   332
// 	  lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1405
   333
// 	break;
athos@1405
   334
//       default: ;
athos@1405
   335
// 	//FIXME error
athos@1405
   336
//       }
athos@1405
   337
//     }
athos@1405
   338
//   }
athos@1261
   339
  
athos@1405
   340
//   void LpGlpk::_setRowUpperBound(int i, Value up)
athos@1405
   341
//   {
athos@1405
   342
//     if (up==-INF) {
athos@1405
   343
//       //FIXME error
athos@1405
   344
//     }
athos@1405
   345
//     int b=lpx_get_row_type(lp, i);
athos@1405
   346
//     double lo=lpx_get_row_lb(lp, i);
athos@1405
   347
//     if (up==INF) {
athos@1405
   348
//       switch (b) {
athos@1405
   349
//       case LPX_FR:
athos@1405
   350
//       case LPX_LO:
athos@1405
   351
// 	break;
athos@1405
   352
//       case LPX_UP:
athos@1405
   353
// 	lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
athos@1405
   354
// 	break;
athos@1405
   355
//       case LPX_DB:
athos@1405
   356
//       case LPX_FX:
athos@1405
   357
// 	lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
athos@1405
   358
// 	break;
athos@1405
   359
//       default: ;
athos@1405
   360
// 	//FIXME error
athos@1405
   361
//       }
athos@1405
   362
//     } else {
athos@1405
   363
//       switch (b) {
athos@1405
   364
//       case LPX_FR:
athos@1405
   365
// 	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1405
   366
// 	break;
athos@1405
   367
//       case LPX_UP:
athos@1405
   368
// 	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1405
   369
// 	break;
athos@1405
   370
//       case LPX_LO:
athos@1405
   371
//       case LPX_DB:
athos@1405
   372
//       case LPX_FX:
athos@1405
   373
// 	if (lo==up) 
athos@1405
   374
// 	  lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1405
   375
// 	else 
athos@1405
   376
// 	  lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1405
   377
// 	break;
athos@1405
   378
//       default: ;
athos@1405
   379
// 	//FIXME error
athos@1405
   380
//       }
athos@1405
   381
//     }
athos@1405
   382
//   }
athos@1379
   383
athos@1379
   384
  void LpGlpk::_setRowBounds(int i, Value lb, Value ub)
athos@1379
   385
  {
athos@1379
   386
    //Bad parameter
athos@1379
   387
    if (lb==INF || ub==-INF) {
athos@1379
   388
      //FIXME error
athos@1379
   389
    }
athos@1379
   390
athos@1379
   391
    if (lb == -INF){
athos@1379
   392
      if (ub == INF){
athos@1379
   393
	lpx_set_row_bnds(lp, i, LPX_FR, lb, ub);
athos@1379
   394
      }
athos@1379
   395
      else{
athos@1379
   396
	lpx_set_row_bnds(lp, i, LPX_UP, lb, ub);
athos@1379
   397
      }
athos@1379
   398
    }
athos@1379
   399
    else{
athos@1379
   400
      if (ub==INF){
athos@1379
   401
	lpx_set_row_bnds(lp, i, LPX_LO, lb, ub);
athos@1379
   402
athos@1379
   403
      }
athos@1379
   404
      else{
athos@1379
   405
	if (lb == ub){
athos@1379
   406
	  lpx_set_row_bnds(lp, i, LPX_FX, lb, ub);
athos@1379
   407
	}
athos@1379
   408
	else{
athos@1379
   409
	  lpx_set_row_bnds(lp, i, LPX_DB, lb, ub);
athos@1379
   410
	}
athos@1379
   411
      }
athos@1379
   412
    }
athos@1379
   413
athos@1379
   414
  }
athos@1261
   415
  
athos@1298
   416
  void LpGlpk::_setObjCoeff(int i, Value obj_coef)
athos@1298
   417
  {
athos@1376
   418
    //i=0 means the constant term (shift)
athos@1298
   419
    lpx_set_obj_coef(lp, i, obj_coef);
athos@1298
   420
  }
athos@1261
   421
athos@1377
   422
  void LpGlpk::_clearObj()
athos@1376
   423
  {
athos@1377
   424
    for (int i=0;i<=lpx_get_num_cols(lp);++i){
athos@1377
   425
      lpx_set_obj_coef(lp, i, 0);
athos@1376
   426
    }
athos@1376
   427
  }
athos@1377
   428
//   void LpGlpk::_setObj(int length,
athos@1377
   429
// 		       int  const * indices, 
athos@1377
   430
// 		       Value  const * values )
athos@1377
   431
//   {
athos@1377
   432
//     Value new_values[1+lpx_num_cols()];
athos@1377
   433
//     for (i=0;i<=lpx_num_cols();++i){
athos@1377
   434
//       new_values[i]=0;
athos@1377
   435
//     }
athos@1377
   436
//     for (i=1;i<=length;++i){
athos@1377
   437
//       new_values[indices[i]]=values[i];
athos@1377
   438
//     }
athos@1377
   439
    
athos@1377
   440
//     for (i=0;i<=lpx_num_cols();++i){
athos@1377
   441
//       lpx_set_obj_coef(lp, i, new_values[i]);
athos@1377
   442
//     }
athos@1377
   443
//   }
alpar@1263
   444
alpar@1303
   445
  LpGlpk::SolveExitStatus LpGlpk::_solve()
alpar@1263
   446
  {
athos@1458
   447
    int i =  lpx_simplex(lp);
athos@1298
   448
    switch (i) {
athos@1298
   449
    case LPX_E_OK: 
athos@1298
   450
      return SOLVED;
athos@1298
   451
    default:
athos@1298
   452
      return UNSOLVED;
athos@1298
   453
    }
alpar@1263
   454
  }
alpar@1263
   455
alpar@1293
   456
  LpGlpk::Value LpGlpk::_getPrimal(int i)
alpar@1263
   457
  {
athos@1298
   458
    return lpx_get_col_prim(lp,i);
alpar@1263
   459
  }
marci@1787
   460
marci@1787
   461
  LpGlpk::Value LpGlpk::_getDual(int i)
marci@1787
   462
  {
marci@1787
   463
    return lpx_get_row_dual(lp,i);
marci@1787
   464
  }
alpar@1263
   465
  
alpar@1312
   466
  LpGlpk::Value LpGlpk::_getPrimalValue()
alpar@1312
   467
  {
athos@1314
   468
    return lpx_get_obj_val(lp);
alpar@1312
   469
  }
marci@1840
   470
  bool LpGlpk::_isBasicCol(int i) {
marci@1840
   471
    return (lpx_get_col_stat(lp, i)==LPX_BS);
marci@1840
   472
  }
alpar@1312
   473
  
athos@1298
   474
 
alpar@1312
   475
  LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus()
alpar@1294
   476
  {
athos@1298
   477
    int stat=  lpx_get_status(lp);
athos@1298
   478
    switch (stat) {
athos@1298
   479
    case LPX_UNDEF://Undefined (no solve has been run yet)
athos@1298
   480
      return UNDEFINED;
athos@1458
   481
    case LPX_NOFEAS://There is no feasible solution (primal, I guess)
athos@1458
   482
    case LPX_INFEAS://Infeasible 
athos@1458
   483
      return INFEASIBLE;
athos@1458
   484
    case LPX_UNBND://Unbounded
athos@1458
   485
      return INFINITE;
athos@1458
   486
    case LPX_FEAS://Feasible
athos@1458
   487
      return FEASIBLE;
athos@1458
   488
    case LPX_OPT://Feasible
athos@1458
   489
      return OPTIMAL;
athos@1458
   490
    default:
athos@1458
   491
      return UNDEFINED; //to avoid gcc warning
athos@1458
   492
      //FIXME error
athos@1458
   493
    }
athos@1458
   494
  }
athos@1458
   495
athos@1458
   496
  LpGlpk::SolutionStatus LpGlpk::_getDualStatus()
athos@1458
   497
  {
athos@1473
   498
//     std::cout<<"Itt megy: "<<lpx_get_dual_stat(lp)<<std::endl;
athos@1473
   499
//     std::cout<<"Itt a primal: "<<lpx_get_prim_stat(lp)<<std::endl;
athos@1473
   500
alpar@1466
   501
    switch (lpx_get_dual_stat(lp)) {
athos@1458
   502
    case LPX_D_UNDEF://Undefined (no solve has been run yet)
athos@1458
   503
      return UNDEFINED;
athos@1540
   504
    case LPX_D_NOFEAS://There is no dual feasible solution 
athos@1460
   505
//    case LPX_D_INFEAS://Infeasible 
athos@1458
   506
      return INFEASIBLE;
athos@1473
   507
    case LPX_D_FEAS://Feasible    
athos@1473
   508
      switch (lpx_get_status(lp)) {
athos@1473
   509
      case LPX_NOFEAS:
athos@1458
   510
	return INFINITE;
athos@1458
   511
      case LPX_OPT:
athos@1458
   512
	return OPTIMAL;
athos@1458
   513
      default:
athos@1458
   514
	return FEASIBLE;
athos@1458
   515
      }
athos@1458
   516
    default:
athos@1458
   517
      return UNDEFINED; //to avoid gcc warning
athos@1458
   518
      //FIXME error
athos@1458
   519
    }
athos@1458
   520
  }
athos@1458
   521
athos@1463
   522
  LpGlpk::ProblemTypes LpGlpk::_getProblemType()
athos@1458
   523
  {
athos@1460
   524
      //int stat=  lpx_get_status(lp);
athos@1458
   525
    int statp=  lpx_get_prim_stat(lp);
athos@1458
   526
    int statd=  lpx_get_dual_stat(lp);
athos@1464
   527
    if (statp==LPX_P_FEAS && statd==LPX_D_FEAS)
athos@1460
   528
	return PRIMAL_DUAL_FEASIBLE;
athos@1464
   529
    if (statp==LPX_P_FEAS && statd==LPX_D_NOFEAS)
athos@1460
   530
	return PRIMAL_FEASIBLE_DUAL_INFEASIBLE;
athos@1464
   531
    if (statp==LPX_P_NOFEAS && statd==LPX_D_FEAS)
athos@1460
   532
	return PRIMAL_INFEASIBLE_DUAL_FEASIBLE;
athos@1464
   533
    if (statp==LPX_P_NOFEAS && statd==LPX_D_NOFEAS)
athos@1460
   534
	return PRIMAL_DUAL_INFEASIBLE;
athos@1460
   535
    //In all other cases
athos@1460
   536
    return UNKNOWN;
alpar@1294
   537
  }
alpar@1263
   538
alpar@1312
   539
  void LpGlpk::_setMax()
alpar@1312
   540
  {
alpar@1321
   541
    lpx_set_obj_dir(lp, LPX_MAX);
alpar@1321
   542
  }
alpar@1321
   543
alpar@1312
   544
  void LpGlpk::_setMin()
alpar@1312
   545
  {
alpar@1321
   546
    lpx_set_obj_dir(lp, LPX_MIN);
alpar@1321
   547
  }
alpar@1321
   548
alpar@1321
   549
 
alpar@1321
   550
  void LpGlpk::messageLevel(int m)
alpar@1321
   551
  {
alpar@1321
   552
    lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
alpar@1321
   553
  }
alpar@1312
   554
alpar@1326
   555
  void LpGlpk::presolver(bool b)
alpar@1326
   556
  {
alpar@1326
   557
    lpx_set_int_parm(lp, LPX_K_PRESOL, b);
alpar@1326
   558
  }
alpar@1326
   559
alpar@1312
   560
 
athos@1261
   561
} //END OF NAMESPACE LEMON