[Lemon-commits] alpar: r3076 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Tue Nov 14 10:49:27 CET 2006
Author: alpar
Date: Tue Nov 14 10:49:26 2006
New Revision: 3076
Modified:
hugo/trunk/lemon/lp_base.h
Log:
ColIt added. (Untested, but at least it compiles.)
Modified: hugo/trunk/lemon/lp_base.h
==============================================================================
--- hugo/trunk/lemon/lp_base.h (original)
+++ hugo/trunk/lemon/lp_base.h Tue Nov 14 10:49:26 2006
@@ -39,11 +39,12 @@
class _FixId
{
protected:
- std::vector<int> index;
- std::vector<int> cross;
+ int _first_index;
int first_free;
public:
- _FixId() : first_free(-1) {};
+ std::vector<int> index;
+ std::vector<int> cross;
+ _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;
More information about the Lemon-commits
mailing list