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