[Lemon-commits] athos: r3100 - in hugo/trunk: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Dec 4 17:48:24 CET 2006
Author: athos
Date: Mon Dec 4 17:48:13 2006
New Revision: 3100
Modified:
hugo/trunk/lemon/lp_base.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:
Some query functions got implemented, but only for GLPK.
Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h (original)
+++ hugo/trunk/lemon/lp_base.h Mon Dec 4 17:48:13 2006
@@ -703,12 +703,15 @@
virtual void _setRowCoeffs(int i, LpRowIterator b, LpRowIterator e) = 0;
virtual void _setColCoeffs(int i, LpColIterator b, LpColIterator e) = 0;
virtual void _setCoeff(int row, int col, Value value) = 0;
+ virtual Value _getCoeff(int row, int col) = 0;
+
virtual void _setColLowerBound(int i, Value value) = 0;
virtual void _setColUpperBound(int i, Value value) = 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 _setObjCoeff(int i, Value obj_coef) = 0;
+ virtual Value _getObjCoeff(int i) = 0;
virtual void _clearObj()=0;
virtual SolveExitStatus _solve() = 0;
@@ -725,6 +728,9 @@
virtual void _setMax() = 0;
virtual void _setMin() = 0;
+
+ virtual bool _isMax() = 0;
+
//Own protected stuff
//Constant component of the objective function
@@ -1000,6 +1006,16 @@
_setCoeff(_lpId(r),_lpId(c), val);
}
+ /// Get an element of the coefficient matrix of the LP
+
+ ///\param r is the row of the element in question
+ ///\param c is the coloumn of the element in question
+ ///\return the corresponding coefficient
+
+ Value coeff(Row r, Col c){
+ return _getCoeff(_lpId(r),_lpId(c));
+ }
+
/// Set the lower bound of a column (i.e a variable)
/// The lower bound of a variable (column) has to be given by an
@@ -1171,8 +1187,12 @@
///Set an element of the objective function
void objCoeff(Col c, Value v) {_setObjCoeff(_lpId(c),v); };
+
+ ///Get an element of the objective function
+ Value objCoeff(Col c) {return _getObjCoeff(_lpId(c)); };
+
///Set the objective function
-
+
///\param e is a linear expression of type \ref Expr.
///\bug Is should be called obj()
void setObj(Expr e) {
@@ -1187,6 +1207,11 @@
///Minimize
void min() { _setMin(); }
+ ///Query function: is this a maximization problem?
+ bool is_max() {return _isMax(); }
+
+ ///Query function: is this a minimization problem?
+ bool is_min() {return !is_max(); }
///@}
Modified: hugo/trunk/lemon/lp_glpk.cc
==============================================================================
--- hugo/trunk/lemon/lp_glpk.cc (original)
+++ hugo/trunk/lemon/lp_glpk.cc Mon Dec 4 17:48:13 2006
@@ -213,6 +213,13 @@
}
}
+ LpGlpk::Value LpGlpk::_getCoeff(int row, int col)
+ {
+ ///\todo This is not yet implemented!!!
+ return 0;
+ }
+
+
void LpGlpk::_setColLowerBound(int i, Value lo)
{
if (lo==INF) {
@@ -424,6 +431,11 @@
lpx_set_obj_coef(lp, i, obj_coef);
}
+ LpGlpk::Value LpGlpk::_getObjCoeff(int i){
+ //i=0 means the constant term (shift)
+ return lpx_get_obj_coef(lp, i);
+ }
+
void LpGlpk::_clearObj()
{
for (int i=0;i<=lpx_get_num_cols(lp);++i){
@@ -551,7 +563,13 @@
lpx_set_obj_dir(lp, LPX_MIN);
}
+ bool LpGlpk::_isMax()
+ {
+ return (lpx_get_obj_dir(lp)==LPX_MAX);
+ }
+
+
void LpGlpk::messageLevel(int m)
{
lpx_set_int_parm(lp, LPX_K_MSGLEV, m);
Modified: hugo/trunk/lemon/lp_glpk.h
==============================================================================
--- hugo/trunk/lemon/lp_glpk.h (original)
+++ hugo/trunk/lemon/lp_glpk.h Mon Dec 4 17:48:13 2006
@@ -60,12 +60,15 @@
virtual void _setRowCoeffs(int i, LpRowIterator b, LpRowIterator e);
virtual void _setColCoeffs(int i, LpColIterator b, LpColIterator e);
virtual void _setCoeff(int row, int col, Value value);
+ virtual Value _getCoeff(int row, int col);
+
virtual void _setColLowerBound(int i, Value value);
virtual void _setColUpperBound(int i, Value value);
// 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 _setObjCoeff(int i, Value obj_coef);
+ virtual Value _getObjCoeff(int i);
virtual void _clearObj();
// virtual void _setObj(int length,
// int const * indices,
@@ -91,6 +94,8 @@
virtual void _setMax();
virtual void _setMin();
+ virtual bool _isMax();
+
public:
///Set the verbosity of the messages
Modified: hugo/trunk/lemon/lp_skeleton.cc
==============================================================================
--- hugo/trunk/lemon/lp_skeleton.cc (original)
+++ hugo/trunk/lemon/lp_skeleton.cc Mon Dec 4 17:48:13 2006
@@ -68,6 +68,11 @@
{
}
+ LpSkeleton::Value LpSkeleton::_getCoeff(int, int)
+ {
+ return 0;
+ }
+
void LpSkeleton::_setColLowerBound(int, Value)
{
@@ -93,6 +98,10 @@
{
}
+ LpSkeleton::Value LpSkeleton::_getObjCoeff(int i){
+ return 0;
+ }
+
void LpSkeleton::_setMax()
{
}
@@ -101,6 +110,12 @@
{
}
+ bool LpSkeleton::_isMax()
+ {
+ return true;
+ }
+
+
void LpSkeleton::_clearObj()
{
}
Modified: hugo/trunk/lemon/lp_skeleton.h
==============================================================================
--- hugo/trunk/lemon/lp_skeleton.h (original)
+++ hugo/trunk/lemon/lp_skeleton.h Mon Dec 4 17:48:13 2006
@@ -55,6 +55,9 @@
/// Set one element of the coefficient matrix
virtual void _setCoeff(int row, int col, Value value);
+ /// Get one element of the coefficient matrix
+ virtual Value _getCoeff(int row, int col);
+
/// The lower 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.
@@ -91,6 +94,9 @@
/// \e
virtual void _setObjCoeff(int i, Value obj_coef);
+ /// \e
+ virtual Value _getObjCoeff(int i);
+
///\e
///\bug Wrong interface
@@ -134,6 +140,11 @@
virtual void _setMin();
///\e
+ virtual bool _isMax();
+
+
+
+ ///\e
virtual bool _isBasicCol(int i);
Modified: hugo/trunk/test/lp_test.cc
==============================================================================
--- hugo/trunk/test/lp_test.cc (original)
+++ hugo/trunk/test/lp_test.cc Mon Dec 4 17:48:13 2006
@@ -293,6 +293,13 @@
lp.max();
+
+ //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)==1,"The coefficient in question is 1!");
+
+
//Maximization of x1+x2
//over the triangle with vertices (0,0) (0,1) (1,0)
double expected_opt=1;
More information about the Lemon-commits
mailing list