lemon/lp_glpk.cc
author deba
Mon, 28 Nov 2005 11:14:59 +0000
changeset 1834 0a14e1ae45a1
parent 1540 7d028a73d7f2
child 1840 173b53b28d7c
permissions -rw-r--r--
Doc fix
athos@1261
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * lemon/lp_glpk.cc - Part of LEMON, a generic C++ optimization library
athos@1261
     3
 *
athos@1261
     4
 * Copyright (C) 2005 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@1321
   107
  void LpGlpk::_setRowCoeffs(int i, 
alpar@1321
   108
			     int length,
alpar@1321
   109
			     const int   * indices, 
alpar@1321
   110
			     const Value   * values )
alpar@1321
   111
  {
alpar@1321
   112
    lpx_set_mat_row(lp, i, length,
alpar@1321
   113
		    const_cast<int * >(indices) ,
alpar@1321
   114
		    const_cast<Value * >(values));
alpar@1321
   115
  }
alpar@1321
   116
  
alpar@1321
   117
  void LpGlpk::_setColCoeffs(int i, 
alpar@1321
   118
			     int length,
alpar@1321
   119
			     const int   * indices, 
alpar@1321
   120
			     const Value   * values)
alpar@1321
   121
  {
alpar@1321
   122
    lpx_set_mat_col(lp, i, length,
alpar@1321
   123
		    const_cast<int * >(indices),
alpar@1321
   124
		    const_cast<Value * >(values));
alpar@1321
   125
  }
athos@1431
   126
athos@1431
   127
athos@1431
   128
  void LpGlpk::_setCoeff(int row, int col, Value value) 
athos@1431
   129
  {
athos@1431
   130
    ///FIXME Of course this is not efficient at all, but GLPK knows not more.
athos@1431
   131
    // First approach: get one row, apply changes and set it again
athos@1431
   132
    //(one idea to improve this: maybe it is better to do this with 1 coloumn)
athos@1431
   133
    
athos@1431
   134
    int mem_length=2+lpx_get_num_cols(lp);
athos@1431
   135
    int* indices = new int[mem_length];
athos@1431
   136
    Value* values = new Value[mem_length];
athos@1431
   137
    
athos@1431
   138
athos@1431
   139
    int length=lpx_get_mat_row(lp, row, indices, values);
athos@1431
   140
athos@1431
   141
    //The following code does not suppose that the elements of the array indices are sorted
athos@1431
   142
    int i=1;
athos@1431
   143
    bool found=false;
athos@1431
   144
    while (i <= length && !found){
athos@1431
   145
      if (indices[i]==col){
athos@1431
   146
	found = true;
athos@1431
   147
	values[i]=value;
athos@1431
   148
      }
athos@1431
   149
      ++i;
athos@1431
   150
    }
athos@1431
   151
    if (!found){
athos@1431
   152
      ++length;
athos@1431
   153
      indices[length]=col;
athos@1431
   154
      values[length]=value;
athos@1431
   155
    }
athos@1431
   156
    
athos@1431
   157
    lpx_set_mat_row(lp, row, length, indices, values);
athos@1431
   158
    delete [] indices;
athos@1431
   159
    delete [] values;
athos@1431
   160
    
athos@1431
   161
  }
athos@1431
   162
alpar@1321
   163
  void LpGlpk::_setColLowerBound(int i, Value lo)
