[Lemon-commits] [lemon_svn] alpar: r2470 - in hugo/trunk: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:52:55 CET 2006
Author: alpar
Date: Sat Jan 14 09:44:59 2006
New Revision: 2470
Modified:
hugo/trunk/lemon/lp_base.h
hugo/trunk/lemon/lp_cplex.cc
hugo/trunk/lemon/lp_cplex.h
hugo/trunk/lemon/lp_glpk.cc
hugo/trunk/lemon/lp_glpk.h
hugo/trunk/lemon/lp_skeleton.cc
hugo/trunk/lemon/lp_skeleton.h
hugo/trunk/test/lp_test.cc
Log:
- colName() added (untested on CPLEX)
- possibility to set lower/upper bounds of several cols at once
- setObj() -> obj()
- setRow() -> row()
Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h (original)
+++ hugo/trunk/lemon/lp_base.h Sat Jan 14 09:44:59 2006
@@ -572,6 +572,8 @@
virtual int _addRow() = 0;
virtual void _eraseCol(int col) = 0;
virtual void _eraseRow(int row) = 0;
+ virtual void _getColName(int col, std::string & name) = 0;
+ virtual void _setColName(int col, const std::string & name) = 0;
virtual void _setRowCoeffs(int i,
int length,
int const * indices,
@@ -808,7 +810,7 @@
///a better one.
///\todo Option to control whether a constraint with a single variable is
///added or not.
- void setRow(Row r, Value l,const Expr &e, Value u) {
+ void row(Row r, Value l,const Expr &e, Value u) {
std::vector<int> indices;
std::vector<Value> values;
indices.push_back(0);
@@ -829,8 +831,8 @@
///\param r is the row to be modified
///\param c is a linear expression (see \ref Constr)
- void setRow(Row r, const Constr &c) {
- setRow(r,
+ void row(Row r, const Constr &c) {
+ row(r,
c.lowerBounded()?c.lowerBound():-INF,
c.expr(),
c.upperBounded()?c.upperBound():INF);
@@ -846,7 +848,7 @@
///a better one.
Row addRow(Value l,const Expr &e, Value u) {
Row r=addRow();
- setRow(r,l,e,u);
+ row(r,l,e,u);
return r;
}
@@ -856,7 +858,7 @@
///\return The created row.
Row addRow(const Constr &c) {
Row r=addRow();
- setRow(r,c);
+ row(r,c);
return r;
}
///Erase a coloumn (i.e a variable) from the LP
@@ -876,23 +878,80 @@
rows.erase(r.id);
}
- ///Set an element of the coefficient matrix of the LP
+ /// Get the name of a column
+
+ ///\param c is the coresponding coloumn
+ ///\return The name of the colunm
+ std::string ColName(Col c){
+ std::string name;
+ _getColName(cols.floatingId(c.id), name);
+ return name;
+ }
+
+ /// Set the name of a column
+
+ ///\param c is the coresponding coloumn
+ ///\param name The name to be given
+ void ColName(Col c, const std::string & name){
+ _setColName(cols.floatingId(c.id), name);
+ }
+
+ /// Set an element of the coefficient matrix of the LP
///\param r is the row of the element to be modified
///\param c is the coloumn of the element to be modified
///\param val is the new value of the coefficient
- void setCoeff(Row r, Col c, Value val){
+
+ void Coeff(Row r, Col c, Value val){
_setCoeff(rows.floatingId(r.id),cols.floatingId(c.id), val);
}
/// Set the lower bound of a column (i.e a variable)
- /// The upper bound of a variable (column) has to be given by an
+ /// The lower bound of a variable (column) has to be given by an
/// extended number of type Value, i.e. a finite number of type
/// Value or -\ref INF.
void colLowerBound(Col c, Value value) {
_setColLowerBound(cols.floatingId(c.id),value);
}
+
+ ///\brief Set the lower bound of several columns
+ ///(i.e a variables) at once
+ ///
+ ///This magic function takes a container as its argument
+ ///and applies the function on all of its elements.
+ /// The lower bound of a variable (column) has to be given by an
+ /// extended number of type Value, i.e. a finite number of type
+ /// Value or -\ref INF.
+#ifdef DOXYGEN
+ template<class T>
+ void colLowerBound(T &t, Value value) { return 0;}
+#else
+ template<class T>
+ typename enable_if<typename T::value_type::LpSolverCol,void>::type
+ colLowerBound(T &t, Value value,dummy<0> = 0) {
+ for(typename T::iterator i=t.begin();i!=t.end();++i) {
+ colLowerBound(*i, value);
+ }
+ }
+ template<class T>
+ typename enable_if<typename T::value_type::second_type::LpSolverCol,
+ void>::type
+ colLowerBound(T &t, Value value,dummy<1> = 1) {
+ for(typename T::iterator i=t.begin();i!=t.end();++i) {
+ colLowerBound(i->second, value);
+ }
+ }
+ template<class T>
+ typename enable_if<typename T::MapIt::Value::LpSolverCol,
+ void>::type
+ colLowerBound(T &t, Value value,dummy<2> = 2) {
+ for(typename T::MapIt i(t); i!=INVALID; ++i){
+ colLowerBound(*i, value);
+ }
+ }
+#endif
+
/// Set the upper bound of a column (i.e a variable)
/// The upper bound of a variable (column) has to be given by an
@@ -901,6 +960,44 @@
void colUpperBound(Col c, Value value) {
_setColUpperBound(cols.floatingId(c.id),value);
};
+
+ ///\brief Set the lower bound of several columns
+ ///(i.e a variables) at once
+ ///
+ ///This magic function takes a container as its argument
+ ///and applies the function on all of its elements.
+ /// The upper bound of a variable (column) has to be given by an
+ /// extended number of type Value, i.e. a finite number of type
+ /// Value or \ref INF.
+#ifdef DOXYGEN
+ template<class T>
+ void colUpperBound(T &t, Value value) { return 0;}
+#else
+ template<class T>
+ typename enable_if<typename T::value_type::LpSolverCol,void>::type
+ colUpperBound(T &t, Value value,dummy<0> = 0) {
+ for(typename T::iterator i=t.begin();i!=t.end();++i) {
+ colUpperBound(*i, value);
+ }
+ }
+ template<class T>
+ typename enable_if<typename T::value_type::second_type::LpSolverCol,
+ void>::type
+ colUpperBound(T &t, Value value,dummy<1> = 1) {
+ for(typename T::iterator i=t.begin();i!=t.end();++i) {
+ colUpperBound(i->second, value);
+ }
+ }
+ template<class T>
+ typename enable_if<typename T::MapIt::Value::LpSolverCol,
+ void>::type
+ colUpperBound(T &t, Value value,dummy<2> = 2) {
+ for(typename T::MapIt i(t); i!=INVALID; ++i){
+ colUpperBound(*i, value);
+ }
+ }
+#endif
+
/// Set the lower and the upper bounds of a column (i.e a variable)
/// The lower and the upper bounds of
@@ -912,6 +1009,44 @@
_setColUpperBound(cols.floatingId(c.id),upper);
}
+ ///\brief Set the lower and the upper bound of several columns
+ ///(i.e a variables) at once
+ ///
+ ///This magic function takes a container as its argument
+ ///and applies the function on all of its elements.
+ /// The lower and the upper bounds of
+ /// a variable (column) have to be given by an
+ /// extended number of type Value, i.e. a finite number of type
+ /// Value, -\ref INF or \ref INF.
+#ifdef DOXYGEN
+ template<class T>
+ void colBounds(T &t, Value lower, Value upper) { return 0;}
+#else
+ template<class T>
+ typename enable_if<typename T::value_type::LpSolverCol,void>::type
+ colBounds(T &t, Value lower, Value upper,dummy<0> = 0) {
+ for(typename T::iterator i=t.begin();i!=t.end();++i) {
+ colBounds(*i, lower, upper);
+ }
+ }
+ template<class T>
+ typename enable_if<typename T::value_type::second_type::LpSolverCol,
+ void>::type
+ colBounds(T &t, Value lower, Value upper,dummy<1> = 1) {
+ for(typename T::iterator i=t.begin();i!=t.end();++i) {
+ colBounds(i->second, lower, upper);
+ }
+ }
+ template<class T>
+ typename enable_if<typename T::MapIt::Value::LpSolverCol,
+ void>::type
+ colBounds(T &t, Value lower, Value upper,dummy<2> = 2) {
+ for(typename T::MapIt i(t); i!=INVALID; ++i){
+ colBounds(*i, lower, upper);
+ }
+ }
+#endif
+
// /// Set the lower bound of a row (i.e a constraint)
// /// The lower bound of a linear expression (row) has to be given by an
@@ -945,6 +1080,7 @@
///Set the objective function
///\param e is a linear expression of type \ref Expr.
+ ///\bug Is should be called obj()
void setObj(Expr e) {
_clearObj();
for (Expr::iterator i=e.begin(); i!=e.end(); ++i)
Modified: hugo/trunk/lemon/lp_cplex.cc
==============================================================================
--- hugo/trunk/lemon/lp_cplex.cc (original)
+++ hugo/trunk/lemon/lp_cplex.cc Sat Jan 14 09:44:59 2006
@@ -80,7 +80,17 @@
void LpCplex::_eraseRow(int i) {
CPXdelrows(env, lp, i, i);
}
-
+
+ void LpCplex::_getColName(int col, std::string &name)
+ {
+ ///\bug Unimplemented
+ }
+
+ void LpCplex::_setColName(int col, const std::string &name)
+ {
+ ///\bug Untested
+ CPXchgcolname(env, lp, 1, &col, const_cast<char*>(name.c_str()));
+ }
///\warning Data at index 0 is ignored in the arrays.
void LpCplex::_setRowCoeffs(int i,
Modified: hugo/trunk/lemon/lp_cplex.h
==============================================================================
--- hugo/trunk/lemon/lp_cplex.h (original)
+++ hugo/trunk/lemon/lp_cplex.h Sat Jan 14 09:44:59 2006
@@ -57,6 +57,8 @@
virtual int _addRow();
virtual void _eraseCol(int i);
virtual void _eraseRow(int i);
+ virtual void _getColName(int col, std::string & name);
+ virtual void _setColName(int col, const std::string & name);
virtual void _setRowCoeffs(int i,
int length,
const int * indices,
Modified: hugo/trunk/lemon/lp_glpk.cc
==============================================================================
--- hugo/trunk/lemon/lp_glpk.cc (original)
+++ hugo/trunk/lemon/lp_glpk.cc Sat Jan 14 09:44:59 2006
@@ -104,6 +104,19 @@
lpx_del_rows(lp, 1, rows);
}
+ void LpGlpk::_getColName(int col, std::string & name)
+ {
+
+ char *n = lpx_get_col_name(lp,col);
+ name = n?n:"";
+ }
+
+
+ void LpGlpk::_setColName(int col, const std::string & name)
+ {
+ lpx_set_col_name(lp,col,const_cast<char*>(name.c_str()));
+ }
+
void LpGlpk::_setRowCoeffs(int i,
int length,
const int * indices,
Modified: hugo/trunk/lemon/lp_glpk.h
==============================================================================
--- hugo/trunk/lemon/lp_glpk.h (original)
+++ hugo/trunk/lemon/lp_glpk.h Sat Jan 14 09:44:59 2006
@@ -52,7 +52,8 @@
virtual int _addRow();
virtual void _eraseCol(int i);
virtual void _eraseRow(int i);
-
+ virtual void _getColName(int col, std::string & name);
+ virtual void _setColName(int col, const std::string & name);
virtual void _setRowCoeffs(int i,
int length,
const int * indices,
Modified: hugo/trunk/lemon/lp_skeleton.cc
==============================================================================
--- hugo/trunk/lemon/lp_skeleton.cc (original)
+++ hugo/trunk/lemon/lp_skeleton.cc Sat Jan 14 09:44:59 2006
@@ -48,6 +48,14 @@
void LpSkeleton::_eraseRow(int) {
}
+ void LpSkeleton::_getColName(int, std::string &) {
+ }
+
+
+ void LpSkeleton::_setColName(int, const std::string &) {
+ }
+
+
void LpSkeleton::_setRowCoeffs(int,
int,
int const *,
Modified: hugo/trunk/lemon/lp_skeleton.h
==============================================================================
--- hugo/trunk/lemon/lp_skeleton.h (original)
+++ hugo/trunk/lemon/lp_skeleton.h Sat Jan 14 09:44:59 2006
@@ -41,6 +41,11 @@
/// \e
virtual void _eraseRow(int i);
/// \e
+ virtual void _getColName(int col, std::string & name);
+ /// \e
+ virtual void _setColName(int col, const std::string & name);
+
+ /// \e
/// \warning Arrays are indexed from 1 (datum at index 0 is ignored)
///
Modified: hugo/trunk/test/lp_test.cc
==============================================================================
--- hugo/trunk/test/lp_test.cc (original)
+++ hugo/trunk/test/lp_test.cc Sat Jan 14 09:44:59 2006
@@ -27,21 +27,31 @@
std::vector<LP::Col> x(10);
// for(int i=0;i<10;i++) x.push_back(lp.addCol());
lp.addColSet(x);
-
+ lp.colLowerBound(x,1);
+ lp.colUpperBound(x,1);
+ lp.colBounds(x,1,2);
#ifndef GYORSITAS
std::vector<LP::Col> y(10);
lp.addColSet(y);
+ lp.colLowerBound(y,1);
+ lp.colUpperBound(y,1);
+ lp.colBounds(y,1,2);
+
std::map<int,LP::Col> z;
z.insert(std::make_pair(12,INVALID));
z.insert(std::make_pair(2,INVALID));
z.insert(std::make_pair(7,INVALID));
z.insert(std::make_pair(5,INVALID));
-
+
lp.addColSet(z);
+ lp.colLowerBound(z,1);
+ lp.colUpperBound(z,1);
+ lp.colBounds(z,1,2);
+
{
LP::Expr e,f,g;
LP::Col p1,p2,p3,p4,p5;
More information about the Lemon-commits
mailing list