COIN-OR::LEMON - Graph Library

Ticket #203: faster-addrow-c46afb3f67a6.patch

File faster-addrow-c46afb3f67a6.patch, 4.7 KB (added by Tapolcai János, 16 years ago)
  • lemon/lp_base.h

    # HG changeset patch
    # User tapolcai@opti.tmit.bme.hu
    # Date 1232384495 -3600
    # Node ID a7b59195961a46c22b4caf361fd36cde482c0e6a
    # Parent  c46afb3f67a660bc039746a688210033927b1f5a
    faster lb _addRow function
    
    diff --git a/lemon/lp_base.h b/lemon/lp_base.h
    a b namespace lemon { 
    597597      const Value &upperBound() const { return _ub; }
    598598      ///Is the constraint lower bounded?
    599599      bool lowerBounded() const {
    600         return _lb != -INF && !isnan(_lb);
     600        return _lb != -INF && !std::isnan(_lb);
    601601      }
    602602      ///Is the constraint upper bounded?
    603603      bool upperBounded() const {
    604         return _ub != INF && !isnan(_ub);
     604        return _ub != INF && !std::isnan(_ub);
    605605      }
    606606
    607607    };
    namespace lemon { 
    941941    virtual void _setRowName(int row, const std::string& name) = 0;
    942942    virtual int _rowByName(const std::string& name) const = 0;
    943943
     944    virtual int _addRow(ExprIterator b, ExprIterator e){
     945      int i=_addRow();_setRowCoeffs(i, b, e); return i;
     946    };
    944947    virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e) = 0;
    945948    virtual void _getRowCoeffs(int i, InsertIterator b) const = 0;
    946949
    namespace lemon { 
    10671070    ///a better one.
    10681071    void col(Col c, const DualExpr &e) {
    10691072      e.simplify();
    1070       _setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), rows),
    1071                     ExprIterator(e.comps.end(), rows));
     1073      _setColCoeffs(cols(id(c)), ExprIterator(e.comps.begin(), cols),
     1074                    ExprIterator(e.comps.end(), cols));
    10721075    }
    10731076
    10741077    ///Get a column (i.e a dual constraint) of the LP
    namespace lemon { 
    11971200    ///\param u is the upper bound (\ref INF means no bound)
    11981201    ///\return The created row.
    11991202    Row addRow(Value l,const Expr &e, Value u) {
    1200       Row r=addRow();
    1201       row(r,l,e,u);
     1203      Row r;
     1204      e.simplify();
     1205      int id=_addRow(ExprIterator(e.comps.begin(), cols),
     1206                    ExprIterator(e.comps.end(), cols));
     1207      _setRowLowerBound(id,l - *e);
     1208      _setRowUpperBound(id,u - *e);
     1209      r._id=id;
    12021210      return r;
    12031211    }
    12041212
    namespace lemon { 
    12071215    ///\param c is a linear expression (see \ref Constr)
    12081216    ///\return The created row.
    12091217    Row addRow(const Constr &c) {
    1210       Row r=addRow();
    1211       row(r,c);
     1218      Row r=addRow(c.lowerBounded()?c.lowerBound():-INF,
     1219            c.expr(), c.upperBounded()?c.upperBound():INF);
    12121220      return r;
    12131221    }
    12141222    ///Erase a column (i.e a variable) from the LP
    namespace lemon { 
    16661674  inline LpBase::Constr operator<=(const LpBase::Value &n,
    16671675                                   const LpBase::Constr &c) {
    16681676    LpBase::Constr tmp(c);
    1669     LEMON_ASSERT(isnan(tmp.lowerBound()), "Wrong LP constraint");
     1677    LEMON_ASSERT(std::isnan(tmp.lowerBound()), "Wrong LP constraint");
    16701678    tmp.lowerBound()=n;
    16711679    return tmp;
    16721680  }
    namespace lemon { 
    16781686                                   const LpBase::Value &n)
    16791687  {
    16801688    LpBase::Constr tmp(c);
    1681     LEMON_ASSERT(isnan(tmp.upperBound()), "Wrong LP constraint");
     1689    LEMON_ASSERT(std::isnan(tmp.upperBound()), "Wrong LP constraint");
    16821690    tmp.upperBound()=n;
    16831691    return tmp;
    16841692  }
    namespace lemon { 
    16901698  inline LpBase::Constr operator>=(const LpBase::Value &n,
    16911699                                   const LpBase::Constr &c) {
    16921700    LpBase::Constr tmp(c);
    1693     LEMON_ASSERT(isnan(tmp.upperBound()), "Wrong LP constraint");
     1701    LEMON_ASSERT(std::isnan(tmp.upperBound()), "Wrong LP constraint");
    16941702    tmp.upperBound()=n;
    16951703    return tmp;
    16961704  }
    namespace lemon { 
    17021710                                   const LpBase::Value &n)
    17031711  {
    17041712    LpBase::Constr tmp(c);
    1705     LEMON_ASSERT(isnan(tmp.lowerBound()), "Wrong LP constraint");
     1713    LEMON_ASSERT(std::isnan(tmp.lowerBound()), "Wrong LP constraint");
    17061714    tmp.lowerBound()=n;
    17071715    return tmp;
    17081716  }
  • lemon/lp_skeleton.cc

    diff --git a/lemon/lp_skeleton.cc b/lemon/lp_skeleton.cc
    a b namespace lemon { 
    4343  void SkeletonSolverBase::_setRowName(int, const std::string &) {}
    4444  int SkeletonSolverBase::_rowByName(const std::string&) const { return -1; }
    4545
     46  int SkeletonSolverBase::_addRow(ExprIterator, ExprIterator) { return -1; }
    4647  void SkeletonSolverBase::_setRowCoeffs(int, ExprIterator, ExprIterator) {}
    4748  void SkeletonSolverBase::_getRowCoeffs(int, InsertIterator) const {}
    4849
  • lemon/lp_skeleton.h

    diff --git a/lemon/lp_skeleton.h b/lemon/lp_skeleton.h
    a b namespace lemon { 
    5757    /// \e
    5858    virtual int _rowByName(const std::string& name) const;
    5959
     60    /// \e
     61    virtual int _addRow(ExprIterator b, ExprIterator e);
    6062    /// \e
    6163    virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
    6264    /// \e