alpar@1321
   164
  {
alpar@1321
   165
    if (lo==INF) {
alpar@1321
   166
      //FIXME error
alpar@1321
   167
    }
alpar@1321
   168
    int b=lpx_get_col_type(lp, i);
alpar@1321
   169
    double up=lpx_get_col_ub(lp, i);	
alpar@1321
   170
    if (lo==-INF) {
alpar@1321
   171
      switch (b) {
alpar@1321
   172
      case LPX_FR:
alpar@1321
   173
      case LPX_LO:
alpar@1321
   174
	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
alpar@1321
   175
	break;
alpar@1321
   176
      case LPX_UP:
alpar@1321
   177
	break;
alpar@1321
   178
      case LPX_DB:
alpar@1321
   179
      case LPX_FX:
alpar@1321
   180
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   181
	break;
alpar@1321
   182
      default: ;
alpar@1321
   183
	//FIXME error
alpar@1321
   184
      }
alpar@1321
   185
    } else {
alpar@1321
   186
      switch (b) {
alpar@1321
   187
      case LPX_FR:
alpar@1321
   188
      case LPX_LO:
alpar@1321
   189
	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
alpar@1321
   190
	break;
alpar@1321
   191
      case LPX_UP:	  
alpar@1321
   192
      case LPX_DB:
alpar@1321
   193
      case LPX_FX:
alpar@1321
   194
	if (lo==up) 
alpar@1321
   195
	  lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
alpar@1321
   196
	else 
alpar@1321
   197
	  lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
alpar@1321
   198
	break;
alpar@1321
   199
      default: ;
alpar@1321
   200
	//FIXME error
alpar@1321
   201
      }
athos@1261
   202
    }
athos@1261
   203
alpar@1321
   204
  }
alpar@1321
   205
  
alpar@1321
   206
  void LpGlpk::_setColUpperBound(int i, Value up)
alpar@1321
   207
  {
alpar@1321
   208
    if (up==-INF) {
alpar@1321
   209
      //FIXME error
athos@1261
   210
    }
alpar@1321
   211
    int b=lpx_get_col_type(lp, i);
alpar@1321
   212
    double lo=lpx_get_col_lb(lp, i);
alpar@1321
   213
    if (up==INF) {
alpar@1321
   214
      switch (b) {
alpar@1321
   215
      case LPX_FR:
alpar@1321
   216
      case LPX_LO:
alpar@1321
   217
	break;
alpar@1321
   218
      case LPX_UP:
alpar@1321
   219
	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
alpar@1321
   220
	break;
alpar@1321
   221
      case LPX_DB:
alpar@1321
   222
      case LPX_FX:
alpar@1321
   223
	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
alpar@1321
   224
	break;
alpar@1321
   225
      default: ;
athos@1261
   226
	//FIXME error
athos@1261
   227
      }
alpar@1321
   228
    } else {
alpar@1321
   229
      switch (b) {
alpar@1321
   230
      case LPX_FR:
alpar@1321
   231
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   232
	break;
alpar@1321
   233
      case LPX_UP:
alpar@1321
   234
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   235
	break;
alpar@1321
   236
      case LPX_LO:
alpar@1321
   237
      case LPX_DB:
alpar@1321
   238
      case LPX_FX:
alpar@1321
   239
	if (lo==up) 
alpar@1321
   240
	  lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
alpar@1321
   241
	else 
alpar@1321
   242
	  lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
alpar@1321
   243
	break;
alpar@1321
   244
      default: ;
athos@1261
   245
	//FIXME error
athos@1261
   246
      }
alpar@1321
   247
    }
alpar@1321
   248
  }
alpar@1321
   249
  
athos@1405
   250
//   void LpGlpk::_setRowLowerBound(int i, Value lo)
athos@1405
   251
//   {
athos@1405
   252
//     if (lo==INF) {
athos@1405
   253
//       //FIXME error
athos@1405
   254
//     }
athos@1405
   255
//     int b=lpx_get_row_type(lp, i);
athos@1405
   256
//     double up=lpx_get_row_ub(lp, i);	
athos@1405
   257
//     if (lo==-INF) {
athos@1405
   258
//       switch (b) {
athos@1405
   259
//       case LPX_FR:
athos@1405
   260
//       case LPX_LO:
athos@1405
   261
// 	lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
athos@1405
   262
// 	break;
athos@1405
   263
//       case LPX_UP:
athos@1405
   264
// 	break;
athos@1405
   265
//       case LPX_DB:
athos@1405
   266
//       case LPX_FX:
athos@1405
   267
// 	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1405
   268
// 	break;
athos@1405
   269
//       default: ;
athos@1405
   270
// 	//FIXME error
athos@1405
   271
//       }
athos@1405
   272
//     } else {
athos@1405
   273
