lemon/lp_glpk.cc
author deba
Thu, 15 Feb 2007 14:22:08 +0000
changeset 2363 2aabce558574
parent 2349 c945f577a66d
child 2364 3a5e67bd42d2
permissions -rw-r--r--
Changes on the LP interface

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