lemon/lp_glpk.cc
author deba
Thu, 15 Feb 2007 19:15:14 +0000
changeset 2364 3a5e67bd42d2
parent 2363 2aabce558574
child 2366 bfbdded3763a
permissions -rw-r--r--
Lp row and col getter function
lp section reader and writer for lemon IO
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@2364
   129
  void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator 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@2364
   137
    for(ConstRowIterator 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
  }
deba@2364
   144
deba@2364
   145
  void LpGlpk::_getRowCoeffs(int i, RowIterator b) 
deba@2364
   146
  {
deba@2364
   147
    int length = lpx_get_mat_row(lp, i, 0, 0);
deba@2364
   148
    
deba@2364
   149
    std::vector<int> indices(length + 1);
deba@2364
   150
    std::vector<Value> values(length + 1);
deba@2364
   151
    
deba@2364
   152
    lpx_get_mat_row(lp, i, &indices[0], &values[0]);
deba@2364
   153
    
deba@2364
   154
    for (int i = 1; i <= length; ++i) {
deba@2364
   155
      *b = std::make_pair(indices[i], values[i]);
deba@2364
   156
      ++b;
deba@2364
   157
    }
deba@2364
   158
  }
alpar@1321
   159
  
deba@2364
   160
  void LpGlpk::_setColCoeffs(int i, ConstColIterator b, ConstColIterator e) {
deba@2312
   161
deba@2312
   162
    std::vector<int> indices;
deba@2312
   163
    std::vector<Value> values;
deba@2312
   164
deba@2312
   165
    indices.push_back(0);
deba@2312
   166
    values.push_back(0);
deba@2312
   167
deba@2364
   168
    for(ConstColIterator it=b; it!=e; ++it) {
deba@2312
   169
      indices.push_back(it->first);
deba@2312
   170
      values.push_back(it->second);
deba@2312
   171
    }
deba@2312
   172
    
deba@2312
   173
    lpx_set_mat_col(lp, i, values.size() - 1, &indices[0], &values[0]);
alpar@1321
   174
  }
athos@1431
   175
deba@2364
   176
  void LpGlpk::_getColCoeffs(int i, ColIterator b) 
deba@2364
   177
  {
deba@2364
   178
    int length = lpx_get_mat_col(lp, i, 0, 0);
deba@2364
   179
    
deba@2364
   180
    std::vector<int> indices(length + 1);
deba@2364
   181
    std::vector<Value> values(length + 1);
deba@2364
   182
    
deba@2364
   183
    lpx_get_mat_col(lp, i, &indices[0], &values[0]);
deba@2364
   184
    
deba@2364
   185
    for (int i = 1; i <= length; ++i) {
deba@2364
   186
      *b = std::make_pair(indices[i], values[i]);
deba@2364
   187
      ++b;
deba@2364
   188
    }
deba@2364
   189
  }
athos@1431
   190
athos@1431
   191
  void LpGlpk::_setCoeff(int row, int col, Value value) 
athos@1431
   192
  {
deba@2312
   193
deba@2312
   194
    if (lpx_get_num_cols(lp) < lpx_get_num_rows(lp)) {
deba@2312
   195
deba@2312
   196
      int length=lpx_get_mat_row(lp, row, 0, 0);
deba@2312
   197
      
deba@2312
   198
      std::vector<int> indices(length + 2);
deba@2312
   199
      std::vector<Value> values(length + 2);
deba@2312
   200
      
deba@2312
   201
      lpx_get_mat_row(lp, row, &indices[0], &values[0]);
deba@2312
   202
      
deba@2312
   203
      //The following code does not suppose that the elements of the
deba@2312
   204
      //array indices are sorted
deba@2312
   205
      bool found=false;
deba@2312
   206
      for (int i = 1; i <= length; ++i) {
deba@2312
   207
        if (indices[i]==col){
deba@2312
   208
          found=true;
deba@2312
   209
          values[i]=value;
deba@2312
   210
          break;
deba@2312
   211
        }
deba@2312
   212
      }
deba@2312
   213
      if (!found){
deba@2312
   214
        ++length;
deba@2312
   215
        indices[length]=col;
deba@2312
   216
        values[length]=value;
deba@2312
   217
      }
athos@1431
   218
    
deba@2312
   219
      lpx_set_mat_row(lp, row, length, &indices[0], &values[0]);
deba@2312
   220
deba@2312
   221
    } else {
deba@2312
   222
deba@2312
   223
      int length=lpx_get_mat_col(lp, col, 0, 0);
deba@2312
   224
      
deba@2312
   225
      std::vector<int> indices(length + 2);
deba@2312
   226
      std::vector<Value> values(length + 2);
deba@2312
   227
      
deba@2312
   228
      lpx_get_mat_col(lp, col, &indices[0], &values[0]);
deba@2312
   229
      
deba@2312
   230
      //The following code does not suppose that the elements of the
deba@2312
   231
      //array indices are sorted
deba@2312
   232
      bool found=false;
deba@2312
   233
      for (int i = 1; i <= length; ++i) {
deba@2312
   234
        if (indices[i]==col){
deba@2312
   235
          found=true;
deba@2312
   236
          values[i]=value;
deba@2312
   237
          break;
deba@2312
   238
        }
deba@2312
   239
      }
deba@2312
   240
      if (!found){
deba@2312
   241
        ++length;
deba@2312
   242
        indices[length]=row;
deba@2312
   243
        values[length]=value;
deba@2312
   244
      }
athos@1431
   245
    
deba@2312
   246
      lpx_set_mat_col(lp, col, length, &indices[0], &values[0]);
athos@1431
   247
    }
athos@1431
   248
  }
