COIN-OR::LEMON - Graph Library

Ticket #255: fc9e366e6759.patch

File fc9e366e6759.patch, 3.4 KB (added by Balazs Dezso, 16 years ago)
  • lemon/glpk.cc

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1238619240 -7200
    # Node ID fc9e366e6759193639870b0673b5f8b618899185
    # Parent  538b3dd9a2c0022e2fe412748bab16f73f8c284b
    Fixing presolver and basis handling
    
    diff -r 538b3dd9a2c0 -r fc9e366e6759 lemon/glpk.cc
    a b  
    533533  GlpkLp::GlpkLp()
    534534    : LpBase(), LpSolver(), GlpkBase() {
    535535    messageLevel(MESSAGE_NO_OUTPUT);
     536    presolver(false);
    536537  }
    537538
    538539  GlpkLp::GlpkLp(const GlpkLp& other)
    539540    : LpBase(other), LpSolver(other), GlpkBase(other) {
    540541    messageLevel(MESSAGE_NO_OUTPUT);
     542    presolver(false);
    541543  }
    542544
    543545  GlpkLp* GlpkLp::newSolver() const { return new GlpkLp; }
     
    574576      smcp.msg_lev = GLP_MSG_ALL;
    575577      break;
    576578    }
     579    smcp.presolve = _presolve;
    577580
    578     if (glp_simplex(lp, &smcp) != 0) return UNSOLVED;
     581    // If the basis is not valid we get an error return value.
     582    // In this case we can try to create a new basis.
     583    switch (glp_simplex(lp, &smcp)) {
     584    case 0:
     585      break;
     586    case GLP_EBADB:
     587    case GLP_ESING:
     588    case GLP_ECOND:
     589      lpx_set_int_parm(lp, LPX_K_MSGLEV, smcp.msg_lev);
     590      glp_adv_basis(lp, 0);
     591      if (glp_simplex(lp, &smcp) != 0) return UNSOLVED;
     592      break;
     593    default:
     594      return UNSOLVED;
     595    }
     596
    579597    return SOLVED;
    580598  }
    581599
     
    600618      break;
    601619    }
    602620    smcp.meth = GLP_DUAL;
     621    smcp.presolve = _presolve;
    603622
    604     if (glp_simplex(lp, &smcp) != 0) return UNSOLVED;
     623    // If the basis is not valid we get an error return value.
     624    // In this case we can try to create a new basis.
     625    switch (glp_simplex(lp, &smcp)) {
     626    case 0:
     627      break;
     628    case GLP_EBADB:
     629    case GLP_ESING:
     630    case GLP_ECOND:
     631      lpx_set_int_parm(lp, LPX_K_MSGLEV, smcp.msg_lev);
     632      glp_adv_basis(lp, 0);
     633      if (glp_simplex(lp, &smcp) != 0) return UNSOLVED;
     634      break;
     635    default:
     636      return UNSOLVED;
     637    }
    605638    return SOLVED;
    606639  }
    607640
     
    819852    }
    820853  }
    821854
    822   void GlpkLp::presolver(bool b) {
    823     lpx_set_int_parm(lp, LPX_K_PRESOL, b ? 1 : 0);
     855  void GlpkLp::presolver(bool presolve) {
     856    _presolve = presolve;
    824857  }
    825858
    826859  void GlpkLp::messageLevel(MessageLevel m) {
     
    881914    }
    882915    smcp.meth = GLP_DUAL;
    883916
    884     if (glp_simplex(lp, &smcp) != 0) return UNSOLVED;
     917    // If the basis is not valid we get an error return value.
     918    // In this case we can try to create a new basis.
     919    switch (glp_simplex(lp, &smcp)) {
     920    case 0:
     921      break;
     922    case GLP_EBADB:
     923    case GLP_ESING:
     924    case GLP_ECOND:
     925      lpx_set_int_parm(lp, LPX_K_MSGLEV, smcp.msg_lev);
     926      glp_adv_basis(lp, 0);
     927      if (glp_simplex(lp, &smcp) != 0) return UNSOLVED;
     928      break;
     929    default:
     930      return UNSOLVED;
     931    }
     932
    885933    if (glp_get_status(lp) != GLP_OPT) return SOLVED;
    886934
    887935    glp_iocp iocp;
  • lemon/glpk.h

    diff -r 538b3dd9a2c0 -r fc9e366e6759 lemon/glpk.h
    a b  
    178178    ///Solve with dual simplex
    179179    SolveExitStatus solveDual();
    180180
     181  private:
     182
     183    bool _presolve;
     184
     185  public:
     186
    181187    ///Turns on or off the presolver
    182188
    183189    ///Turns on (\c b is \c true) or off (\c b is \c false) the presolver
    184190    ///
    185191    ///The presolver is off by default.
    186     void presolver(bool b);
     192    void presolver(bool presolve);
    187193
    188194    ///Enum for \c messageLevel() parameter
    189195    enum MessageLevel {