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