athos@1431
   249
athos@2328
   250
  LpGlpk::Value LpGlpk::_getCoeff(int row, int col)
athos@2324
   251
  {
athos@2328
   252
athos@2328
   253
    int length=lpx_get_mat_row(lp, row, 0, 0);
athos@2328
   254
    
deba@2364
   255
    std::vector<int> indices(length + 1);
deba@2364
   256
    std::vector<Value> values(length + 1);
athos@2328
   257
    
athos@2328
   258
    lpx_get_mat_row(lp, row, &indices[0], &values[0]);
athos@2328
   259
    
athos@2328
   260
    //The following code does not suppose that the elements of the
athos@2328
   261
    //array indices are sorted
athos@2328
   262
    for (int i = 1; i <= length; ++i) {
athos@2328
   263
      if (indices[i]==col){
athos@2328
   264
	return values[i];
athos@2328
   265
      }
athos@2328
   266
    }
athos@2324
   267
    return 0;
athos@2328
   268
athos@2324
   269
  }
athos@2324
   270
athos@2324
   271
alpar@1321
   272
  void LpGlpk::_setColLowerBound(int i, Value lo)
alpar@1321
   273
  {
alpar@1321
   274
    if (lo==INF) {
alpar@1321
   275
      //FIXME error
alpar@1321
   276
    }
alpar@1321
   277
    int b=lpx_get_col_type(lp, i);
alpar@1321
   278
    double up=lpx_get_col_ub(lp, i);	
alpar@1321
   279
    if (lo==-INF) {
alpar@1321
   280
      switch (b) {
alpar@1321
   281
      case LPX_FR:
alpar@1321
   282
      case LPX_LO:
alpar@1321
   283
	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
alpar@1321
   284
	break;
alpar@1321
   285
      case LPX_UP:
alpar@1321
   286
	break;
alpar@1321
   287
      case LPX_DB:
alpar@1321
   288
      case LPX_FX:
alpar@1321
   289
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   290
	break;
alpar@1321
   291
      default: ;
alpar@1321
   292
	//FIXME error
alpar@1321
   293
      }
alpar@1321
   294
    } else {
alpar@1321
   295
      switch (b) {
alpar@1321
   296
      case LPX_FR:
alpar@1321
   297
      case LPX_LO:
alpar@1321
   298
	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
alpar@1321
   299
	break;
alpar@1321
   300
      case LPX_UP:	  
alpar@1321
   301
      case LPX_DB:
alpar@1321
   302
      case LPX_FX:
alpar@1321
   303
	if (lo==up) 
alpar@1321
   304
	  lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
alpar@1321
   305
	else 
alpar@1321
   306
	  lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
alpar@1321
   307
	break;
alpar@1321
   308
      default: ;
alpar@1321
   309
	//FIXME error
alpar@1321
   310
      }
athos@1261
   311
    }
athos@1261
   312
alpar@1321
   313
  }
athos@2328
   314
athos@2328
   315
  LpGlpk::Value LpGlpk::_getColLowerBound(int i)
