# HG changeset patch # User deba # Date 1171653091 0 # Node ID bfbdded3763ae2062ee654ec15a01fc279671c5a # Parent 751a14b992f25d6d60b8334e99f82b687efedd11 Using const in lp interface colByName functionality diff -r 751a14b992f2 -r bfbdded3763a lemon/lp_base.h --- a/lemon/lp_base.h Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/lp_base.h Fri Feb 16 19:11:31 2007 +0000 @@ -135,10 +135,10 @@ }; class ColIt : public Col { - LpSolverBase *_lp; + const LpSolverBase *_lp; public: ColIt() {} - ColIt(LpSolverBase &lp) : _lp(&lp) + ColIt(const LpSolverBase &lp) : _lp(&lp) { _lp->cols.firstFix(id); } @@ -180,10 +180,10 @@ }; class RowIt : public Row { - LpSolverBase *_lp; + const LpSolverBase *_lp; public: RowIt() {} - RowIt(LpSolverBase &lp) : _lp(&lp) + RowIt(const LpSolverBase &lp) : _lp(&lp) { _lp->rows.firstFix(id); } @@ -735,45 +735,47 @@ virtual int _addCol() = 0; 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 _getColName(int col, std::string & name) const = 0; virtual void _setColName(int col, const std::string & name) = 0; + virtual int _colByName(const std::string& name) const = 0; + virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) = 0; - virtual void _getRowCoeffs(int i, RowIterator b) = 0; + virtual void _getRowCoeffs(int i, RowIterator b) const = 0; virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e) = 0; - virtual void _getColCoeffs(int i, ColIterator b) = 0; + virtual void _getColCoeffs(int i, ColIterator b) const = 0; virtual void _setCoeff(int row, int col, Value value) = 0; - virtual Value _getCoeff(int row, int col) = 0; + virtual Value _getCoeff(int row, int col) const = 0; virtual void _setColLowerBound(int i, Value value) = 0; - virtual Value _getColLowerBound(int i) = 0; + virtual Value _getColLowerBound(int i) const = 0; virtual void _setColUpperBound(int i, Value value) = 0; - virtual Value _getColUpperBound(int i) = 0; + virtual Value _getColUpperBound(int i) const = 0; virtual void _setRowBounds(int i, Value lower, Value upper) = 0; - virtual void _getRowBounds(int i, Value &lower, Value &upper)=0; + virtual void _getRowBounds(int i, Value &lower, Value &upper) const = 0; virtual void _setObjCoeff(int i, Value obj_coef) = 0; - virtual Value _getObjCoeff(int i) = 0; + virtual Value _getObjCoeff(int i) const = 0; virtual void _clearObj()=0; virtual SolveExitStatus _solve() = 0; - virtual Value _getPrimal(int i) = 0; - virtual Value _getDual(int i) = 0; - virtual Value _getPrimalValue() = 0; - virtual bool _isBasicCol(int i) = 0; - virtual SolutionStatus _getPrimalStatus() = 0; - virtual SolutionStatus _getDualStatus() = 0; - ///\todo This could be implemented here, too, using _getPrimalStatus() and - ///_getDualStatus() - virtual ProblemTypes _getProblemType() = 0; + virtual Value _getPrimal(int i) const = 0; + virtual Value _getDual(int i) const = 0; + virtual Value _getPrimalValue() const = 0; + virtual bool _isBasicCol(int i) const = 0; + virtual SolutionStatus _getPrimalStatus() const = 0; + virtual SolutionStatus _getDualStatus() const = 0; + virtual ProblemTypes _getProblemType() const = 0; virtual void _setMax() = 0; virtual void _setMin() = 0; - virtual bool _isMax() = 0; + virtual bool _isMax() const = 0; //Own protected stuff @@ -877,7 +879,7 @@ ///\param r is the column to get ///\return the dual expression associated to the column - DualExpr col(Col c) { + DualExpr col(Col c) const { DualExpr e; _getColCoeffs(_lpId(c), ColIterator(std::inserter(e, e.end()), *this)); return e; @@ -974,7 +976,7 @@ ///a better one. ///\todo Option to control whether a constraint with a single variable is ///added or not. - void row(Row r, Value l,const Expr &e, Value u) { + void row(Row r, Value l, const Expr &e, Value u) { e.simplify(); _setRowCoeffs(_lpId(r), ConstRowIterator(e.begin(), *this), ConstRowIterator(e.end(), *this)); @@ -995,7 +997,7 @@ ///\param r is the row to get ///\return the expression associated to the row - Expr row(Row r) { + Expr row(Row r) const { Expr e; _getRowCoeffs(_lpId(r), RowIterator(std::inserter(e, e.end()), *this)); return e; @@ -1045,7 +1047,7 @@ ///\param c is the coresponding coloumn ///\return The name of the colunm - std::string colName(Col c){ + std::string colName(Col c) const { std::string name; _getColName(_lpId(c), name); return name; @@ -1055,7 +1057,7 @@ ///\param c is the coresponding coloumn ///\param name The name to be given - void colName(Col c, const std::string& name){ + void colName(Col c, const std::string& name) { _setColName(_lpId(c), name); } @@ -1065,7 +1067,7 @@ ///\param c is the coloumn of the element to be modified ///\param val is the new value of the coefficient - void coeff(Row r, Col c, Value val){ + void coeff(Row r, Col c, Value val) { _setCoeff(_lpId(r),_lpId(c), val); } @@ -1075,7 +1077,7 @@ ///\param c is the coloumn of the element in question ///\return the corresponding coefficient - Value coeff(Row r, Col c){ + Value coeff(Row r, Col c) const { return _getCoeff(_lpId(r),_lpId(c)); } @@ -1093,7 +1095,7 @@ /// 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) { + Value colLowerBound(Col c) const { return _getColLowerBound(_lpId(c)); } @@ -1148,7 +1150,7 @@ /// 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) { + Value colUpperBound(Col c) const { return _getColUpperBound(_lpId(c)); } @@ -1260,7 +1262,7 @@ /// 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) { + void getRowBounds(Row c, Value &lower, Value &upper) const { _getRowBounds(_lpId(c),lower, upper); } @@ -1268,7 +1270,7 @@ 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)); }; + Value objCoeff(Col c) const { return _getObjCoeff(_lpId(c)); }; ///Set the objective function @@ -1284,7 +1286,7 @@ ///Get the objective function ///\return the objective function as a linear expression of type \ref Expr. - Expr obj() { + Expr obj() const { Expr e; for (ColIt it(*this); it != INVALID; ++it) { double c = objCoeff(it); @@ -1302,10 +1304,10 @@ void min() { _setMin(); } ///Query function: is this a maximization problem? - bool is_max() {return _isMax(); } + bool is_max() const {return _isMax(); } ///Query function: is this a minimization problem? - bool is_min() {return !is_max(); } + bool is_min() const {return !is_max(); } ///@} @@ -1330,28 +1332,28 @@ ///@{ /// The status of the primal problem (the original LP problem) - SolutionStatus primalStatus() { + SolutionStatus primalStatus() const { return _getPrimalStatus(); } /// The status of the dual (of the original LP) problem - SolutionStatus dualStatus() { + SolutionStatus dualStatus() const { return _getDualStatus(); } ///The type of the original LP problem - ProblemTypes problemType() { + ProblemTypes problemType() const { return _getProblemType(); } ///\e - Value primal(Col c) { return _getPrimal(_lpId(c)); } + Value primal(Col c) const { return _getPrimal(_lpId(c)); } ///\e - Value dual(Row r) { return _getDual(_lpId(r)); } + Value dual(Row r) const { return _getDual(_lpId(r)); } ///\e - bool isBasicCol(Col c) { return _isBasicCol(_lpId(c)); } + bool isBasicCol(Col c) const { return _isBasicCol(_lpId(c)); } ///\e @@ -1360,7 +1362,7 @@ /// of the primal problem, depending on whether we minimize or maximize. ///- \ref NaN if no primal solution is found. ///- The (finite) objective value if an optimal solution is found. - Value primalValue() { return _getPrimalValue()+obj_const_comp;} + Value primalValue() const { return _getPrimalValue()+obj_const_comp;} ///@} }; @@ -1394,7 +1396,7 @@ ///Gives back the type of the column. /// ///Gives back the type of the column. - ColTypes colType(Col c){ + ColTypes colType(Col c) const { return _colType(_lpId(c)); } @@ -1412,20 +1414,20 @@ /// ///Gives back the type of the column. ///\return true if the column has integer type and false if not. - bool integer(Col c){ + bool integer(Col c) const { return (colType(c)==INT); } /// The status of the MIP problem - SolutionStatus mipStatus() { + SolutionStatus mipStatus() const { return _getMipStatus(); } protected: - virtual ColTypes _colType(int col) = 0; + virtual ColTypes _colType(int col) const = 0; virtual void _colType(int col, ColTypes col_type) = 0; - virtual SolutionStatus _getMipStatus()=0; + virtual SolutionStatus _getMipStatus() const = 0; }; diff -r 751a14b992f2 -r bfbdded3763a lemon/lp_cplex.cc --- a/lemon/lp_cplex.cc Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/lp_cplex.cc Fri Feb 16 19:11:31 2007 +0000 @@ -84,7 +84,7 @@ CPXdelrows(env, lp, i, i); } - void LpCplex::_getColName(int col, std::string &name) + void LpCplex::_getColName(int col, std::string &name) const { ///\bug Untested int storespace; @@ -107,6 +107,16 @@ ///\bug return code unchecked for error CPXchgcolname(env, lp, 1, &col, names); } + + int LpCplex::_colByName(const std::string& name) const + { + int index; + if (CPXgetcolindex(env, lp, + const_cast(name.c_str()), &index) == 0) { + return index; + } + return -1; + } ///\warning Data at index 0 is ignored in the arrays. void LpCplex::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) @@ -125,7 +135,7 @@ &rowlist[0], &indices[0], &values[0]); } - void LpSoplex::_getRowCoeffs(int i, RowIterator b) { + void LpSoplex::_getRowCoeffs(int i, RowIterator b) const { /// \todo implement } @@ -145,7 +155,7 @@ &indices[0], &collist[0], &values[0]); } - void LpSoplex::_getColCoeffs(int i, ColIterator b) { + void LpSoplex::_getColCoeffs(int i, ColIterator b) const { /// \todo implement } @@ -154,7 +164,7 @@ CPXchgcoef(env, lp, row, col, value); } - LpCplex::Value LpCplex::_getCoeff(int row, int col) + LpCplex::Value LpCplex::_getCoeff(int row, int col) const { LpCplex::Value value; CPXgetcoef(env, lp, row, col, &value); @@ -173,7 +183,7 @@ } - LpCplex::Value LpCplex::_getColLowerBound(int i) + LpCplex::Value LpCplex::_getColLowerBound(int i) const { LpCplex::Value x; CPXgetlb (env, lp, &x, i, i); @@ -191,7 +201,7 @@ status = CPXchgbds(env, lp, 1, indices, lu, bd); } - LpCplex::Value LpCplex::_getColUpperBound(int i) + LpCplex::Value LpCplex::_getColUpperBound(int i) const { LpCplex::Value x; CPXgetub (env, lp, &x, i, i); @@ -270,7 +280,7 @@ // // status = CPXchgcoef(env, lp, i, -2, value_rng); // } - void LpCplex::_getRowBounds(int i, Value &lb, Value &ub) + void LpCplex::_getRowBounds(int i, Value &lb, Value &ub) const { char sense; CPXgetsense(env, lp, &sense,i,i); @@ -302,7 +312,7 @@ CPXchgcoef(env, lp, -1, i, obj_coef); } - LpCplex::Value LpCplex::_getObjCoeff(int i) + LpCplex::Value LpCplex::_getObjCoeff(int i) const { Value x; CPXgetcoef(env, lp, -1, i, &x); @@ -367,21 +377,21 @@ #endif } - LpCplex::Value LpCplex::_getPrimal(int i) + LpCplex::Value LpCplex::_getPrimal(int i) const { Value x; CPXgetx(env, lp, &x, i, i); return x; } - LpCplex::Value LpCplex::_getDual(int i) + LpCplex::Value LpCplex::_getDual(int i) const { Value y; CPXgetpi(env, lp, &y, i, i); return y; } - LpCplex::Value LpCplex::_getPrimalValue() + LpCplex::Value LpCplex::_getPrimalValue() const { Value objval; //method = CPXgetmethod (env, lp); @@ -390,7 +400,8 @@ //printf("Objective value: %g \n",objval); return objval; } - bool LpCplex::_isBasicCol(int i) { + bool LpCplex::_isBasicCol(int i) const + { int cstat[CPXgetnumcols(env, lp)]; CPXgetbase(env, lp, cstat, NULL); return (cstat[i]==CPX_BASIC); @@ -458,7 +469,6 @@ // Default: 0 // Description: Method for linear optimization. // Determines which algorithm is used when CPXlpopt() (or "optimize" in the Interactive Optimizer) is called. Currently the behavior of the "Automatic" setting is that CPLEX simply invokes the dual simplex method, but this capability may be expanded in the future so that CPLEX chooses the method based on problem characteristics - //Hulye cplex void statusSwitch(CPXENVptr env,int& stat){ #if CPX_VERSION < 900 int lpmethod; @@ -475,7 +485,7 @@ #endif } - LpCplex::SolutionStatus LpCplex::_getPrimalStatus() + LpCplex::SolutionStatus LpCplex::_getPrimalStatus() const { //Unboundedness not treated well: the following is from cplex 9.0 doc // About Unboundedness @@ -558,7 +568,7 @@ // CPX_STAT_OPTIMAL_RELAXED // CPX_STAT_UNBOUNDED - LpCplex::SolutionStatus LpCplex::_getDualStatus() + LpCplex::SolutionStatus LpCplex::_getDualStatus() const { int stat = CPXgetstat(env, lp); #if CPX_VERSION >= 800 @@ -587,7 +597,7 @@ #endif } - LpCplex::ProblemTypes LpCplex::_getProblemType() + LpCplex::ProblemTypes LpCplex::_getProblemType() const { int stat = CPXgetstat(env, lp); #if CPX_VERSION >= 800 @@ -627,7 +637,7 @@ CPXchgobjsen(env, lp, CPX_MIN); } - bool LpCplex::_isMax() + bool LpCplex::_isMax() const { if (CPXgetobjsen(env, lp)==CPX_MAX) return true; diff -r 751a14b992f2 -r bfbdded3763a lemon/lp_cplex.h --- a/lemon/lp_cplex.h Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/lp_cplex.h Fri Feb 16 19:11:31 2007 +0000 @@ -60,44 +60,45 @@ virtual int _addRow(); virtual void _eraseCol(int i); virtual void _eraseRow(int i); - virtual void _getColName(int col, std::string & name); + virtual void _getColName(int col, std::string & name) const; virtual void _setColName(int col, const std::string & name); + virtual int _colByName(const std::string& name) const; virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e); - virtual void _getRowCoeffs(int i, RowIterator b); + virtual void _getRowCoeffs(int i, RowIterator b) const; virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e); - virtual void _getColCoeffs(int i, ColIterator b); + virtual void _getColCoeffs(int i, ColIterator b) const; virtual void _setCoeff(int row, int col, Value value); - virtual Value _getCoeff(int row, int col); + virtual Value _getCoeff(int row, int col) const; virtual void _setColLowerBound(int i, Value value); - virtual Value _getColLowerBound(int i); + virtual Value _getColLowerBound(int i) const; virtual void _setColUpperBound(int i, Value value); - virtual Value _getColUpperBound(int i); + virtual Value _getColUpperBound(int i) const; // 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 _getRowBounds(int i, Value &lb, Value &ub) const; virtual void _setObjCoeff(int i, Value obj_coef); - virtual Value _getObjCoeff(int i); + virtual Value _getObjCoeff(int i) const; virtual void _clearObj(); virtual SolveExitStatus _solve(); - virtual Value _getPrimal(int i); - virtual Value _getDual(int i); - virtual Value _getPrimalValue(); - virtual bool _isBasicCol(int i); + virtual Value _getPrimal(int i) const; + virtual Value _getDual(int i) const; + virtual Value _getPrimalValue() const; + virtual bool _isBasicCol(int i) const; - virtual SolutionStatus _getPrimalStatus(); - virtual SolutionStatus _getDualStatus(); - virtual ProblemTypes _getProblemType(); + virtual SolutionStatus _getPrimalStatus() const; + virtual SolutionStatus _getDualStatus() const; + virtual ProblemTypes _getProblemType() const; virtual void _setMax(); virtual void _setMin(); - virtual bool _isMax(); + virtual bool _isMax() const; }; } //END OF NAMESPACE LEMON diff -r 751a14b992f2 -r bfbdded3763a lemon/lp_glpk.cc --- a/lemon/lp_glpk.cc Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/lp_glpk.cc Fri Feb 16 19:11:31 2007 +0000 @@ -37,6 +37,7 @@ rows = _lp_bits::LpId(1); cols = _lp_bits::LpId(1); lp = lpx_create_prob(); + lpx_create_index(lp); ///\todo control function for this: lpx_set_int_parm(lp, LPX_K_DUAL, 1); messageLevel(0); @@ -112,7 +113,7 @@ lpx_del_rows(lp, 1, rows); } - void LpGlpk::_getColName(int col, std::string & name) + void LpGlpk::_getColName(int col, std::string & name) const { char *n = lpx_get_col_name(lp,col); @@ -125,6 +126,13 @@ lpx_set_col_name(lp,col,const_cast(name.c_str())); } + + int LpGlpk::_colByName(const std::string& name) const + { + int k = lpx_find_col(lp, const_cast(name.c_str())); + return k > 0 ? k : -1; + } + void LpGlpk::_setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e) { @@ -142,7 +150,7 @@ lpx_set_mat_row(lp, i, values.size() - 1, &indices[0], &values[0]); } - void LpGlpk::_getRowCoeffs(int i, RowIterator b) + void LpGlpk::_getRowCoeffs(int i, RowIterator b) const { int length = lpx_get_mat_row(lp, i, 0, 0); @@ -173,7 +181,7 @@ lpx_set_mat_col(lp, i, values.size() - 1, &indices[0], &values[0]); } - void LpGlpk::_getColCoeffs(int i, ColIterator b) + void LpGlpk::_getColCoeffs(int i, ColIterator b) const { int length = lpx_get_mat_col(lp, i, 0, 0); @@ -247,7 +255,7 @@ } } - LpGlpk::Value LpGlpk::_getCoeff(int row, int col) + LpGlpk::Value LpGlpk::_getCoeff(int row, int col) const { int length=lpx_get_mat_row(lp, row, 0, 0); @@ -312,7 +320,7 @@ } - LpGlpk::Value LpGlpk::_getColLowerBound(int i) + LpGlpk::Value LpGlpk::_getColLowerBound(int i) const { int b=lpx_get_col_type(lp, i); switch (b) { @@ -369,7 +377,7 @@ } } - LpGlpk::Value LpGlpk::_getColUpperBound(int i) + LpGlpk::Value LpGlpk::_getColUpperBound(int i) const { int b=lpx_get_col_type(lp, i); switch (b) { @@ -414,7 +422,7 @@ } - void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) + void LpGlpk::_getRowBounds(int i, Value &lb, Value &ub) const { int b=lpx_get_row_type(lp, i); @@ -444,7 +452,7 @@ lpx_set_obj_coef(lp, i, obj_coef); } - LpGlpk::Value LpGlpk::_getObjCoeff(int i){ + LpGlpk::Value LpGlpk::_getObjCoeff(int i) const { //i=0 means the constant term (shift) return lpx_get_obj_coef(lp, i); } @@ -472,26 +480,27 @@ } } - LpGlpk::Value LpGlpk::_getPrimal(int i) + LpGlpk::Value LpGlpk::_getPrimal(int i) const { return lpx_get_col_prim(lp,i); } - LpGlpk::Value LpGlpk::_getDual(int i) + LpGlpk::Value LpGlpk::_getDual(int i) const { return lpx_get_row_dual(lp,i); } - LpGlpk::Value LpGlpk::_getPrimalValue() + LpGlpk::Value LpGlpk::_getPrimalValue() const { return lpx_get_obj_val(lp); } - bool LpGlpk::_isBasicCol(int i) { + bool LpGlpk::_isBasicCol(int i) const + { return (lpx_get_col_stat(lp, i)==LPX_BS); } - LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() + LpGlpk::SolutionStatus LpGlpk::_getPrimalStatus() const { int stat= lpx_get_status(lp); switch (stat) { @@ -512,11 +521,8 @@ } } - LpGlpk::SolutionStatus LpGlpk::_getDualStatus() + LpGlpk::SolutionStatus LpGlpk::_getDualStatus() const { -// std::cout<<"Itt megy: "<::const_iterator it = + invColNames.find(name); + if (it != invColNames.end()) { + return it->second; + } else { + return -1; + } } @@ -109,7 +123,7 @@ solved = false; } - void LpSoplex::_getRowCoeffs(int i, RowIterator b) { + void LpSoplex::_getRowCoeffs(int i, RowIterator b) const { const soplex::SVector& vec = soplex->rowVector(i); for (int k = 0; k < vec.size(); ++k) { *b = std::make_pair(vec.index(k), vec.value(k)); @@ -127,7 +141,7 @@ solved = false; } - void LpSoplex::_getColCoeffs(int i, ColIterator b) { + void LpSoplex::_getColCoeffs(int i, ColIterator b) const { const soplex::SVector& vec = soplex->colVector(i); for (int k = 0; k < vec.size(); ++k) { *b = std::make_pair(vec.index(k), vec.value(k)); @@ -140,7 +154,7 @@ solved = false; } - LpSoplex::Value LpSoplex::_getCoeff(int i, int j) { + LpSoplex::Value LpSoplex::_getCoeff(int i, int j) const { return soplex->rowVector(i)[j]; } @@ -149,7 +163,7 @@ solved = false; } - LpSoplex::Value LpSoplex::_getColLowerBound(int i) { + LpSoplex::Value LpSoplex::_getColLowerBound(int i) const { double value = soplex->lower(i); return value != -soplex::infinity ? value : -INF; } @@ -159,7 +173,7 @@ solved = false; } - LpSoplex::Value LpSoplex::_getColUpperBound(int i) { + LpSoplex::Value LpSoplex::_getColUpperBound(int i) const { double value = soplex->upper(i); return value != soplex::infinity ? value : INF; } @@ -169,7 +183,7 @@ ub != INF ? ub : soplex::infinity); solved = false; } - void LpSoplex::_getRowBounds(int i, Value &lower, Value &upper) { + void LpSoplex::_getRowBounds(int i, Value &lower, Value &upper) const { lower = soplex->lhs(i); if (lower == -soplex::infinity) lower = -INF; upper = soplex->rhs(i); @@ -181,7 +195,7 @@ solved = false; } - LpSoplex::Value LpSoplex::_getObjCoeff(int i) { + LpSoplex::Value LpSoplex::_getObjCoeff(int i) const { return soplex->obj(i); } @@ -212,23 +226,23 @@ } } - LpSoplex::Value LpSoplex::_getPrimal(int i) { + LpSoplex::Value LpSoplex::_getPrimal(int i) const { return primal_value[i]; } - LpSoplex::Value LpSoplex::_getDual(int i) { + LpSoplex::Value LpSoplex::_getDual(int i) const { return dual_value[i]; } - LpSoplex::Value LpSoplex::_getPrimalValue() { + LpSoplex::Value LpSoplex::_getPrimalValue() const { return soplex->objValue(); } - bool LpSoplex::_isBasicCol(int i) { + bool LpSoplex::_isBasicCol(int i) const { return soplex->getBasisColStatus(i) == soplex::SPxSolver::BASIC; } - LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() { + LpSoplex::SolutionStatus LpSoplex::_getPrimalStatus() const { if (!solved) return UNDEFINED; switch (soplex->status()) { case soplex::SPxSolver::OPTIMAL: @@ -242,7 +256,7 @@ } } - LpSoplex::SolutionStatus LpSoplex::_getDualStatus() { + LpSoplex::SolutionStatus LpSoplex::_getDualStatus() const { if (!solved) return UNDEFINED; switch (soplex->status()) { case soplex::SPxSolver::OPTIMAL: @@ -254,7 +268,7 @@ } } - LpSoplex::ProblemTypes LpSoplex::_getProblemType() { + LpSoplex::ProblemTypes LpSoplex::_getProblemType() const { if (!solved) return UNKNOWN; switch (soplex->status()) { case soplex::SPxSolver::OPTIMAL: @@ -274,7 +288,7 @@ soplex->changeSense(soplex::SPxSolver::MINIMIZE); solved = false; } - bool LpSoplex::_isMax() { + bool LpSoplex::_isMax() const { return soplex->spxSense() == soplex::SPxSolver::MAXIMIZE; } diff -r 751a14b992f2 -r bfbdded3763a lemon/lp_soplex.h --- a/lemon/lp_soplex.h Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/lp_soplex.h Fri Feb 16 19:11:31 2007 +0000 @@ -34,9 +34,15 @@ namespace lemon { + /// \ingroup gen_opt_group + /// /// \brief Interface for the SOPLEX solver /// - /// This class implements an interface for the SOPLEX LP solver. + /// This class implements an interface for the SoPlex LP solver. + /// The SoPlex library is an object oriented lp solver library + /// developed at the Konrad-Zuse-Zentrum für Informationstechnik + /// Berlin (ZIB). You can find detailed information about it at the + /// http://soplex.zib.de address. class LpSoplex :virtual public LpSolverBase { protected: @@ -46,6 +52,7 @@ bool solved; std::vector colNames; + std::map invColNames; std::vector primal_value; std::vector dual_value; @@ -70,38 +77,39 @@ virtual int _addRow(); virtual void _eraseCol(int i); virtual void _eraseRow(int i); - virtual void _getColName(int col, std::string & name); + virtual void _getColName(int col, std::string & name) const; virtual void _setColName(int col, const std::string & name); + virtual int _colByName(const std::string& name) const; virtual void _setRowCoeffs(int i, ConstRowIterator b, ConstRowIterator e); - virtual void _getRowCoeffs(int i, RowIterator b); + virtual void _getRowCoeffs(int i, RowIterator b) const; virtual void _setColCoeffs(int i, ConstColIterator b, ConstColIterator e); - virtual void _getColCoeffs(int i, ColIterator b); + virtual void _getColCoeffs(int i, ColIterator b) const; virtual void _setCoeff(int row, int col, Value value); - virtual Value _getCoeff(int row, int col); + virtual Value _getCoeff(int row, int col) const; virtual void _setColLowerBound(int i, Value value); - virtual Value _getColLowerBound(int i); + virtual Value _getColLowerBound(int i) const; virtual void _setColUpperBound(int i, Value value); - virtual Value _getColUpperBound(int i); + virtual Value _getColUpperBound(int i) const; virtual void _setRowBounds(int i, Value lower, Value upper); - virtual void _getRowBounds(int i, Value &lower, Value &upper); + virtual void _getRowBounds(int i, Value &lower, Value &upper) const; virtual void _setObjCoeff(int i, Value obj_coef); - virtual Value _getObjCoeff(int i); + virtual Value _getObjCoeff(int i) const; virtual void _clearObj(); virtual SolveExitStatus _solve(); - virtual Value _getPrimal(int i); - virtual Value _getDual(int i); - virtual Value _getPrimalValue(); - virtual bool _isBasicCol(int i); + virtual Value _getPrimal(int i) const; + virtual Value _getDual(int i) const; + virtual Value _getPrimalValue() const; + virtual bool _isBasicCol(int i) const; - virtual SolutionStatus _getPrimalStatus(); - virtual SolutionStatus _getDualStatus(); - virtual ProblemTypes _getProblemType(); + virtual SolutionStatus _getPrimalStatus() const; + virtual SolutionStatus _getDualStatus() const; + virtual ProblemTypes _getProblemType() const; virtual void _setMax(); virtual void _setMin(); - virtual bool _isMax(); + virtual bool _isMax() const; }; } //END OF NAMESPACE LEMON diff -r 751a14b992f2 -r bfbdded3763a lemon/mip_cplex.cc --- a/lemon/mip_cplex.cc Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/mip_cplex.cc Fri Feb 16 19:11:31 2007 +0000 @@ -58,7 +58,7 @@ CPXchgctype (env, lp, 1, indices, ctype); } - MipCplex::ColTypes MipCplex::_colType(int i){ + MipCplex::ColTypes MipCplex::_colType(int i) const { char ctype[1]; status = CPXgetctype (env, lp, ctype, i, i); @@ -85,7 +85,7 @@ } - LpCplex::SolutionStatus MipCplex::_getMipStatus(){ + LpCplex::SolutionStatus MipCplex::_getMipStatus() const { int stat = CPXgetstat(env, lp); @@ -119,13 +119,13 @@ } - MipCplex::Value MipCplex::_getPrimal(int i){ + MipCplex::Value MipCplex::_getPrimal(int i) const { Value x; CPXgetmipx(env, lp, &x, i, i); return x; } - MipCplex::Value MipCplex::_getPrimalValue(){ + MipCplex::Value MipCplex::_getPrimalValue() const { Value objval; status = CPXgetmipobjval(env, lp, &objval); return objval; diff -r 751a14b992f2 -r bfbdded3763a lemon/mip_cplex.h --- a/lemon/mip_cplex.h Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/mip_cplex.h Fri Feb 16 19:11:31 2007 +0000 @@ -47,13 +47,13 @@ protected: - virtual ColTypes _colType(int col); + virtual ColTypes _colType(int col) const; virtual void _colType(int col, ColTypes col_type); virtual LpCplex::SolveExitStatus _solve(); - virtual LpCplex::SolutionStatus _getMipStatus(); - virtual ParentLp::Value _getPrimal(int i); - virtual ParentLp::Value _getPrimalValue(); + virtual LpCplex::SolutionStatus _getMipStatus() const; + virtual ParentLp::Value _getPrimal(int i) const; + virtual ParentLp::Value _getPrimalValue() const; }; } //END OF NAMESPACE LEMON diff -r 751a14b992f2 -r bfbdded3763a lemon/mip_glpk.cc --- a/lemon/mip_glpk.cc Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/mip_glpk.cc Fri Feb 16 19:11:31 2007 +0000 @@ -40,7 +40,7 @@ } } - MipGlpk::ColTypes MipGlpk::_colType(int i){ + MipGlpk::ColTypes MipGlpk::_colType(int i) const { switch (lpx_get_col_kind(lp,i)){ case LPX_IV: return INT;//Or binary @@ -52,7 +52,7 @@ } - LpGlpk::SolveExitStatus MipGlpk::_solve(){ + LpGlpk::SolveExitStatus MipGlpk::_solve() { int result = lpx_simplex(lp); // if (lpx_get_status(lp)==LPX_OPT){ @@ -71,7 +71,7 @@ } - LpGlpk::SolutionStatus MipGlpk::_getMipStatus(){ + LpGlpk::SolutionStatus MipGlpk::_getMipStatus() const { if (lpx_get_status(lp)==LPX_OPT){ //Meg kell nezni: ha az LP is infinite, akkor ez is, ha az is @@ -100,11 +100,11 @@ } - MipGlpk::Value MipGlpk::_getPrimal(int i){ + MipGlpk::Value MipGlpk::_getPrimal(int i) const { return lpx_mip_col_val(lp,i); } - MipGlpk::Value MipGlpk::_getPrimalValue(){ + MipGlpk::Value MipGlpk::_getPrimalValue() const { return lpx_mip_obj_val(lp); } } //END OF NAMESPACE LEMON diff -r 751a14b992f2 -r bfbdded3763a lemon/mip_glpk.h --- a/lemon/mip_glpk.h Fri Feb 16 15:57:48 2007 +0000 +++ b/lemon/mip_glpk.h Fri Feb 16 19:11:31 2007 +0000 @@ -45,13 +45,13 @@ protected: - virtual ColTypes _colType(int col); + virtual ColTypes _colType(int col) const; virtual void _colType(int col, ColTypes col_type); virtual LpGlpk::SolveExitStatus _solve(); - virtual LpGlpk::SolutionStatus _getMipStatus(); - virtual ParentLp::Value _getPrimal(int i); - virtual ParentLp::Value _getPrimalValue(); + virtual LpGlpk::SolutionStatus _getMipStatus() const; + virtual ParentLp::Value _getPrimal(int i) const; + virtual ParentLp::Value _getPrimalValue() const; }; } //END OF NAMESPACE LEMON