//       switch (b) {
athos@1405
   274
//       case LPX_FR:
athos@1405
   275
//       case LPX_LO:
athos@1405
   276
// 	lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
athos@1405
   277
// 	break;
athos@1405
   278
//       case LPX_UP:	  
athos@1405
   279
//       case LPX_DB:
athos@1405
   280
//       case LPX_FX:
athos@1405
   281
// 	if (lo==up) 
athos@1405
   282
// 	  lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1405
   283
// 	else 
athos@1405
   284
// 	  lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1405
   285
// 	break;
athos@1405
   286
//       default: ;
athos@1405
   287
// 	//FIXME error
athos@1405
   288
//       }
athos@1405
   289
//     }
athos@1405
   290
//   }
athos@1261
   291
  
athos@1405
   292
//   void LpGlpk::_setRowUpperBound(int i, Value up)
athos@1405
   293
//   {
athos@1405
   294
//     if (up==-INF) {
athos@1405
   295
//       //FIXME error
athos@1405
   296
//     }
athos@1405
   297
//     int b=lpx_get_row_type(lp, i);
athos@1405
   298
//     double lo=lpx_get_row_lb(lp, i);
athos@1405
   299
//     if (up==INF) {
athos@1405
   300
//       switch (b) {
athos@1405
   301
//       case LPX_FR:
athos@1405
   302
//       case LPX_LO:
athos@1405
   303
// 	break;
athos@1405
   304
//       case LPX_UP:
athos@1405
   305
// 	lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
athos@1405
   306
// 	break;
athos@1405
   307
//       case LPX_DB:
athos@1405
   308
//       case LPX_FX:
athos@1405
   309
// 	lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
athos@1405
   310
// 	break;
athos@1405
   311
//       default: ;
athos@1405
   312
// 	//FIXME error
athos@1405
   313
//       }
athos@1405
   314
//     } else {
athos@1405
   315
//       switch (b) {
athos@1405
   316
//       case LPX_FR:
athos@1405
   317
// 	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1405
   318
// 	break;
athos@1405
   319
//       case LPX_UP:
athos@1405
   320
// 	lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1405
   321
// 	break;
athos@1405
   322
//       case LPX_LO:
athos@1405
   323
//       case LPX_DB:
athos@1405
   324
//       case LPX_FX:
athos@1405
   325
// 	if (lo==up) 
athos@1405
   326
// 	  lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1405
   327
// 	else 
athos@1405
   328
// 	  lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1405
   329
// 	break;
athos@1405
   330
//       default: ;
athos@1405
   331
// 	//FIXME error
athos@1405
   332
//       }
athos@1405
   333
//     }
athos@1405
   334
//   }
athos@1379
   335
athos@1379
   336
  void LpGlpk::_setRowBounds(int i, Value lb, Value ub)
athos@1379
   337
  {
athos@1379
   338
    //Bad parameter
athos@1379
   339
    if (lb==INF || ub==-INF) {
athos@1379
   340
      //FIXME error
athos@1379
   341
    }
athos@1379
   342
athos@1379
   343
    if (lb == -INF){
athos@1379
   344
      if (ub == INF){
athos@1379
   345
	lpx_set_row_bnds(lp, i, LPX_FR, lb, ub);
athos@1379
   346
      }
athos@1379
   347
      else{
athos@1379
   348
	lpx_set_row_bnds(lp, i, LPX_UP, lb, ub);
athos@1379
   349
      }
athos@1379
   350
    }
athos@1379
   351
    else{
athos@1379
   352
      if (ub==INF){
athos@1379
   353
	lpx_set_row_bnds(lp, i, LPX_LO, lb, ub);
athos@1379
   354
athos@1379
   355
      }
athos@1379
   356
      else{
athos@1379
   357
	if (lb == ub){
athos@1379
   358
	  lpx_set_row_bnds(lp, i, LPX_FX, lb, ub);
athos@1379
   359
	}
athos@1379
   360
	else{
athos@1379
   361
	  lpx_set_row_bnds(lp, i, LPX_DB, lb, ub);
athos@1379
   362
	}
athos@1379
   363
      }
athos@1379
   364
    }
athos@1379
   365
athos@1379
   366
  }