athos@2328
   316
  {
athos@2328
   317
    int b=lpx_get_col_type(lp, i);
athos@2328
   318
      switch (b) {
athos@2328
   319
      case LPX_LO:
athos@2328
   320
      case LPX_DB:
athos@2328
   321
      case LPX_FX:
athos@2328
   322
	return lpx_get_col_lb(lp, i);	
athos@2328
   323
      default: ;
athos@2328
   324
	return -INF;
athos@2328
   325
      }
athos@2328
   326
  }
alpar@1321
   327
  
alpar@1321
   328
  void LpGlpk::_setColUpperBound(int i, Value up)
alpar@1321
   329
  {
alpar@1321
   330
    if (up==-INF) {
alpar@1321
   331
      //FIXME error
athos@1261
   332
    }
alpar@1321
   333
    int b=lpx_get_col_type(lp, i);
alpar@1321
   334
    double lo=lpx_get_col_lb(lp, i);
alpar@1321
   335
    if (up==INF) {
alpar@1321
   336
      switch (b) {
alpar@1321
   337
      case LPX_FR:
alpar@1321
   338
      case LPX_LO:
alpar@1321
   339
	break;
alpar@1321
   340
      case LPX_UP:
alpar@1321
   341
	lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
alpar@1321
   342
	break;
alpar@1321
   343
      case LPX_DB:
alpar@1321
   344
      case LPX_FX:
alpar@1321
   345
	lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
alpar@1321
   346
	break;
alpar@1321
   347
      default: ;
athos@1261
   348
	//FIXME error
athos@1261
   349
      }
alpar@1321
   350
    } else {
alpar@1321
   351
      switch (b) {
alpar@1321
   352
      case LPX_FR:
alpar@1321
   353
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   354
	break;
alpar@1321
   355
      case LPX_UP:
alpar@1321
   356
	lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
alpar@1321
   357
	break;
alpar@1321
   358
      case LPX_LO:
alpar@1321
   359
      case LPX_DB:
alpar@1321
   360
      case LPX_FX:
alpar@1321
   361
	if (lo==up) 
alpar@1321
   362
	  lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
alpar@1321
   363
	else 
alpar@1321
   364
	  lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
alpar@1321
   365
	break;
alpar@1321
   366
      default: ;
athos@1261
   367
	//FIXME error
athos@1261
   368
      }
alpar@1321
   369
    }
alpar@1321
   370
  }
athos@2328
   371
athos@2328
   372
  LpGlpk::Value LpGlpk::_getColUpperBound(int i)
athos@2328
   373
  {
athos@2328
   374
    int b=lpx_get_col_type(lp, i);
athos@2328
   375
      switch (b) {
athos@2328
   376
      case LPX_UP:
athos@2328
   377
      case LPX_DB:
athos@2328
   378
      case LPX_FX:
athos@2328
   379
	return lpx_get_col_ub(lp, i);	
athos@2328
   380
      default: ;
athos@2328
   381
	return INF;
athos@2328
   382
      }
athos@2328
   383
  }
alpar@1321
   384
  
athos@1379
   385
  void LpGlpk::_setRowBounds(int i, Value lb, Value ub)
athos@1379
   386
  {
athos@1379
   387
    //Bad parameter
athos@1379
   388
    if (lb==INF || ub==-INF) {
athos@1379
   389
      //FIXME error
athos@1379
   390
    }
athos@1379
   391
athos@1379
   392
    if (lb == -INF){
athos@1379
   393
      if (ub == INF){
athos@1379
   394
	lpx_set_row_bnds(lp, i, LPX_FR, lb, ub);
athos@1379
   395
      }
athos@1379
   396
      else{
athos@1379
   397
	lpx_set_row_bnds(lp, i, LPX_UP, lb, ub);
athos@1379
   398
      }
athos@1379
   399
    }
athos@1379
   400
    else{
athos@1379
   401
      if (ub==INF){
athos@1379
   402
	lpx_set_row_bnds(lp, i, LPX_LO, lb, ub);
athos@1379
   403
athos@1379
   404
      }
athos@1379
   405
      else{
athos@1379
   406
	if (lb == ub){
athos@1379
   407
	  lpx_set_row_bnds(lp, i, LPX_FX, lb, ub);
athos@1379
   408
	}
athos@1379
   409
	else{
athos@1379
   410
	  lpx_set_row_bnds(lp, i, LPX_DB, lb, ub);
athos@1379
   411
	}
athos@1379
   412
      }
athos@1379
   413
    }
athos@1379
   414
athos@1379
   415
  }
athos@2328
   416
athos@2328
   417
  void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub)
