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