COIN-OR::LEMON - Graph Library

Changeset 2441:d8d6ab871608 in lemon-0.x for lemon/mip_glpk.cc


Ignore:
Timestamp:
05/07/07 20:19:55 (17 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3278
Message:

Conformity to new GLPK interface
Hacking Mip without integer variables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/mip_glpk.cc

    r2391 r2441  
    2222#include <lemon/mip_glpk.h>
    2323
     24#if GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15)
     25#define LEMON_glp(func) (glp_##func)
     26#define LEMON_lpx(func) (lpx_##func)
     27
     28#define LEMON_GLP(def) (GLP_##def)
     29#define LEMON_LPX(def) (LPX_##def)
     30
     31#else
     32
     33#define LEMON_glp(func) (lpx_##func)
     34#define LEMON_lpx(func) (lpx_##func)
     35
     36#define LEMON_GLP(def) (LPX_##def)
     37#define LEMON_LPX(def) (LPX_##def)
     38
     39#endif
     40
    2441namespace lemon {
    2542 
    2643  MipGlpk::MipGlpk() {
    27     lpx_set_class(lp,LPX_MIP);
     44#if !(GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15))
     45    LEMON_lpx(set_class)(lp,LEMON_GLP(MIP));
     46#endif
    2847  }
    2948
     
    3150    switch (col_type){
    3251      case INT:
    33         lpx_set_col_kind(lp,i,LPX_IV);
     52        LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(IV));
    3453        break;
    3554      case REAL:
    36         lpx_set_col_kind(lp,i,LPX_CV);
     55        LEMON_glp(set_col_kind)(lp,i,LEMON_GLP(CV));
    3756        break;
    3857    default:;
     
    4261 
    4362  MipGlpk::ColTypes MipGlpk::_colType(int i) const {
    44     switch (lpx_get_col_kind(lp,i)){
    45     case LPX_IV:
     63    switch (LEMON_glp(get_col_kind)(lp,i)){
     64    case LEMON_GLP(IV):
    4665      return INT;//Or binary
    47     case LPX_CV:
     66    case LEMON_GLP(CV):
    4867      return REAL;
    4968    default:
     
    5473 
    5574  LpGlpk::SolveExitStatus MipGlpk::_solve() {
    56     int result = lpx_simplex(lp);
    57     //
    58     if (lpx_get_status(lp)==LPX_OPT){
     75    int result = LEMON_lpx(simplex)(lp);
     76
     77    // hack: mip does not contain integer variable
     78#if GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15)
     79    int tmp = -1;
     80    if (LEMON_glp(get_num_int(lp)) == 0) {
     81      tmp = LEMON_lpx(add_cols)(lp, 1);
     82      LEMON_glp(set_col_bnds)(lp, tmp, LEMON_GLP(FX), 0.0, 0.0);
     83      LEMON_glp(set_col_kind)(lp, tmp, LEMON_GLP(IV));
     84    }
     85#endif
     86
     87    if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)) {
    5988      //Maybe we could try the routine lpx_intopt(lp), a revised
    6089      //version of lpx_integer
    61       result = lpx_integer(lp);
     90
     91      result = LEMON_lpx(integer)(lp);
    6292      switch (result){
    63       case LPX_E_OK:
    64         return SOLVED;
     93      case LEMON_LPX(E_OK):
     94        solved = true;
    6595      default:
    66         return UNSOLVED;
    67       }
    68      
     96        solved = false;
     97      } 
     98    } else {
     99      solved = false;
    69100    }
    70     return UNSOLVED;
     101#if GLP_MAJOR_VERSION > 4 || (GLP_MAJOR_VERSION == 4 && GLP_MINOR_VERSION > 15)
     102    if (tmp != -1) {
     103      int tmpa[2];
     104      tmpa[1] = tmp;
     105      LEMON_lpx(del_cols)(lp, 1, tmpa);
     106    }
     107#endif
     108    return solved ? SOLVED : UNSOLVED;
    71109  }
    72110
     
    74112  LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const {
    75113
    76     if (lpx_get_status(lp)==LPX_OPT){
     114    if (LEMON_lpx(get_status)(lp)==LEMON_LPX(OPT)){
    77115      //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is
    78116      //infeasible, akkor ez is, de ez lehet maskepp is infeasible.
    79       int stat=  lpx_mip_status(lp);
     117      int stat= LEMON_lpx(mip_status)(lp);
    80118     
    81119      switch (stat) {
    82       case LPX_I_UNDEF://Undefined (no solve has been run yet)
     120      case LEMON_LPX(I_UNDEF)://Undefined (no solve has been run yet)
    83121        return UNDEFINED;
    84       case LPX_I_NOFEAS://There is no feasible integral solution
     122      case LEMON_LPX(I_NOFEAS)://There is no feasible integral solution
    85123        return INFEASIBLE;
    86         //     case LPX_UNBND://Unbounded
     124        //     case LEMON_LPX(UNBND)://Unbounded
    87125        //       return INFINITE;
    88       case LPX_I_FEAS://Feasible
     126      case LEMON_LPX(I_FEAS)://Feasible
    89127        return FEASIBLE;
    90       case LPX_I_OPT://Feasible
     128      case LEMON_LPX(I_OPT)://Feasible
    91129        return OPTIMAL;
    92130      default:
    93       return UNDEFINED; //to avoid gcc warning
     131        return UNDEFINED; //to avoid gcc warning
    94132      //FIXME error
    95133      }
     
    102140
    103141  MipGlpk::Value MipGlpk::_getPrimal(int i) const {
    104     return lpx_mip_col_val(lp,i);
     142    return LEMON_glp(mip_col_val)(lp,i);
    105143  }
    106144 
    107145  MipGlpk::Value MipGlpk::_getPrimalValue() const {
    108     return lpx_mip_obj_val(lp);
     146    return LEMON_glp(mip_obj_val)(lp);
    109147  }
    110148} //END OF NAMESPACE LEMON
Note: See TracChangeset for help on using the changeset viewer.