athos@2328
   418
  {
athos@2328
   419
athos@2328
   420
    int b=lpx_get_row_type(lp, i);
athos@2328
   421
    switch (b) {
athos@2328
   422
    case LPX_FR:
athos@2328
   423
    case LPX_UP:
athos@2328
   424
      lb = -INF;
athos@2328
   425
	break;
athos@2328
   426
    default: 
athos@2328
   427
      lb=lpx_get_row_lb(lp, i);
athos@2328
   428
    }
athos@2328
   429
athos@2328
   430
    switch (b) {
athos@2328
   431
    case LPX_FR:
athos@2328
   432
    case LPX_LO:
athos@2328
   433
      ub = INF;
athos@2328
   434
	break;
athos@2328
   435
    default: 
athos@2328
   436
      ub=lpx_get_row_ub(lp, i);
athos@2328
   437
    }
athos@2328
   438
    
athos@2328
   439
  }
athos@1261
   440
  
athos@1298
   441
  void LpGlpk::_setObjCoeff(int i, Value obj_coef)
athos@1298
   442
  {
athos@1376
   443
    //i=0 means the constant term (shift)
athos@1298
   444
    lpx_set_obj_coef(lp, i, obj_coef);
athos@1298
   445
  }
athos@1261
   446
athos@2324
   447
  LpGlpk::Value LpGlpk::_getObjCoeff(int i){
athos@2324
   448
    //i=0 means the constant term (shift)
athos@2324
   449
    return lpx_get_obj_coef(lp, i);
athos@2324
   450
  }
athos@2324
   451
athos@1377
   452
  void LpGlpk::_clearObj()
athos@1376
   453
  {
athos@1377
   454
    for (int i=0;i<=lpx_get_num_cols(lp);++i){
athos@1377
   455
      lpx_set_obj_coef(lp, i, 0);
athos@1376
   456
    }
athos@1376
   457
  }
alpar@1263
   458
alpar@1303
   459
  LpGlpk::SolveExitStatus LpGlpk::_solve()
alpar@1263
   460
  {
athos@2345
   461
    // A way to check the problem to be solved
athos@2345
   462
    //lpx_write_cpxlp(lp,"naittvan.cpx");    
athos@2345
   463
deba@2363
   464
    lpx_std_basis(lp);
athos@1458
   465
    int i =  lpx_simplex(lp);
deba@2363
   466
    
athos@1298
   467
    switch (i) {
athos@1298
   468
    case LPX_E_OK: 
athos@1298
   469
      return SOLVED;
athos@1298
   470
    default:
athos@1298
   471
      return UNSOLVED;
athos@1298
   472
    }
alpar@1263
   473
  }
alpar@1263
   474
alpar@1293
   475
  LpGlpk::Value LpGlpk::_getPrimal(int i)
alpar@1263
   476
  {
athos@1298
   477
    return lpx_get_col_prim(lp,i);
alpar@1263
   478
  }
marci@1787
   479
marci@1787
   480
  LpGlpk::Value LpGlpk::_getDual(int i)
marci@1787
   481
  {
marci@1787
   482
    return lpx_get_row_dual(lp,i);
marci@1787
   483
  }
alpar@1263
   484
  
alpar@1312
   485
  LpGlpk::Value LpGlpk::_getPrimalValue()
alpar@1312
   486
  {
athos@1314
   487
    return lpx_get_obj_val(lp);
alpar@1312
   488
  }
marci@1840
   489
  bool LpGlpk::_isBasicCol(int i) {
marci@1840
   490
    return (lpx_get_col_stat(lp, i)==LPX_BS);
marci@1840
   491
  }
alpar@1312
   492
  
athos@1298
   493
 
alpar@1312
   494
  LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus()
alpar@1294
   495
  {
athos@1298
   496
    int stat=  lpx_get_status(lp);
athos@1298
   497
    switch (stat) {
athos@1298
   498
    case LPX_UNDEF://Undefined (no solve has been run yet)
athos@1298
   499
      return UNDEFINED;
athos@1458
   500
    case LPX_NOFEAS://There is no feasible solution (primal, I guess)
athos@1458
   501
    case LPX_INFEAS://Infeasible 
athos@1458
   502
      return INFEASIBLE;
athos@1458
   503
    case LPX_UNBND://Unbounded
athos@1458
   504
      return INFINITE;
athos@1458
   505
    case LPX_FEAS://Feasible
athos@1458
   506
      return FEASIBLE;
athos@1458
   507
    case LPX_OPT://Feasible
athos@1458
   508
      return OPTIMAL;
athos@1458
   509
    default:
athos@1458
   510
      return UNDEFINED; //to avoid gcc warning
athos@1458
   511
      //FIXME error
athos@1458
   512
    }
athos@1458
   513
  }
