- colName() added (untested on CPLEX)
authoralpar
Sat, 14 Jan 2006 08:44:59 +0000
changeset 18955b01801efbc0
parent 1894 f794a0bb40c9
child 1896 92ef660710f1
- colName() added (untested on CPLEX)
- possibility to set lower/upper bounds of several cols at once
- setObj() -> obj()
- setRow() -> row()
lemon/lp_base.h
lemon/lp_cplex.cc
lemon/lp_cplex.h
lemon/lp_glpk.cc
lemon/lp_glpk.h
lemon/lp_skeleton.cc
lemon/lp_skeleton.h
test/lp_test.cc
     1.1 --- a/lemon/lp_base.h	Sat Jan 14 08:17:00 2006 +0000
     1.2 +++ b/lemon/lp_base.h	Sat Jan 14 08:44:59 2006 +0000
     1.3 @@ -572,6 +572,8 @@
     1.4      virtual int _addRow() = 0;
     1.5      virtual void _eraseCol(int col) = 0;
     1.6      virtual void _eraseRow(int row) = 0;
     1.7 +    virtual void _getColName(int col,       std::string & name) = 0;
     1.8 +    virtual void _setColName(int col, const std::string & name) = 0;
     1.9      virtual void _setRowCoeffs(int i, 
    1.10  			       int length,
    1.11                                 int  const * indices, 
    1.12 @@ -808,7 +810,7 @@
    1.13      ///a better one.
    1.14      ///\todo Option to control whether a constraint with a single variable is
    1.15      ///added or not.
    1.16 -    void setRow(Row r, Value l,const Expr &e, Value u) {
    1.17 +    void row(Row r, Value l,const Expr &e, Value u) {
    1.18        std::vector<int> indices;
    1.19        std::vector<Value> values;
    1.20        indices.push_back(0);
    1.21 @@ -829,8 +831,8 @@
    1.22  
    1.23      ///\param r is the row to be modified
    1.24      ///\param c is a linear expression (see \ref Constr)
    1.25 -    void setRow(Row r, const Constr &c) {
    1.26 -      setRow(r,
    1.27 +    void row(Row r, const Constr &c) {
    1.28 +      row(r,
    1.29  	     c.lowerBounded()?c.lowerBound():-INF,
    1.30  	     c.expr(),
    1.31  	     c.upperBounded()?c.upperBound():INF);
    1.32 @@ -846,7 +848,7 @@
    1.33      ///a better one.
    1.34      Row addRow(Value l,const Expr &e, Value u) {
    1.35        Row r=addRow();
    1.36 -      setRow(r,l,e,u);
    1.37 +      row(r,l,e,u);
    1.38        return r;
    1.39      }
    1.40  
    1.41 @@ -856,7 +858,7 @@
    1.42      ///\return The created row.
    1.43      Row addRow(const Constr &c) {
    1.44        Row r=addRow();
    1.45 -      setRow(r,c);
    1.46 +      row(r,c);
    1.47        return r;
    1.48      }
    1.49      ///Erase a coloumn (i.e a variable) from the LP
    1.50 @@ -876,23 +878,80 @@
    1.51        rows.erase(r.id);
    1.52      }
    1.53  
    1.54 -    ///Set an element of the coefficient matrix of the LP
    1.55 +    /// Get the name of a column
    1.56 +    
    1.57 +    ///\param c is the coresponding coloumn 
    1.58 +    ///\return The name of the colunm
    1.59 +    std::string ColName(Col c){
    1.60 +      std::string name;
    1.61 +      _getColName(cols.floatingId(c.id), name);
    1.62 +      return name;
    1.63 +    }
    1.64 +    
    1.65 +    /// Set the name of a column
    1.66 +    
    1.67 +    ///\param c is the coresponding coloumn 
    1.68 +    ///\param name The name to be given
    1.69 +    void ColName(Col c, const std::string & name){
    1.70 +      _setColName(cols.floatingId(c.id), name);
    1.71 +    }
    1.72 +    
    1.73 +    /// Set an element of the coefficient matrix of the LP
    1.74  
    1.75      ///\param r is the row of the element to be modified
    1.76      ///\param c is the coloumn of the element to be modified
    1.77      ///\param val is the new value of the coefficient
    1.78 -    void setCoeff(Row r, Col c, Value val){
    1.79 +
    1.80 +    void Coeff(Row r, Col c, Value val){
    1.81        _setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
    1.82      }
    1.83  
    1.84      /// Set the lower bound of a column (i.e a variable)
    1.85  
    1.86 -    /// The upper bound of a variable (column) has to be given by an 
    1.87 +    /// The lower bound of a variable (column) has to be given by an 
    1.88      /// extended number of type Value, i.e. a finite number of type 
    1.89      /// Value or -\ref INF.
    1.90      void colLowerBound(Col c, Value value) {
    1.91        _setColLowerBound(cols.floatingId(c.id),value);
    1.92      }
    1.93 +    
    1.94 +    ///\brief Set the lower bound of  several columns
    1.95 +    ///(i.e a variables) at once
    1.96 +    ///
    1.97 +    ///This magic function takes a container as its argument
    1.98 +    ///and applies the function on all of its elements.
    1.99 +    /// The lower bound of a variable (column) has to be given by an 
   1.100 +    /// extended number of type Value, i.e. a finite number of type 
   1.101 +    /// Value or -\ref INF.
   1.102 +#ifdef DOXYGEN
   1.103 +    template<class T>
   1.104 +    void colLowerBound(T &t, Value value) { return 0;} 
   1.105 +#else
   1.106 +    template<class T>
   1.107 +    typename enable_if<typename T::value_type::LpSolverCol,void>::type
   1.108 +    colLowerBound(T &t, Value value,dummy<0> = 0) {
   1.109 +      for(typename T::iterator i=t.begin();i!=t.end();++i) {
   1.110 +	colLowerBound(*i, value);
   1.111 +      }
   1.112 +    }
   1.113 +    template<class T>
   1.114 +    typename enable_if<typename T::value_type::second_type::LpSolverCol,
   1.115 +		       void>::type
   1.116 +    colLowerBound(T &t, Value value,dummy<1> = 1) { 
   1.117 +      for(typename T::iterator i=t.begin();i!=t.end();++i) {
   1.118 +	colLowerBound(i->second, value);
   1.119 +      }
   1.120 +    }
   1.121 +    template<class T>
   1.122 +    typename enable_if<typename T::MapIt::Value::LpSolverCol,
   1.123 +		       void>::type
   1.124 +    colLowerBound(T &t, Value value,dummy<2> = 2) { 
   1.125 +      for(typename T::MapIt i(t); i!=INVALID; ++i){
   1.126 +	colLowerBound(*i, value);
   1.127 +      }
   1.128 +    }
   1.129 +#endif
   1.130 +    
   1.131      /// Set the upper bound of a column (i.e a variable)
   1.132  
   1.133      /// The upper bound of a variable (column) has to be given by an 
   1.134 @@ -901,6 +960,44 @@
   1.135      void colUpperBound(Col c, Value value) {
   1.136        _setColUpperBound(cols.floatingId(c.id),value);
   1.137      };
   1.138 +
   1.139 +    ///\brief Set the lower bound of  several columns
   1.140 +    ///(i.e a variables) at once
   1.141 +    ///
   1.142 +    ///This magic function takes a container as its argument
   1.143 +    ///and applies the function on all of its elements.
   1.144 +    /// The upper bound of a variable (column) has to be given by an 
   1.145 +    /// extended number of type Value, i.e. a finite number of type 
   1.146 +    /// Value or \ref INF.
   1.147 +#ifdef DOXYGEN
   1.148 +    template<class T>
   1.149 +    void colUpperBound(T &t, Value value) { return 0;} 
   1.150 +#else
   1.151 +    template<class T>
   1.152 +    typename enable_if<typename T::value_type::LpSolverCol,void>::type
   1.153 +    colUpperBound(T &t, Value value,dummy<0> = 0) {
   1.154 +      for(typename T::iterator i=t.begin();i!=t.end();++i) {
   1.155 +	colUpperBound(*i, value);
   1.156 +      }
   1.157 +    }
   1.158 +    template<class T>
   1.159 +    typename enable_if<typename T::value_type::second_type::LpSolverCol,
   1.160 +		       void>::type
   1.161 +    colUpperBound(T &t, Value value,dummy<1> = 1) { 
   1.162 +      for(typename T::iterator i=t.begin();i!=t.end();++i) {
   1.163 +	colUpperBound(i->second, value);
   1.164 +      }
   1.165 +    }
   1.166 +    template<class T>
   1.167 +    typename enable_if<typename T::MapIt::Value::LpSolverCol,
   1.168 +		       void>::type
   1.169 +    colUpperBound(T &t, Value value,dummy<2> = 2) { 
   1.170 +      for(typename T::MapIt i(t); i!=INVALID; ++i){
   1.171 +	colUpperBound(*i, value);
   1.172 +      }
   1.173 +    }
   1.174 +#endif
   1.175 +
   1.176      /// Set the lower and the upper bounds of a column (i.e a variable)
   1.177  
   1.178      /// The lower and the upper bounds of
   1.179 @@ -912,6 +1009,44 @@
   1.180        _setColUpperBound(cols.floatingId(c.id),upper);
   1.181      }
   1.182      
   1.183 +    ///\brief Set the lower and the upper bound of several columns
   1.184 +    ///(i.e a variables) at once
   1.185 +    ///
   1.186 +    ///This magic function takes a container as its argument
   1.187 +    ///and applies the function on all of its elements.
   1.188 +    /// The lower and the upper bounds of
   1.189 +    /// a variable (column) have to be given by an 
   1.190 +    /// extended number of type Value, i.e. a finite number of type 
   1.191 +    /// Value, -\ref INF or \ref INF.
   1.192 +#ifdef DOXYGEN
   1.193 +    template<class T>
   1.194 +    void colBounds(T &t, Value lower, Value upper) { return 0;} 
   1.195 +#else
   1.196 +    template<class T>
   1.197 +    typename enable_if<typename T::value_type::LpSolverCol,void>::type
   1.198 +    colBounds(T &t, Value lower, Value upper,dummy<0> = 0) {
   1.199 +      for(typename T::iterator i=t.begin();i!=t.end();++i) {
   1.200 +	colBounds(*i, lower, upper);
   1.201 +      }
   1.202 +    }
   1.203 +    template<class T>
   1.204 +    typename enable_if<typename T::value_type::second_type::LpSolverCol,
   1.205 +		       void>::type
   1.206 +    colBounds(T &t, Value lower, Value upper,dummy<1> = 1) { 
   1.207 +      for(typename T::iterator i=t.begin();i!=t.end();++i) {
   1.208 +	colBounds(i->second, lower, upper);
   1.209 +      }
   1.210 +    }
   1.211 +    template<class T>
   1.212 +    typename enable_if<typename T::MapIt::Value::LpSolverCol,
   1.213 +		       void>::type
   1.214 +    colBounds(T &t, Value lower, Value upper,dummy<2> = 2) { 
   1.215 +      for(typename T::MapIt i(t); i!=INVALID; ++i){
   1.216 +	colBounds(*i, lower, upper);
   1.217 +      }
   1.218 +    }
   1.219 +#endif
   1.220 +    
   1.221  //     /// Set the lower bound of a row (i.e a constraint)
   1.222  
   1.223  //     /// The lower bound of a linear expression (row) has to be given by an 
   1.224 @@ -945,6 +1080,7 @@
   1.225      ///Set the objective function
   1.226      
   1.227      ///\param e is a linear expression of type \ref Expr.
   1.228 +    ///\bug Is should be called obj()
   1.229      void setObj(Expr e) {
   1.230        _clearObj();
   1.231        for (Expr::iterator i=e.begin(); i!=e.end(); ++i)
     2.1 --- a/lemon/lp_cplex.cc	Sat Jan 14 08:17:00 2006 +0000
     2.2 +++ b/lemon/lp_cplex.cc	Sat Jan 14 08:44:59 2006 +0000
     2.3 @@ -80,7 +80,17 @@
     2.4    void LpCplex::_eraseRow(int i) {
     2.5      CPXdelrows(env, lp, i, i);
     2.6    }
     2.7 -
     2.8 +  
     2.9 +  void LpCplex::_getColName(int col, std::string &name)
    2.10 +  {
    2.11 +    ///\bug Unimplemented
    2.12 +  }
    2.13 +  
    2.14 +  void LpCplex::_setColName(int col, const std::string &name)
    2.15 +  {
    2.16 +    ///\bug Untested
    2.17 +    CPXchgcolname(env, lp, 1, &col, const_cast<char*>(name.c_str()));
    2.18 +  }
    2.19    
    2.20    ///\warning Data at index 0 is ignored in the arrays.
    2.21    void LpCplex::_setRowCoeffs(int i, 
     3.1 --- a/lemon/lp_cplex.h	Sat Jan 14 08:17:00 2006 +0000
     3.2 +++ b/lemon/lp_cplex.h	Sat Jan 14 08:44:59 2006 +0000
     3.3 @@ -57,6 +57,8 @@
     3.4      virtual int _addRow();
     3.5      virtual void _eraseCol(int i);
     3.6      virtual void _eraseRow(int i);
     3.7 +    virtual void _getColName(int col,       std::string & name);
     3.8 +    virtual void _setColName(int col, const std::string & name);
     3.9      virtual void _setRowCoeffs(int i, 
    3.10  			       int length,
    3.11                                 const int   * indices, 
     4.1 --- a/lemon/lp_glpk.cc	Sat Jan 14 08:17:00 2006 +0000
     4.2 +++ b/lemon/lp_glpk.cc	Sat Jan 14 08:44:59 2006 +0000
     4.3 @@ -104,6 +104,19 @@
     4.4      lpx_del_rows(lp, 1, rows);
     4.5    }
     4.6  
     4.7 +  void LpGlpk::_getColName(int col, std::string & name)
     4.8 +  {
     4.9 +    
    4.10 +    char *n = lpx_get_col_name(lp,col);
    4.11 +    name = n?n:"";
    4.12 +  }
    4.13 +  
    4.14 +  
    4.15 +  void LpGlpk::_setColName(int col, const std::string & name)
    4.16 +  {
    4.17 +    lpx_set_col_name(lp,col,const_cast<char*>(name.c_str()));
    4.18 +  }
    4.19 +  
    4.20    void LpGlpk::_setRowCoeffs(int i, 
    4.21  			     int length,
    4.22  			     const int   * indices, 
     5.1 --- a/lemon/lp_glpk.h	Sat Jan 14 08:17:00 2006 +0000
     5.2 +++ b/lemon/lp_glpk.h	Sat Jan 14 08:44:59 2006 +0000
     5.3 @@ -52,7 +52,8 @@
     5.4      virtual int _addRow();
     5.5      virtual void _eraseCol(int i);
     5.6      virtual void _eraseRow(int i);
     5.7 -
     5.8 +    virtual void _getColName(int col,       std::string & name);
     5.9 +    virtual void _setColName(int col, const std::string & name);
    5.10      virtual void _setRowCoeffs(int i, 
    5.11  			       int length,
    5.12                                 const int   * indices, 
     6.1 --- a/lemon/lp_skeleton.cc	Sat Jan 14 08:17:00 2006 +0000
     6.2 +++ b/lemon/lp_skeleton.cc	Sat Jan 14 08:44:59 2006 +0000
     6.3 @@ -48,6 +48,14 @@
     6.4    void LpSkeleton::_eraseRow(int) {
     6.5    }
     6.6  
     6.7 +  void LpSkeleton::_getColName(int, std::string &) {
     6.8 +  }
     6.9 +  
    6.10 +  
    6.11 +  void LpSkeleton::_setColName(int, const std::string &) {
    6.12 +  }
    6.13 +  
    6.14 +  
    6.15    void LpSkeleton::_setRowCoeffs(int, 
    6.16  				 int,
    6.17  				 int  const *, 
     7.1 --- a/lemon/lp_skeleton.h	Sat Jan 14 08:17:00 2006 +0000
     7.2 +++ b/lemon/lp_skeleton.h	Sat Jan 14 08:44:59 2006 +0000
     7.3 @@ -41,6 +41,11 @@
     7.4      /// \e
     7.5      virtual void _eraseRow(int i);
     7.6      /// \e
     7.7 +    virtual void _getColName(int col,       std::string & name);
     7.8 +    /// \e
     7.9 +    virtual void _setColName(int col, const std::string & name);
    7.10 +
    7.11 +    /// \e
    7.12  
    7.13      /// \warning Arrays are indexed from 1 (datum at index 0 is ignored)
    7.14      ///
     8.1 --- a/test/lp_test.cc	Sat Jan 14 08:17:00 2006 +0000
     8.2 +++ b/test/lp_test.cc	Sat Jan 14 08:44:59 2006 +0000
     8.3 @@ -27,21 +27,31 @@
     8.4    std::vector<LP::Col> x(10);
     8.5    //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
     8.6    lp.addColSet(x);
     8.7 -
     8.8 +  lp.colLowerBound(x,1);
     8.9 +  lp.colUpperBound(x,1);
    8.10 +  lp.colBounds(x,1,2);
    8.11  #ifndef GYORSITAS
    8.12  
    8.13    std::vector<LP::Col> y(10);
    8.14    lp.addColSet(y);
    8.15  
    8.16 +  lp.colLowerBound(y,1);
    8.17 +  lp.colUpperBound(y,1);
    8.18 +  lp.colBounds(y,1,2);
    8.19 +
    8.20    std::map<int,LP::Col> z;
    8.21    
    8.22    z.insert(std::make_pair(12,INVALID));
    8.23    z.insert(std::make_pair(2,INVALID));
    8.24    z.insert(std::make_pair(7,INVALID));
    8.25    z.insert(std::make_pair(5,INVALID));
    8.26 -  
    8.27 +
    8.28    lp.addColSet(z);
    8.29  
    8.30 +  lp.colLowerBound(z,1);
    8.31 +  lp.colUpperBound(z,1);
    8.32 +  lp.colBounds(z,1,2);
    8.33 +
    8.34    {
    8.35      LP::Expr e,f,g;
    8.36      LP::Col p1,p2,p3,p4,p5;