athos@1261
   367
  
athos@1298
   368
  void LpGlpk::_setObjCoeff(int i, Value obj_coef)
athos@1298
   369
  {
athos@1376
   370
    //i=0 means the constant term (shift)
athos@1298
   371
    lpx_set_obj_coef(lp, i, obj_coef);
athos@1298
   372
  }
athos@1261
   373
athos@1377
   374
  void LpGlpk::_clearObj()
athos@1376
   375
  {
athos@1377
   376
    for (int i=0;i<=lpx_get_num_cols(lp);++i){
athos@1377
   377
      lpx_set_obj_coef(lp, i, 0);
athos@1376
   378
    }
athos@1376
   379
  }
athos@1377
   380
//   void LpGlpk::_setObj(int length,
athos@1377
   381
// 		       int  const * indices, 
athos@1377
   382
// 		       Value  const * values )
athos@1377
   383
//   {
athos@1377
   384
//     Value new_values[1+lpx_num_cols()];
athos@1377
   385
//     for (i=0;i<=lpx_num_cols();++i){
athos@1377
   386
//       new_values[i]=0;
athos@1377
   387
//     }
athos@1377
   388
//     for (i=1;i<=length;++i){
athos@1377
   389
//       new_values[indices[i]]=values[i];
athos@1377
   390
//     }
athos@1377
   391
    
athos@1377
   392
//     for (i=0;i<=lpx_num_cols();++i){
athos@1377
   393
//       lpx_set_obj_coef(lp, i, new_values[i]);
athos@1377
   394
//     }
athos@1377
   395
//   }
alpar@1263
   396
alpar@1303
   397
  LpGlpk::SolveExitStatus LpGlpk::_solve()
alpar@1263
   398
  {
athos@1458
   399
    int i =  lpx_simplex(lp);
athos@1298
   400
    switch (i) {
athos@1298
   401
    case LPX_E_OK: 
athos@1298
   402
      return SOLVED;
athos@1298
   403
    default:
athos@1298
   404
      return UNSOLVED;
athos@1298
   405
    }
alpar@1263
   406
  }
alpar@1263
   407
alpar@1293
   408
  LpGlpk::Value LpGlpk::_getPrimal(int i)
alpar@1263
   409
  {
athos@1298
   410
    return lpx_get_col_prim(lp,i);
alpar@1263
   411
  }
marci@1787
   412
marci@1787
   413
  LpGlpk::Value LpGlpk::_getDual(int i)
marci@1787
   414
  {
marci@1787
   415
    return lpx_get_row_dual(lp,i);
marci@1787
   416
  }
alpar@1263
   417
  
alpar@1312
   418
  LpGlpk::Value LpGlpk::_getPrimalValue()
alpar@1312
   419
  {
athos@1314
   420
    return lpx_get_obj_val(lp);
alpar@1312
   421
  }
alpar@1312
   422
  
athos@1298
   423
 
alpar@1312
   424
  LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus()
alpar@1294
   425
  {
athos@1298
   426
    int stat=  lpx_get_status(lp);
athos@1298
   427
    switch (stat) {
athos@1298
   428
    case LPX_UNDEF://Undefined (no solve has been run yet)
athos@1298
   429
      return UNDEFINED;
athos@1458
   430
    case LPX_NOFEAS://There is no feasible solution (primal, I guess)
athos@1458
   431
    case LPX_INFEAS://Infeasible 
athos@1458
   432
      return INFEASIBLE;
athos@1458
   433
    case LPX_UNBND://Unbounded
athos@1458
   434
      return INFINITE;
athos@1458
   435
    case LPX_FEAS://Feasible
athos@1458
   436
      return FEASIBLE;
athos@1458
   437
    case LPX_OPT://Feasible
athos@1458
   438
      return OPTIMAL;
athos@1458
   439
    default:
athos@1458
   440
      return UNDEFINED; //to avoid gcc warning
athos@1458
   441
      //FIXME error
athos@1458
   442
    }
athos@1458
   443
  }
