# HG changeset patch # User alpar # Date 1163497766 0 # Node ID 005b3f927287186ddef9b71eb24020c4f57e9a7b # Parent d3c664c975eef0a3a8ca4e2e853316cf09c502dd ColIt added. (Untested, but at least it compiles.) diff -r d3c664c975ee -r 005b3f927287 lemon/lp_base.h --- a/lemon/lp_base.h Mon Nov 13 18:58:39 2006 +0000 +++ b/lemon/lp_base.h Tue Nov 14 09:49:26 2006 +0000 @@ -39,11 +39,12 @@ class _FixId { protected: + int _first_index; + int first_free; + public: std::vector index; std::vector cross; - int first_free; - public: - _FixId() : first_free(-1) {}; + _FixId() : _first_index(-1), first_free(-1) {}; ///Convert a floating id to a fix one ///\param n is a floating id @@ -61,6 +62,7 @@ ///\todo Multiple additions should also be handled. int insert(int n) { + if(cross.empty()) _first_index=n; if(n>=int(cross.size())) { cross.resize(n+1); if(first_free==-1) { @@ -101,6 +103,11 @@ /// std::size_t maxFixId() { return cross.size()-1; } + ///Returns the first (smallest) inserted index + + ///Returns the first (smallest) inserted index + ///or -1 if no index has been inserted before. + int firstIndex() {return _first_index;} }; ///Common base class for LP solvers @@ -109,6 +116,10 @@ ///\ingroup gen_opt_group class LpSolverBase { + protected: + _FixId rows; + _FixId cols; + public: ///Possible outcomes of an LP solving procedure @@ -164,6 +175,10 @@ static inline bool isNaN(const Value& v) { return v!=v; } + friend class Col; + friend class ColIt; + friend class Row; + ///Refer to a column of the LP. ///This type is used to refer to a column of the LP. @@ -189,6 +204,23 @@ bool operator!=(Col c) const {return id!=c.id;} }; + class ColIt : public Col { + LpSolverBase *_lp; + ColIt() {} + ColIt(LpSolverBase &lp) : _lp(&lp) + { + id = _lp->cols.cross.empty()?-1: + _lp->cols.fixId(_lp->cols.firstIndex()); + } + ColIt(const Invalid&) : Col(INVALID) {} + ColIt &operator++() + { + int fid = _lp->cols.floatingId(id)+1; + id = unsigned(fid)<_lp->cols.cross.size() ? _lp->cols.fixId(fid) : -1; + return *this; + } + }; + ///Refer to a row of the LP. ///This type is used to refer to a row of the LP. @@ -564,8 +596,6 @@ protected: - _FixId rows; - _FixId cols; //Abstract virtual functions virtual LpSolverBase &_newLp() = 0; @@ -579,7 +609,7 @@ }; virtual int _addCol() = 0; - virtual int _addRow() = 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;