lemon/lp_base.h
changeset 1895 5b01801efbc0
parent 1875 98698b69a902
child 1899 2d4835f5a86a
     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)