COIN-OR::LEMON - Graph Library

Changeset 1895:5b01801efbc0 in lemon-0.x


Ignore:
Timestamp:
01/14/06 09:44:59 (19 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2470
Message:
  • colName() added (untested on CPLEX)
  • possibility to set lower/upper bounds of several cols at once
  • setObj() -> obj()
  • setRow() -> row()
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • lemon/lp_base.h

    r1875 r1895  
    573573    virtual void _eraseCol(int col) = 0;
    574574    virtual void _eraseRow(int row) = 0;
     575    virtual void _getColName(int col,       std::string & name) = 0;
     576    virtual void _setColName(int col, const std::string & name) = 0;
    575577    virtual void _setRowCoeffs(int i,
    576578                               int length,
     
    809811    ///\todo Option to control whether a constraint with a single variable is
    810812    ///added or not.
    811     void setRow(Row r, Value l,const Expr &e, Value u) {
     813    void row(Row r, Value l,const Expr &e, Value u) {
    812814      std::vector<int> indices;
    813815      std::vector<Value> values;
     
    830832    ///\param r is the row to be modified
    831833    ///\param c is a linear expression (see \ref Constr)
    832     void setRow(Row r, const Constr &c) {
    833       setRow(r,
     834    void row(Row r, const Constr &c) {
     835      row(r,
    834836             c.lowerBounded()?c.lowerBound():-INF,
    835837             c.expr(),
     
    847849    Row addRow(Value l,const Expr &e, Value u) {
    848850      Row r=addRow();
    849       setRow(r,l,e,u);
     851      row(r,l,e,u);
    850852      return r;
    851853    }
     
    857859    Row addRow(const Constr &c) {
    858860      Row r=addRow();
    859       setRow(r,c);
     861      row(r,c);
    860862      return r;
    861863    }
     
    877879    }
    878880
    879     ///Set an element of the coefficient matrix of the LP
     881    /// Get the name of a column
     882   
     883    ///\param c is the coresponding coloumn
     884    ///\return The name of the colunm
     885    std::string ColName(Col c){
     886      std::string name;
     887      _getColName(cols.floatingId(c.id), name);
     888      return name;
     889    }
     890   
     891    /// Set the name of a column
     892   
     893    ///\param c is the coresponding coloumn
     894    ///\param name The name to be given
     895    void ColName(Col c, const std::string & name){
     896      _setColName(cols.floatingId(c.id), name);
     897    }
     898   
     899    /// Set an element of the coefficient matrix of the LP
    880900
    881901    ///\param r is the row of the element to be modified
    882902    ///\param c is the coloumn of the element to be modified
    883903    ///\param val is the new value of the coefficient
    884     void setCoeff(Row r, Col c, Value val){
     904
     905    void Coeff(Row r, Col c, Value val){
    885906      _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
    886907    }
     
    888909    /// Set the lower bound of a column (i.e a variable)
    889910
    890     /// The upper bound of a variable (column) has to be given by an
     911    /// The lower bound of a variable (column) has to be given by an
    891912    /// extended number of type Value, i.e. a finite number of type
    892913    /// Value or -\ref INF.
     
    894915      _setColLowerBound(cols.floatingId(c.id),value);
    895916    }
     917   
     918    ///\brief Set the lower bound of  several columns
     919    ///(i.e a variables) at once
     920    ///
     921    ///This magic function takes a container as its argument
     922    ///and applies the function on all of its elements.
     923    /// The lower bound of a variable (column) has to be given by an
     924    /// extended number of type Value, i.e. a finite number of type
     925    /// Value or -\ref INF.
     926#ifdef DOXYGEN
     927    template<class T>
     928    void colLowerBound(T &t, Value value) { return 0;}
     929#else
     930    template<class T>
     931    typename enable_if<typename T::value_type::LpSolverCol,void>::type
     932    colLowerBound(T &t, Value value,dummy<0> = 0) {
     933      for(typename T::iterator i=t.begin();i!=t.end();++i) {
     934        colLowerBound(*i, value);
     935      }
     936    }
     937    template<class T>
     938    typename enable_if<typename T::value_type::second_type::LpSolverCol,
     939                       void>::type
     940    colLowerBound(T &t, Value value,dummy<1> = 1) {
     941      for(typename T::iterator i=t.begin();i!=t.end();++i) {
     942        colLowerBound(i->second, value);
     943      }
     944    }
     945    template<class T>
     946    typename enable_if<typename T::MapIt::Value::LpSolverCol,
     947                       void>::type
     948    colLowerBound(T &t, Value value,dummy<2> = 2) {
     949      for(typename T::MapIt i(t); i!=INVALID; ++i){
     950        colLowerBound(*i, value);
     951      }
     952    }
     953#endif
     954   
    896955    /// Set the upper bound of a column (i.e a variable)
    897956
     
    902961      _setColUpperBound(cols.floatingId(c.id),value);
    903962    };
     963
     964    ///\brief Set the lower bound of  several columns
     965    ///(i.e a variables) at once
     966    ///
     967    ///This magic function takes a container as its argument
     968    ///and applies the function on all of its elements.
     969    /// The upper bound of a variable (column) has to be given by an
     970    /// extended number of type Value, i.e. a finite number of type
     971    /// Value or \ref INF.
     972#ifdef DOXYGEN
     973    template<class T>
     974    void colUpperBound(T &t, Value value) { return 0;}
     975#else
     976    template<class T>
     977    typename enable_if<typename T::value_type::LpSolverCol,void>::type
     978    colUpperBound(T &t, Value value,dummy<0> = 0) {
     979      for(typename T::iterator i=t.begin();i!=t.end();++i) {
     980        colUpperBound(*i, value);
     981      }
     982    }
     983    template<class T>
     984    typename enable_if<typename T::value_type::second_type::LpSolverCol,
     985                       void>::type
     986    colUpperBound(T &t, Value value,dummy<1> = 1) {
     987      for(typename T::iterator i=t.begin();i!=t.end();++i) {
     988        colUpperBound(i->second, value);
     989      }
     990    }
     991    template<class T>
     992    typename enable_if<typename T::MapIt::Value::LpSolverCol,
     993                       void>::type
     994    colUpperBound(T &t, Value value,dummy<2> = 2) {
     995      for(typename T::MapIt i(t); i!=INVALID; ++i){
     996        colUpperBound(*i, value);
     997      }
     998    }
     999#endif
     1000
    9041001    /// Set the lower and the upper bounds of a column (i.e a variable)
    9051002
     
    9131010    }
    9141011   
     1012    ///\brief Set the lower and the upper bound of several columns
     1013    ///(i.e a variables) at once
     1014    ///
     1015    ///This magic function takes a container as its argument
     1016    ///and applies the function on all of its elements.
     1017    /// The lower and the upper bounds of
     1018    /// a variable (column) have to be given by an
     1019    /// extended number of type Value, i.e. a finite number of type
     1020    /// Value, -\ref INF or \ref INF.
     1021#ifdef DOXYGEN
     1022    template<class T>
     1023    void colBounds(T &t, Value lower, Value upper) { return 0;}
     1024#else
     1025    template<class T>
     1026    typename enable_if<typename T::value_type::LpSolverCol,void>::type
     1027    colBounds(T &t, Value lower, Value upper,dummy<0> = 0) {
     1028      for(typename T::iterator i=t.begin();i!=t.end();++i) {
     1029        colBounds(*i, lower, upper);
     1030      }
     1031    }
     1032    template<class T>
     1033    typename enable_if<typename T::value_type::second_type::LpSolverCol,
     1034                       void>::type
     1035    colBounds(T &t, Value lower, Value upper,dummy<1> = 1) {
     1036      for(typename T::iterator i=t.begin();i!=t.end();++i) {
     1037        colBounds(i->second, lower, upper);
     1038      }
     1039    }
     1040    template<class T>
     1041    typename enable_if<typename T::MapIt::Value::LpSolverCol,
     1042                       void>::type
     1043    colBounds(T &t, Value lower, Value upper,dummy<2> = 2) {
     1044      for(typename T::MapIt i(t); i!=INVALID; ++i){
     1045        colBounds(*i, lower, upper);
     1046      }
     1047    }
     1048#endif
     1049   
    9151050//     /// Set the lower bound of a row (i.e a constraint)
    9161051
     
    9461081   
    9471082    ///\param e is a linear expression of type \ref Expr.
     1083    ///\bug Is should be called obj()
    9481084    void setObj(Expr e) {
    9491085      _clearObj();
  • lemon/lp_cplex.cc

    r1875 r1895  
    8181    CPXdelrows(env, lp, i, i);
    8282  }
    83 
     83 
     84  void LpCplex::_getColName(int col, std::string &name)
     85  {
     86    ///\bug Unimplemented
     87  }
     88 
     89  void LpCplex::_setColName(int col, const std::string &name)
     90  {
     91    ///\bug Untested
     92    CPXchgcolname(env, lp, 1, &col, const_cast<char*>(name.c_str()));
     93  }
    8494 
    8595  ///\warning Data at index 0 is ignored in the arrays.
  • lemon/lp_cplex.h

    r1875 r1895  
    5858    virtual void _eraseCol(int i);
    5959    virtual void _eraseRow(int i);
     60    virtual void _getColName(int col,       std::string & name);
     61    virtual void _setColName(int col, const std::string & name);
    6062    virtual void _setRowCoeffs(int i,
    6163                               int length,
  • lemon/lp_glpk.cc

    r1875 r1895  
    105105  }
    106106
     107  void LpGlpk::_getColName(int col, std::string & name)
     108  {
     109   
     110    char *n = lpx_get_col_name(lp,col);
     111    name = n?n:"";
     112  }
     113 
     114 
     115  void LpGlpk::_setColName(int col, const std::string & name)
     116  {
     117    lpx_set_col_name(lp,col,const_cast<char*>(name.c_str()));
     118  }
     119 
    107120  void LpGlpk::_setRowCoeffs(int i,
    108121                             int length,
  • lemon/lp_glpk.h

    r1875 r1895  
    5353    virtual void _eraseCol(int i);
    5454    virtual void _eraseRow(int i);
    55 
     55    virtual void _getColName(int col,       std::string & name);
     56    virtual void _setColName(int col, const std::string & name);
    5657    virtual void _setRowCoeffs(int i,
    5758                               int length,
  • lemon/lp_skeleton.cc

    r1875 r1895  
    4949  }
    5050
     51  void LpSkeleton::_getColName(int, std::string &) {
     52  }
     53 
     54 
     55  void LpSkeleton::_setColName(int, const std::string &) {
     56  }
     57 
     58 
    5159  void LpSkeleton::_setRowCoeffs(int,
    5260                                 int,
  • lemon/lp_skeleton.h

    r1875 r1895  
    4141    /// \e
    4242    virtual void _eraseRow(int i);
     43    /// \e
     44    virtual void _getColName(int col,       std::string & name);
     45    /// \e
     46    virtual void _setColName(int col, const std::string & name);
     47
    4348    /// \e
    4449
  • test/lp_test.cc

    r1797 r1895  
    2828  //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
    2929  lp.addColSet(x);
    30 
     30  lp.colLowerBound(x,1);
     31  lp.colUpperBound(x,1);
     32  lp.colBounds(x,1,2);
    3133#ifndef GYORSITAS
    3234
    3335  std::vector<LP::Col> y(10);
    3436  lp.addColSet(y);
     37
     38  lp.colLowerBound(y,1);
     39  lp.colUpperBound(y,1);
     40  lp.colBounds(y,1,2);
    3541
    3642  std::map<int,LP::Col> z;
     
    4046  z.insert(std::make_pair(7,INVALID));
    4147  z.insert(std::make_pair(5,INVALID));
    42  
     48
    4349  lp.addColSet(z);
     50
     51  lp.colLowerBound(z,1);
     52  lp.colUpperBound(z,1);
     53  lp.colBounds(z,1,2);
    4454
    4555  {
Note: See TracChangeset for help on using the changeset viewer.