lemon/lp_glpk.cc
changeset 458 7afc121e0689
child 459 ed54c0d13df0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/lp_glpk.cc	Tue Dec 02 21:40:33 2008 +0100
     1.3 @@ -0,0 +1,644 @@
     1.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library.
     1.7 + *
     1.8 + * Copyright (C) 2003-2008
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +///\file
    1.23 +///\brief Implementation of the LEMON-GLPK lp solver interface.
    1.24 +
    1.25 +#include <lemon/lp_glpk.h>
    1.26 +//#include <iostream>
    1.27 +
    1.28 +extern "C" {
    1.29 +#include <glpk.h>
    1.30 +}
    1.31 +
    1.32 +#if GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15)
    1.33 +#define LEMON_glp(func) (glp_##func)
    1.34 +#define LEMON_lpx(func) (lpx_##func)
    1.35 +
    1.36 +#define LEMON_GLP(def) (GLP_##def)
    1.37 +#define LEMON_LPX(def) (LPX_##def)
    1.38 +
    1.39 +#else
    1.40 +
    1.41 +#define LEMON_glp(func) (lpx_##func)
    1.42 +#define LEMON_lpx(func) (lpx_##func)
    1.43 +
    1.44 +#define LEMON_GLP(def) (LPX_##def)
    1.45 +#define LEMON_LPX(def) (LPX_##def)
    1.46 +
    1.47 +#endif
    1.48 +
    1.49 +namespace lemon {
    1.50 +
    1.51 +  LpGlpk::LpGlpk() : Parent() {
    1.52 +    solved = false;
    1.53 +    rows = _lp_bits::LpId(1);
    1.54 +    cols = _lp_bits::LpId(1);
    1.55 +    lp = LEMON_glp(create_prob)();
    1.56 +    LEMON_glp(create_index)(lp);
    1.57 +    messageLevel(0);
    1.58 +  }
    1.59 +
    1.60 +  LpGlpk::LpGlpk(const LpGlpk &glp) : Parent() {
    1.61 +    solved = false;
    1.62 +    rows = _lp_bits::LpId(1);
    1.63 +    cols = _lp_bits::LpId(1);
    1.64 +    lp = LEMON_glp(create_prob)();
    1.65 +    LEMON_glp(create_index)(lp);
    1.66 +    messageLevel(0);
    1.67 +    //Coefficient matrix, row bounds
    1.68 +    LEMON_glp(add_rows)(lp, LEMON_glp(get_num_rows)(glp.lp));
    1.69 +    LEMON_glp(add_cols)(lp, LEMON_glp(get_num_cols)(glp.lp));
    1.70 +    int len;
    1.71 +    std::vector<int> ind(1+LEMON_glp(get_num_cols)(glp.lp));
    1.72 +    std::vector<Value> val(1+LEMON_glp(get_num_cols)(glp.lp));
    1.73 +    for (int i=1;i<=LEMON_glp(get_num_rows)(glp.lp);++i)
    1.74 +      {
    1.75 +        len=LEMON_glp(get_mat_row)(glp.lp,i,&*ind.begin(),&*val.begin());
    1.76 +        LEMON_glp(set_mat_row)(lp, i,len,&*ind.begin(),&*val.begin());
    1.77 +        LEMON_glp(set_row_bnds)(lp,i,
    1.78 +                                LEMON_glp(get_row_type)(glp.lp,i),
    1.79 +                                LEMON_glp(get_row_lb)(glp.lp,i),
    1.80 +                                LEMON_glp(get_row_ub)(glp.lp,i));
    1.81 +      }
    1.82 +
    1.83 +    //Objective function, coloumn bounds
    1.84 +    LEMON_glp(set_obj_dir)(lp, LEMON_glp(get_obj_dir)(glp.lp));
    1.85 +    //Objectif function's constant term treated separately
    1.86 +    LEMON_glp(set_obj_coef)(lp,0,LEMON_glp(get_obj_coef)(glp.lp,0));
    1.87 +    for (int i=1;i<=LEMON_glp(get_num_cols)(glp.lp);++i)
    1.88 +      {
    1.89 +        LEMON_glp(set_obj_coef)(lp,i,
    1.90 +                                LEMON_glp(get_obj_coef)(glp.lp,i));
    1.91 +        LEMON_glp(set_col_bnds)(lp,i,
    1.92 +                                LEMON_glp(get_col_type)(glp.lp,i),
    1.93 +                                LEMON_glp(get_col_lb)(glp.lp,i),
    1.94 +                                LEMON_glp(get_col_ub)(glp.lp,i));
    1.95 +      }
    1.96 +    rows = glp.rows;
    1.97 +    cols = glp.cols;
    1.98 +  }
    1.99 +
   1.100 +  LpGlpk::~LpGlpk() {
   1.101 +    LEMON_glp(delete_prob)(lp);
   1.102 +  }
   1.103 +
   1.104 +  int LpGlpk::_addCol() {
   1.105 +    int i=LEMON_glp(add_cols)(lp, 1);
   1.106 +    LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FR), 0.0, 0.0);
   1.107 +    solved = false;
   1.108 +    return i;
   1.109 +  }
   1.110 +
   1.111 +  ///\e
   1.112 +
   1.113 +
   1.114 +  LpSolverBase* LpGlpk::_newLp()
   1.115 +  {
   1.116 +    LpGlpk* newlp = new LpGlpk;
   1.117 +    return newlp;
   1.118 +  }
   1.119 +
   1.120 +  ///\e
   1.121 +
   1.122 +  LpSolverBase* LpGlpk::_copyLp()
   1.123 +  {
   1.124 +    LpGlpk *newlp = new LpGlpk(*this);
   1.125 +    return newlp;
   1.126 +  }
   1.127 +
   1.128 +  int LpGlpk::_addRow() {
   1.129 +    int i=LEMON_glp(add_rows)(lp, 1);
   1.130 +    solved = false;
   1.131 +    return i;
   1.132 +  }
   1.133 +
   1.134 +
   1.135 +  void LpGlpk::_eraseCol(int i) {
   1.136 +    int ca[2];
   1.137 +    ca[1]=i;
   1.138 +    LEMON_glp(del_cols)(lp, 1, ca);
   1.139 +    solved = false;
   1.140 +  }
   1.141 +
   1.142 +  void LpGlpk::_eraseRow(int i) {
   1.143 +    int ra[2];
   1.144 +    ra[1]=i;
   1.145 +    LEMON_glp(del_rows)(lp, 1, ra);
   1.146 +    solved = false;
   1.147 +  }
   1.148 +
   1.149 +  void LpGlpk::_getColName(int c, std::string & name) const
   1.150 +  {
   1.151 +
   1.152 +    const char *n = LEMON_glp(get_col_name)(lp,c);
   1.153 +    name = n?n:"";
   1.154 +  }
   1.155 +
   1.156 +
   1.157 +  void LpGlpk::_setColName(int c, const std::string & name)
   1.158 +  {
   1.159 +    LEMON_glp(set_col_name)(lp,c,const_cast<char*>(name.c_str()));
   1.160 +
   1.161 +  }
   1.162 +
   1.163 +  int LpGlpk::_colByName(const std::string& name) const
   1.164 +  {
   1.165 +    int k = LEMON_glp(find_col)(lp, const_cast<char*>(name.c_str()));
   1.166 +    return k > 0 ? k : -1;
   1.167 +  }
   1.168 +
   1.169 +
   1.170 +  void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e)
   1.171 +  {
   1.172 +    std::vector<int> indices;
   1.173 +    std::vector<Value> values;
   1.174 +
   1.175 +    indices.push_back(0);
   1.176 +    values.push_back(0);
   1.177 +
   1.178 +    for(ConstRowIterator it=b; it!=e; ++it) {
   1.179 +      indices.push_back(it->first);
   1.180 +      values.push_back(it->second);
   1.181 +    }
   1.182 +
   1.183 +    LEMON_glp(set_mat_row)(lp, i, values.size() - 1,
   1.184 +                                &indices[0], &values[0]);
   1.185 +
   1.186 +    solved = false;
   1.187 +  }
   1.188 +
   1.189 +  void LpGlpk::_getRowCoeffs(int ix, RowIterator b) const
   1.190 +  {
   1.191 +    int length = LEMON_glp(get_mat_row)(lp, ix, 0, 0);
   1.192 +
   1.193 +    std::vector<int> indices(length + 1);
   1.194 +    std::vector<Value> values(length + 1);
   1.195 +
   1.196 +    LEMON_glp(get_mat_row)(lp, ix, &indices[0], &values[0]);
   1.197 +
   1.198 +    for (int i = 1; i <= length; ++i) {
   1.199 +      *b = std::make_pair(indices[i], values[i]);
   1.200 +      ++b;
   1.201 +    }
   1.202 +  }
   1.203 +
   1.204 +  void LpGlpk::_setColCoeffs(int ix, ConstColIterator b, ConstColIterator e) {
   1.205 +
   1.206 +    std::vector<int> indices;
   1.207 +    std::vector<Value> values;
   1.208 +
   1.209 +    indices.push_back(0);
   1.210 +    values.push_back(0);
   1.211 +
   1.212 +    for(ConstColIterator it=b; it!=e; ++it) {
   1.213 +      indices.push_back(it->first);
   1.214 +      values.push_back(it->second);
   1.215 +    }
   1.216 +
   1.217 +    LEMON_glp(set_mat_col)(lp, ix, values.size() - 1,
   1.218 +                                &indices[0], &values[0]);
   1.219 +
   1.220 +    solved = false;
   1.221 +  }
   1.222 +
   1.223 +  void LpGlpk::_getColCoeffs(int ix, ColIterator b) const
   1.224 +  {
   1.225 +    int length = LEMON_glp(get_mat_col)(lp, ix, 0, 0);
   1.226 +
   1.227 +    std::vector<int> indices(length + 1);
   1.228 +    std::vector<Value> values(length + 1);
   1.229 +
   1.230 +    LEMON_glp(get_mat_col)(lp, ix, &indices[0], &values[0]);
   1.231 +
   1.232 +    for (int i = 1; i <= length; ++i) {
   1.233 +      *b = std::make_pair(indices[i], values[i]);
   1.234 +      ++b;
   1.235 +    }
   1.236 +  }
   1.237 +
   1.238 +  void LpGlpk::_setCoeff(int ix, int jx, Value value)
   1.239 +  {
   1.240 +
   1.241 +    if (LEMON_glp(get_num_cols)(lp) < LEMON_glp(get_num_rows)(lp)) {
   1.242 +
   1.243 +      int length=LEMON_glp(get_mat_row)(lp, ix, 0, 0);
   1.244 +
   1.245 +      std::vector<int> indices(length + 2);
   1.246 +      std::vector<Value> values(length + 2);
   1.247 +
   1.248 +      LEMON_glp(get_mat_row)(lp, ix, &indices[0], &values[0]);
   1.249 +
   1.250 +      //The following code does not suppose that the elements of the
   1.251 +      //array indices are sorted
   1.252 +      bool found=false;
   1.253 +      for (int i = 1; i <= length; ++i) {
   1.254 +        if (indices[i]==jx){
   1.255 +          found=true;
   1.256 +          values[i]=value;
   1.257 +          break;
   1.258 +        }
   1.259 +      }
   1.260 +      if (!found){
   1.261 +        ++length;
   1.262 +        indices[length]=jx;
   1.263 +        values[length]=value;
   1.264 +      }
   1.265 +
   1.266 +      LEMON_glp(set_mat_row)(lp, ix, length, &indices[0], &values[0]);
   1.267 +
   1.268 +    } else {
   1.269 +
   1.270 +      int length=LEMON_glp(get_mat_col)(lp, jx, 0, 0);
   1.271 +
   1.272 +      std::vector<int> indices(length + 2);
   1.273 +      std::vector<Value> values(length + 2);
   1.274 +
   1.275 +      LEMON_glp(get_mat_col)(lp, jx, &indices[0], &values[0]);
   1.276 +
   1.277 +      //The following code does not suppose that the elements of the
   1.278 +      //array indices are sorted
   1.279 +      bool found=false;
   1.280 +      for (int i = 1; i <= length; ++i) {
   1.281 +        if (indices[i]==ix){
   1.282 +          found=true;
   1.283 +          values[i]=value;
   1.284 +          break;
   1.285 +        }
   1.286 +      }
   1.287 +      if (!found){
   1.288 +        ++length;
   1.289 +        indices[length]=ix;
   1.290 +        values[length]=value;
   1.291 +      }
   1.292 +
   1.293 +      LEMON_glp(set_mat_col)(lp, jx, length, &indices[0], &values[0]);
   1.294 +    }
   1.295 +
   1.296 +    solved = false;
   1.297 +  }
   1.298 +
   1.299 +  LpGlpk::Value LpGlpk::_getCoeff(int ix, int jx) const
   1.300 +  {
   1.301 +
   1.302 +    int length=LEMON_glp(get_mat_row)(lp, ix, 0, 0);
   1.303 +
   1.304 +    std::vector<int> indices(length + 1);
   1.305 +    std::vector<Value> values(length + 1);
   1.306 +
   1.307 +    LEMON_glp(get_mat_row)(lp, ix, &indices[0], &values[0]);
   1.308 +
   1.309 +    //The following code does not suppose that the elements of the
   1.310 +    //array indices are sorted
   1.311 +    for (int i = 1; i <= length; ++i) {
   1.312 +      if (indices[i]==jx){
   1.313 +        return values[i];
   1.314 +      }
   1.315 +    }
   1.316 +    return 0;
   1.317 +
   1.318 +  }
   1.319 +
   1.320 +
   1.321 +  void LpGlpk::_setColLowerBound(int i, Value lo)
   1.322 +  {
   1.323 +    if (lo==INF) {
   1.324 +      //FIXME error
   1.325 +    }
   1.326 +    int b=LEMON_glp(get_col_type)(lp, i);
   1.327 +    double up=LEMON_glp(get_col_ub)(lp, i);
   1.328 +    if (lo==-INF) {
   1.329 +      switch (b) {
   1.330 +      case LEMON_GLP(FR):
   1.331 +      case LEMON_GLP(LO):
   1.332 +        LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FR), lo, up);
   1.333 +        break;
   1.334 +      case LEMON_GLP(UP):
   1.335 +        break;
   1.336 +      case LEMON_GLP(DB):
   1.337 +      case LEMON_GLP(FX):
   1.338 +        LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(UP), lo, up);
   1.339 +        break;
   1.340 +      default: ;
   1.341 +        //FIXME error
   1.342 +      }
   1.343 +    } else {
   1.344 +      switch (b) {
   1.345 +      case LEMON_GLP(FR):
   1.346 +      case LEMON_GLP(LO):
   1.347 +        LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(LO), lo, up);
   1.348 +        break;
   1.349 +      case LEMON_GLP(UP):
   1.350 +      case LEMON_GLP(DB):
   1.351 +      case LEMON_GLP(FX):
   1.352 +        if (lo==up)
   1.353 +          LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FX), lo, up);
   1.354 +        else
   1.355 +          LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(DB), lo, up);
   1.356 +        break;
   1.357 +      default: ;
   1.358 +        //FIXME error
   1.359 +      }
   1.360 +    }
   1.361 +
   1.362 +    solved = false;
   1.363 +  }
   1.364 +
   1.365 +  LpGlpk::Value LpGlpk::_getColLowerBound(int i) const
   1.366 +  {
   1.367 +    int b=LEMON_glp(get_col_type)(lp, i);
   1.368 +      switch (b) {
   1.369 +      case LEMON_GLP(LO):
   1.370 +      case LEMON_GLP(DB):
   1.371 +      case LEMON_GLP(FX):
   1.372 +        return LEMON_glp(get_col_lb)(lp, i);
   1.373 +      default: ;
   1.374 +        return -INF;
   1.375 +      }
   1.376 +  }
   1.377 +
   1.378 +  void LpGlpk::_setColUpperBound(int i, Value up)
   1.379 +  {
   1.380 +    if (up==-INF) {
   1.381 +      //FIXME error
   1.382 +    }
   1.383 +    int b=LEMON_glp(get_col_type)(lp, i);
   1.384 +    double lo=LEMON_glp(get_col_lb)(lp, i);
   1.385 +    if (up==INF) {
   1.386 +      switch (b) {
   1.387 +      case LEMON_GLP(FR):
   1.388 +      case LEMON_GLP(LO):
   1.389 +        break;
   1.390 +      case LEMON_GLP(UP):
   1.391 +        LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FR), lo, up);
   1.392 +        break;
   1.393 +      case LEMON_GLP(DB):
   1.394 +      case LEMON_GLP(FX):
   1.395 +        LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(LO), lo, up);
   1.396 +        break;
   1.397 +      default: ;
   1.398 +        //FIXME error
   1.399 +      }
   1.400 +    } else {
   1.401 +      switch (b) {
   1.402 +      case LEMON_GLP(FR):
   1.403 +        LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(UP), lo, up);
   1.404 +        break;
   1.405 +      case LEMON_GLP(UP):
   1.406 +        LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(UP), lo, up);
   1.407 +        break;
   1.408 +      case LEMON_GLP(LO):
   1.409 +      case LEMON_GLP(DB):
   1.410 +      case LEMON_GLP(FX):
   1.411 +        if (lo==up)
   1.412 +          LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(FX), lo, up);
   1.413 +        else
   1.414 +          LEMON_glp(set_col_bnds)(lp, i, LEMON_GLP(DB), lo, up);
   1.415 +        break;
   1.416 +      default: ;
   1.417 +        //FIXME error
   1.418 +      }
   1.419 +    }
   1.420 +
   1.421 +    solved = false;
   1.422 +  }
   1.423 +
   1.424 +  LpGlpk::Value LpGlpk::_getColUpperBound(int i) const
   1.425 +  {
   1.426 +    int b=LEMON_glp(get_col_type)(lp, i);
   1.427 +      switch (b) {
   1.428 +      case LEMON_GLP(UP):
   1.429 +      case LEMON_GLP(DB):
   1.430 +      case LEMON_GLP(FX):
   1.431 +        return LEMON_glp(get_col_ub)(lp, i);
   1.432 +      default: ;
   1.433 +        return INF;
   1.434 +      }
   1.435 +  }
   1.436 +
   1.437 +  void LpGlpk::_setRowBounds(int i, Value lb, Value ub)
   1.438 +  {
   1.439 +    //Bad parameter
   1.440 +    if (lb==INF || ub==-INF) {
   1.441 +      //FIXME error
   1.442 +    }
   1.443 +
   1.444 +    if (lb == -INF){
   1.445 +      if (ub == INF){
   1.446 +        LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(FR), lb, ub);
   1.447 +      }
   1.448 +      else{
   1.449 +        LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(UP), lb, ub);
   1.450 +      }
   1.451 +    }
   1.452 +    else{
   1.453 +      if (ub==INF){
   1.454 +        LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(LO), lb, ub);
   1.455 +
   1.456 +      }
   1.457 +      else{
   1.458 +        if (lb == ub){
   1.459 +          LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(FX), lb, ub);
   1.460 +        }
   1.461 +        else{
   1.462 +          LEMON_glp(set_row_bnds)(lp, i, LEMON_GLP(DB), lb, ub);
   1.463 +        }
   1.464 +      }
   1.465 +    }
   1.466 +
   1.467 +    solved = false;
   1.468 +  }
   1.469 +
   1.470 +  void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) const
   1.471 +  {
   1.472 +
   1.473 +    int b=LEMON_glp(get_row_type)(lp, i);
   1.474 +    switch (b) {
   1.475 +    case LEMON_GLP(FR):
   1.476 +    case LEMON_GLP(UP):
   1.477 +      lb = -INF;
   1.478 +        break;
   1.479 +    default:
   1.480 +      lb=LEMON_glp(get_row_lb)(lp, i);
   1.481 +    }
   1.482 +
   1.483 +    switch (b) {
   1.484 +    case LEMON_GLP(FR):
   1.485 +    case LEMON_GLP(LO):
   1.486 +      ub = INF;
   1.487 +        break;
   1.488 +    default:
   1.489 +      ub=LEMON_glp(get_row_ub)(lp, i);
   1.490 +    }
   1.491 +
   1.492 +  }
   1.493 +
   1.494 +  void LpGlpk::_setObjCoeff(int i, Value obj_coef)
   1.495 +  {
   1.496 +    //i=0 means the constant term (shift)
   1.497 +    LEMON_glp(set_obj_coef)(lp, i, obj_coef);
   1.498 +
   1.499 +    solved = false;
   1.500 +  }
   1.501 +
   1.502 +  LpGlpk::Value LpGlpk::_getObjCoeff(int i) const {
   1.503 +    //i=0 means the constant term (shift)
   1.504 +    return LEMON_glp(get_obj_coef)(lp, i);
   1.505 +  }
   1.506 +
   1.507 +  void LpGlpk::_clearObj()
   1.508 +  {
   1.509 +    for (int i=0;i<=LEMON_glp(get_num_cols)(lp);++i){
   1.510 +      LEMON_glp(set_obj_coef)(lp, i, 0);
   1.511 +    }
   1.512 +
   1.513 +    solved = false;
   1.514 +  }
   1.515 +
   1.516 +  LpGlpk::SolveExitStatus LpGlpk::_solve()
   1.517 +  {
   1.518 +    // A way to check the problem to be solved
   1.519 +    //LEMON_glp(write_cpxlp(lp,"naittvan.cpx");
   1.520 +
   1.521 +    LEMON_lpx(std_basis)(lp);
   1.522 +    int i =  LEMON_lpx(simplex)(lp);
   1.523 +
   1.524 +    switch (i) {
   1.525 +    case LEMON_LPX(E_OK):
   1.526 +      solved = true;
   1.527 +      return SOLVED;
   1.528 +    default:
   1.529 +      return UNSOLVED;
   1.530 +    }
   1.531 +  }
   1.532 +
   1.533 +  LpGlpk::Value LpGlpk::_getPrimal(int i) const
   1.534 +  {
   1.535 +    return LEMON_glp(get_col_prim)(lp,i);
   1.536 +  }
   1.537 +
   1.538 +  LpGlpk::Value LpGlpk::_getDual(int i) const
   1.539 +  {
   1.540 +    return LEMON_glp(get_row_dual)(lp,i);
   1.541 +  }
   1.542 +
   1.543 +  LpGlpk::Value LpGlpk::_getPrimalValue() const
   1.544 +  {
   1.545 +    return LEMON_glp(get_obj_val)(lp);
   1.546 +  }
   1.547 +  bool LpGlpk::_isBasicCol(int i) const
   1.548 +  {
   1.549 +    return (LEMON_glp(get_col_stat)(lp, i)==LEMON_GLP(BS));
   1.550 +  }
   1.551 +
   1.552 +
   1.553 +  LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() const
   1.554 +  {
   1.555 +    if (!solved) return UNDEFINED;
   1.556 +    int stat=  LEMON_lpx(get_status)(lp);
   1.557 +    switch (stat) {
   1.558 +    case LEMON_LPX(UNDEF)://Undefined (no solve has been run yet)
   1.559 +      return UNDEFINED;
   1.560 +    case LEMON_LPX(NOFEAS)://There is no feasible solution (primal, I guess)
   1.561 +    case LEMON_LPX(INFEAS)://Infeasible
   1.562 +      return INFEASIBLE;
   1.563 +    case LEMON_LPX(UNBND)://Unbounded
   1.564 +      return INFINITE;
   1.565 +    case LEMON_LPX(FEAS)://Feasible
   1.566 +      return FEASIBLE;
   1.567 +    case LEMON_LPX(OPT)://Feasible
   1.568 +      return OPTIMAL;
   1.569 +    default:
   1.570 +      return UNDEFINED; //to avoid gcc warning
   1.571 +      //FIXME error
   1.572 +    }
   1.573 +  }
   1.574 +
   1.575 +  LpGlpk::SolutionStatus LpGlpk::_getDualStatus() const
   1.576 +  {
   1.577 +    if (!solved) return UNDEFINED;
   1.578 +    switch (LEMON_lpx(get_dual_stat)(lp)) {
   1.579 +    case LEMON_LPX(D_UNDEF)://Undefined (no solve has been run yet)
   1.580 +      return UNDEFINED;
   1.581 +    case LEMON_LPX(D_NOFEAS)://There is no dual feasible solution
   1.582 +//    case LEMON_LPX(D_INFEAS://Infeasible
   1.583 +      return INFEASIBLE;
   1.584 +    case LEMON_LPX(D_FEAS)://Feasible
   1.585 +      switch (LEMON_lpx(get_status)(lp)) {
   1.586 +      case LEMON_LPX(NOFEAS):
   1.587 +        return INFINITE;
   1.588 +      case LEMON_LPX(OPT):
   1.589 +        return OPTIMAL;
   1.590 +      default:
   1.591 +        return FEASIBLE;
   1.592 +      }
   1.593 +    default:
   1.594 +      return UNDEFINED; //to avoid gcc warning
   1.595 +      //FIXME error
   1.596 +    }
   1.597 +  }
   1.598 +
   1.599 +  LpGlpk::ProblemTypes LpGlpk::_getProblemType() const
   1.600 +  {
   1.601 +    if (!solved) return UNKNOWN;
   1.602 +      //int stat=  LEMON_glp(get_status(lp);
   1.603 +    int statp=  LEMON_lpx(get_prim_stat)(lp);
   1.604 +    int statd=  LEMON_lpx(get_dual_stat)(lp);
   1.605 +    if (statp==LEMON_LPX(P_FEAS) && statd==LEMON_LPX(D_FEAS))
   1.606 +        return PRIMAL_DUAL_FEASIBLE;
   1.607 +    if (statp==LEMON_LPX(P_FEAS) && statd==LEMON_LPX(D_NOFEAS))
   1.608 +        return PRIMAL_FEASIBLE_DUAL_INFEASIBLE;
   1.609 +    if (statp==LEMON_LPX(P_NOFEAS) && statd==LEMON_LPX(D_FEAS))
   1.610 +        return PRIMAL_INFEASIBLE_DUAL_FEASIBLE;
   1.611 +    if (statp==LEMON_LPX(P_NOFEAS) && statd==LEMON_LPX(D_NOFEAS))
   1.612 +        return PRIMAL_DUAL_INFEASIBLE;
   1.613 +    //In all other cases
   1.614 +    return UNKNOWN;
   1.615 +  }
   1.616 +
   1.617 +  void LpGlpk::_setMax()
   1.618 +  {
   1.619 +    solved = false;
   1.620 +    LEMON_glp(set_obj_dir)(lp, LEMON_GLP(MAX));
   1.621 +  }
   1.622 +
   1.623 +  void LpGlpk::_setMin()
   1.624 +  {
   1.625 +    solved = false;
   1.626 +    LEMON_glp(set_obj_dir)(lp, LEMON_GLP(MIN));
   1.627 +  }
   1.628 +
   1.629 +  bool LpGlpk::_isMax() const
   1.630 +  {
   1.631 +    return (LEMON_glp(get_obj_dir)(lp)==LEMON_GLP(MAX));
   1.632 +  }
   1.633 +
   1.634 +
   1.635 +
   1.636 +  void LpGlpk::messageLevel(int m)
   1.637 +  {
   1.638 +    LEMON_lpx(set_int_parm)(lp, LEMON_LPX(K_MSGLEV), m);
   1.639 +  }
   1.640 +
   1.641 +  void LpGlpk::presolver(bool b)
   1.642 +  {
   1.643 +    LEMON_lpx(set_int_parm)(lp, LEMON_LPX(K_PRESOL), b);
   1.644 +  }
   1.645 +
   1.646 +
   1.647 +} //END OF NAMESPACE LEMON