athos@1458
   444
athos@1458
   445
  LpGlpk::SolutionStatus LpGlpk::_getDualStatus()
athos@1458
   446
  {
athos@1473
   447
//     std::cout<<"Itt megy: "<<lpx_get_dual_stat(lp)<<std::endl;
athos@1473
   448
//     std::cout<<"Itt a primal: "<<lpx_get_prim_stat(lp)<<std::endl;
athos@1473
   449
alpar@1466
   450
    switch (lpx_get_dual_stat(lp)) {
athos@1458
   451
    case LPX_D_UNDEF://Undefined (no solve has been run yet)
athos@1458
   452
      return UNDEFINED;
athos@1540
   453
    case LPX_D_NOFEAS://There is no dual feasible solution 
athos@1460
   454
//    case LPX_D_INFEAS://Infeasible 
athos@1458
   455
      return INFEASIBLE;
athos@1473
   456
    case LPX_D_FEAS://Feasible    
athos@1473
   457
      switch (lpx_get_status(lp)) {
athos@1473
   458
      case LPX_NOFEAS:
athos@1458
   459
	return INFINITE;
athos@1458
   460
      case LPX_OPT:
athos@1458
   461
	return OPTIMAL;
athos@1458
   462
      default:
athos@1458
   463
	return FEASIBLE;
athos@1458
   464
      }
athos@1458
   465
    default:
athos@1458
   466
      return UNDEFINED; //to avoid gcc warning
athos@1458
   467
      //FIXME error
athos@1458
   468
    }
athos@1458
   469
  }
athos@1458
   470
athos@1463
   471
  LpGlpk::ProblemTypes LpGlpk::_getProblemType()
athos@1458
   472
  {
athos@1460
   473
      //int stat=  lpx_get_status(lp);
athos@1458
   474
    int statp=  lpx_get_prim_stat(lp);
athos@1458
   475
    int statd=  lpx_get_dual_stat(lp);
athos@1464
   476
    if (statp==LPX_P_FEAS && statd==LPX_D_FEAS)
athos@1460
   477
	return PRIMAL_DUAL_FEASIBLE;
athos@1464
   478
    if (statp==LPX_P_FEAS && statd==LPX_D_NOFEAS)
athos@1460
   479
	return PRIMAL_FEASIBLE_DUAL_INFEASIBLE;
athos@1464
   480
    if (statp==LPX_P_NOFEAS && statd==LPX_D_FEAS)
athos@1460
   481
	return PRIMAL_INFEASIBLE_DUAL_FEASIBLE;
athos@1464
   482
    if (statp==LPX_P_NOFEAS && statd==LPX_D_NOFEAS)
athos@1460
   483
	return PRIMAL_DUAL_INFEASIBLE;
athos@1460
   484
    //In all other cases
athos@1460
   485
    return UNKNOWN;
alpar@1294
   486
  }
alpar@1263
   487
alpar@1312
   488
  void LpGlpk::_setMax()
alpar@1312
   489
  {
alpar@1321
   490
    lpx_set_obj_dir(lp, LPX_MAX);
alpar@1321
   491
  }
alpar@1321
   492
alpar@1312
   493
  void LpGlpk::_setMin()
alpar@1312
   494
  {
alpar@1321
   495
    lpx_set_obj_dir(lp, LPX_MIN);
alpar@1321
   496
  }
alpar@1321
   497
alpar@1321
   498
 
alpar@1321
   499
  void LpGlpk::messageLevel(int m)
alpar@1321
   500
  {
alpar@1321
   501
    lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
alpar@1321
   502
  }
alpar@1312
   503
alpar@1326
   504
  void LpGlpk::presolver(bool b)
alpar@1326
   505
  {
alpar@1326
   506
    lpx_set_int_parm(lp, LPX_K_PRESOL, b);
alpar@1326
   507
  }
alpar@1326
   508
alpar@1312
   509
 
athos@1261
   510
} //END OF NAMESPACE LEMON
athos@1261
   511
athos@1261
   512
#endif //LEMON_LP_GLPK_CC