athos@1458
   514
athos@1458
   515
  LpGlpk::SolutionStatus LpGlpk::_getDualStatus()
athos@1458
   516
  {
athos@1473
   517
//     std::cout<<"Itt megy: "<<lpx_get_dual_stat(lp)<<std::endl;
athos@1473
   518
//     std::cout<<"Itt a primal: "<<lpx_get_prim_stat(lp)<<std::endl;
athos@1473
   519
alpar@1466
   520
    switch (lpx_get_dual_stat(lp)) {
athos@1458
   521
    case LPX_D_UNDEF://Undefined (no solve has been run yet)
athos@1458
   522
      return UNDEFINED;
athos@1540
   523
    case LPX_D_NOFEAS://There is no dual feasible solution 
athos@1460
   524
//    case LPX_D_INFEAS://Infeasible 
athos@1458
   525
      return INFEASIBLE;
athos@1473
   526
    case LPX_D_FEAS://Feasible    
athos@1473
   527
      switch (lpx_get_status(lp)) {
athos@1473
   528
      case LPX_NOFEAS:
athos@1458
   529
	return INFINITE;
athos@1458
   530
      case LPX_OPT:
athos@1458
   531
	return OPTIMAL;
athos@1458
   532
      default:
athos@1458
   533
	return FEASIBLE;
athos@1458
   534
      }
athos@1458
   535
    default:
athos@1458
   536
      return UNDEFINED; //to avoid gcc warning
athos@1458
   537
      //FIXME error
athos@1458
   538
    }
athos@1458
   539
  }
athos@1458
   540
athos@1463
   541
  LpGlpk::ProblemTypes LpGlpk::_getProblemType()
athos@1458
   542
  {
athos@1460
   543
      //int stat=  lpx_get_status(lp);
athos@1458
   544
    int statp=  lpx_get_prim_stat(lp);
athos@1458
   545
    int statd=  lpx_get_dual_stat(lp);
athos@1464
   546
    if (statp==LPX_P_FEAS && statd==LPX_D_FEAS)
athos@1460
   547
	return PRIMAL_DUAL_FEASIBLE;
athos@1464
   548
    if (statp==LPX_P_FEAS && statd==LPX_D_NOFEAS)
athos@1460
   549
	return PRIMAL_FEASIBLE_DUAL_INFEASIBLE;
athos@1464
   550
    if (statp==LPX_P_NOFEAS && statd==LPX_D_FEAS)
athos@1460
   551
	return PRIMAL_INFEASIBLE_DUAL_FEASIBLE;
athos@1464
   552
    if (statp==LPX_P_NOFEAS && statd==LPX_D_NOFEAS)
athos@1460
   553
	return PRIMAL_DUAL_INFEASIBLE;
athos@1460
   554
    //In all other cases
athos@1460
   555
    return UNKNOWN;
alpar@1294
   556
  }
alpar@1263
   557
alpar@1312
   558
  void LpGlpk::_setMax()
alpar@1312
   559
  {
alpar@1321
   560
    lpx_set_obj_dir(lp, LPX_MAX);
alpar@1321
   561
  }
alpar@1321
   562
alpar@1312
   563
  void LpGlpk::_setMin()
alpar@1312
   564
  {
alpar@1321
   565
    lpx_set_obj_dir(lp, LPX_MIN);
alpar@1321
   566
  }
alpar@1321
   567
athos@2324
   568
  bool LpGlpk::_isMax()
athos@2324
   569
  {
athos@2324
   570
    return (lpx_get_obj_dir(lp)==LPX_MAX);
athos@2324
   571
  }
athos@2324
   572
alpar@1321
   573
 
athos@2324
   574
alpar@1321
   575
  void LpGlpk::messageLevel(int m)
alpar@1321
   576
  {
alpar@1321
   577
    lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
alpar@1321
   578
  }
alpar@1312
   579
alpar@1326
   580
  void LpGlpk::presolver(bool b)
alpar@1326
   581
  {
alpar@1326
   582
    lpx_set_int_parm(lp, LPX_K_PRESOL, b);
alpar@1326
   583
  }
alpar@1326
   584
alpar@1312
   585
 
athos@1261
   586
} //END OF NAMESPACE LEMON