[Lemon-commits] athos: r3104 - in hugo/trunk: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Thu Dec 7 17:10:55 CET 2006
Author: athos
Date: Thu Dec 7 17:10:54 2006
New Revision: 3104
Modified:
hugo/trunk/lemon/lp_base.h
hugo/trunk/lemon/lp_cplex.cc
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:
Query functions have been implemented for GLPK (CPLEX breaks at the moment, I guess): These functions include:
retrieving one element of the coeff. matrix
retrieving one element of the obj function
lower bd for a variable
upper bound for a variable
lower and upper bounds for a row (these can not be handled separately at the moment)
direction of the optimization (is_max() function)
Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h (original)
+++ hugo/trunk/lemon/lp_base.h Thu Dec 7 17:10:54 2006
@@ -706,10 +706,14 @@
virtual Value _getCoeff(int row, int col) = 0;
virtual void _setColLowerBound(int i, Value value) = 0;
+ virtual Value _getColLowerBound(int i) = 0;
virtual void _setColUpperBound(int i, Value value) = 0;
+ virtual Value _getColUpperBound(int i) = 0;
// virtual void _setRowLowerBound(int i, Value value) = 0;
// virtual void _setRowUpperBound(int i, Value value) = 0;
virtual void _setRowBounds(int i, Value lower, Value upper) = 0;
+ virtual void _getRowBounds(int i, Value &lower, Value &upper)=0;
+
virtual void _setObjCoeff(int i, Value obj_coef) = 0;
virtual Value _getObjCoeff(int i) = 0;
virtual void _clearObj()=0;
@@ -1024,6 +1028,15 @@
void colLowerBound(Col c, Value value) {
_setColLowerBound(_lpId(c),value);
}
+
+ /// Get the lower bound of a column (i.e a variable)
+
+ /// This function returns the lower bound for column (variable) \t c
+ /// (this might be -\ref INF as well).
+ ///\return The lower bound for coloumn \t c
+ Value colLowerBound(Col c) {
+ return _getColLowerBound(_lpId(c));
+ }
///\brief Set the lower bound of several columns
///(i.e a variables) at once
@@ -1071,7 +1084,16 @@
_setColUpperBound(_lpId(c),value);
};
- ///\brief Set the lower bound of several columns
+ /// Get the upper bound of a column (i.e a variable)
+
+ /// This function returns the upper bound for column (variable) \t c
+ /// (this might be \ref INF as well).
+ ///\return The upper bound for coloumn \t c
+ Value colUpperBound(Col c) {
+ return _getColUpperBound(_lpId(c));
+ }
+
+ ///\brief Set the upper bound of several columns
///(i.e a variables) at once
///
///This magic function takes a container as its argument
@@ -1176,15 +1198,30 @@
/// Set the lower and the upper bounds of a row (i.e a constraint)
- /// The lower and the upper bounds of
+ /// The lower and the upper bound of
/// a constraint (row) have to be given by an
/// extended number of type Value, i.e. a finite number of type
- /// Value, -\ref INF or \ref INF.
+ /// Value, -\ref INF or \ref INF. There is no separate function for the
+ /// lower and the upper bound because that would have been hard to implement
+ /// for CPLEX.
void rowBounds(Row c, Value lower, Value upper) {
_setRowBounds(_lpId(c),lower, upper);
- // _setRowUpperBound(_lpId(c),upper);
}
+ /// Get the lower and the upper bounds of a row (i.e a constraint)
+
+ /// The lower and the upper bound of
+ /// a constraint (row) are
+ /// extended numbers of type Value, i.e. finite numbers of type
+ /// Value, -\ref INF or \ref INF.
+ /// \todo There is no separate function for the
+ /// lower and the upper bound because we had problems with the
+ /// implementation of the setting functions for CPLEX:
+ /// check out whether this can be done for these functions.
+ void getRowBounds(Row c, Value &lower, Value &upper) {
+ _getRowBounds(_lpId(c),lower, upper);
+ }
+
///Set an element of the objective function
void objCoeff(Col c, Value v) {_setObjCoeff(_lpId(c),v); };
Modified: hugo/trunk/lemon/lp_cplex.cc
==============================================================================
--- hugo/trunk/lemon/lp_cplex.cc (original)
+++ hugo/trunk/lemon/lp_cplex.cc Thu Dec 7 17:10:54 2006
@@ -43,6 +43,7 @@
}
LpSolverBase &LpCplex::_copyLp() {
+ ///\bug FixID data is not copied!
//The first approach opens a new environment
LpCplex* newlp=new LpCplex();
//The routine CPXcloneprob can be used to create a new CPLEX problem
Modified: hugo/trunk/lemon/lp_glpk.cc
==============================================================================
--- hugo/trunk/lemon/lp_glpk.cc (original)
+++ hugo/trunk/lemon/lp_glpk.cc Thu Dec 7 17:10:54 2006
@@ -213,10 +213,25 @@
}
}
- LpGlpk::Value LpGlpk::_getCoeff(int, int)
+ LpGlpk::Value LpGlpk::_getCoeff(int row, int col)
{
- ///\todo This is not yet implemented!!!
+
+ int length=lpx_get_mat_row(lp, row, 0, 0);
+
+ std::vector<int> indices(length + 2);
+ std::vector<Value> values(length + 2);
+
+ lpx_get_mat_row(lp, row, &indices[0], &values[0]);
+
+ //The following code does not suppose that the elements of the
+ //array indices are sorted
+ for (int i = 1; i <= length; ++i) {
+ if (indices[i]==col){
+ return values[i];
+ }
+ }
return 0;
+
}
@@ -262,6 +277,19 @@
}
}
+
+ LpGlpk::Value LpGlpk::_getColLowerBound(int i)
+ {
+ int b=lpx_get_col_type(lp, i);
+ switch (b) {
+ case LPX_LO:
+ case LPX_DB:
+ case LPX_FX:
+ return lpx_get_col_lb(lp, i);
+ default: ;
+ return -INF;
+ }
+ }
void LpGlpk::_setColUpperBound(int i, Value up)
{
@@ -306,6 +334,19 @@
}
}
}
+
+ LpGlpk::Value LpGlpk::_getColUpperBound(int i)
+ {
+ int b=lpx_get_col_type(lp, i);
+ switch (b) {
+ case LPX_UP:
+ case LPX_DB:
+ case LPX_FX:
+ return lpx_get_col_ub(lp, i);
+ default: ;
+ return INF;
+ }
+ }
// void LpGlpk::_setRowLowerBound(int i, Value lo)
// {
@@ -424,6 +465,30 @@
}
}
+
+ void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub)
+ {
+
+ int b=lpx_get_row_type(lp, i);
+ switch (b) {
+ case LPX_FR:
+ case LPX_UP:
+ lb = -INF;
+ break;
+ default:
+ lb=lpx_get_row_lb(lp, i);
+ }
+
+ switch (b) {
+ case LPX_FR:
+ case LPX_LO:
+ ub = INF;
+ break;
+ default:
+ ub=lpx_get_row_ub(lp, i);
+ }
+
+ }
void LpGlpk::_setObjCoeff(int i, Value obj_coef)
{
Modified: hugo/trunk/lemon/lp_glpk.h
==============================================================================
--- hugo/trunk/lemon/lp_glpk.h (original)
+++ hugo/trunk/lemon/lp_glpk.h Thu Dec 7 17:10:54 2006
@@ -63,10 +63,14 @@
virtual Value _getCoeff(int row, int col);
virtual void _setColLowerBound(int i, Value value);
+ virtual Value _getColLowerBound(int i);
virtual void _setColUpperBound(int i, Value value);
+ virtual Value _getColUpperBound(int i);
+
// virtual void _setRowLowerBound(int i, Value value);
// virtual void _setRowUpperBound(int i, Value value);
virtual void _setRowBounds(int i, Value lower, Value upper);
+ virtual void _getRowBounds(int i, Value &lb, Value &ub);
virtual void _setObjCoeff(int i, Value obj_coef);
virtual Value _getObjCoeff(int i);
virtual void _clearObj();
Modified: hugo/trunk/lemon/lp_skeleton.cc
==============================================================================
--- hugo/trunk/lemon/lp_skeleton.cc (original)
+++ hugo/trunk/lemon/lp_skeleton.cc Thu Dec 7 17:10:54 2006
@@ -78,9 +78,19 @@
{
}
+ LpSkeleton::Value LpSkeleton::_getColLowerBound(int)
+ {
+ return 0;
+ }
+
void LpSkeleton::_setColUpperBound(int, Value)
{
}
+
+ LpSkeleton::Value LpSkeleton::_getColUpperBound(int)
+ {
+ return 0;
+ }
// void LpSkeleton::_setRowLowerBound(int, Value)
// {
@@ -93,6 +103,10 @@
void LpSkeleton::_setRowBounds(int, Value, Value)
{
}
+
+ void LpSkeleton::_getRowBounds(int, Value&, Value&)
+ {
+ }
void LpSkeleton::_setObjCoeff(int, Value)
{
Modified: hugo/trunk/lemon/lp_skeleton.h
==============================================================================
--- hugo/trunk/lemon/lp_skeleton.h (original)
+++ hugo/trunk/lemon/lp_skeleton.h Thu Dec 7 17:10:54 2006
@@ -64,12 +64,22 @@
virtual void _setColLowerBound(int i, Value value);
/// \e
+ /// The lower bound of a variable (column) is an
+ /// extended number of type Value, i.e. a finite number of type
+ /// Value or -\ref INF.
+ virtual Value _getColLowerBound(int i);
+
/// The upper bound of a variable (column) have to be given by an
/// extended number of type Value, i.e. a finite number of type
/// Value or \ref INF.
virtual void _setColUpperBound(int i, Value value);
/// \e
+ /// The upper bound of a variable (column) is an
+ /// extended number of type Value, i.e. a finite number of type
+ /// Value or \ref INF.
+ virtual Value _getColUpperBound(int i);
+
// /// The lower bound of a linear expression (row) have to be given by an
// /// extended number of type Value, i.e. a finite number of type
// /// Value or -\ref INF.
@@ -89,6 +99,14 @@
/// \e
+ /// The lower and the upper bound of
+ /// a constraint (row) are
+ /// extended numbers of type Value, i.e. finite numbers of type
+ /// Value, -\ref INF or \ref INF.
+ virtual void _getRowBounds(int i, Value &lb, Value &ub);
+ /// \e
+
+
/// \e
virtual void _clearObj();
/// \e
Modified: hugo/trunk/test/lp_test.cc
==============================================================================
--- hugo/trunk/test/lp_test.cc (original)
+++ hugo/trunk/test/lp_test.cc Thu Dec 7 17:10:54 2006
@@ -297,7 +297,14 @@
//Testing the problem retrieving routines
check(lp.objCoeff(x1)==1,"First term should be 1 in the obj function!");
check(lp.is_max(),"This is a maximization!");
- check(lp.coeff(upright,x1)==0,"The coefficient in question is 1!");
+ check(lp.coeff(upright,x1)==1,"The coefficient in question is 1!");
+ // std::cout<<lp.colLowerBound(x1)<<std::endl;
+ check( lp.colLowerBound(x1)==0,"The lower bound for variable x1 should be 0.");
+ check( lp.colUpperBound(x1)==LpSolverBase::INF,"The upper bound for variable x1 should be infty.");
+ LpSolverBase::Value lb,ub;
+ lp.getRowBounds(upright,lb,ub);
+ check( lb==-LpSolverBase::INF,"The lower bound for the first row should be -infty.");
+ check( ub==1,"The upper bound for the first row should be 1.");
//Maximization of x1+x2
More information about the Lemon-commits
mailing list