ColIt added. (Untested, but at least it compiles.)
authoralpar
Tue, 14 Nov 2006 09:49:26 +0000
changeset 2303005b3f927287
parent 2302 d3c664c975ee
child 2304 108d6db4f32a
ColIt added. (Untested, but at least it compiles.)
lemon/lp_base.h
     1.1 --- a/lemon/lp_base.h	Mon Nov 13 18:58:39 2006 +0000
     1.2 +++ b/lemon/lp_base.h	Tue Nov 14 09:49:26 2006 +0000
     1.3 @@ -39,11 +39,12 @@
     1.4    class _FixId 
     1.5    {
     1.6    protected:
     1.7 +    int _first_index;
     1.8 +    int first_free;
     1.9 +  public:
    1.10      std::vector<int> index;
    1.11      std::vector<int> cross;
    1.12 -    int first_free;
    1.13 -  public:
    1.14 -    _FixId() : first_free(-1) {};
    1.15 +    _FixId() : _first_index(-1), first_free(-1) {};
    1.16      ///Convert a floating id to a fix one
    1.17  
    1.18      ///\param n is a floating id
    1.19 @@ -61,6 +62,7 @@
    1.20      ///\todo Multiple additions should also be handled.
    1.21      int insert(int n)
    1.22      {
    1.23 +      if(cross.empty()) _first_index=n;
    1.24        if(n>=int(cross.size())) {
    1.25  	cross.resize(n+1);
    1.26  	if(first_free==-1) {
    1.27 @@ -101,6 +103,11 @@
    1.28      ///
    1.29      std::size_t maxFixId() { return cross.size()-1; }
    1.30    
    1.31 +    ///Returns the first (smallest) inserted index
    1.32 +
    1.33 +    ///Returns the first (smallest) inserted index
    1.34 +    ///or -1 if no index has been inserted before.
    1.35 +    int firstIndex() {return _first_index;}
    1.36    };
    1.37      
    1.38    ///Common base class for LP solvers
    1.39 @@ -109,6 +116,10 @@
    1.40    ///\ingroup gen_opt_group
    1.41    class LpSolverBase {
    1.42  
    1.43 +  protected:
    1.44 +    _FixId rows;
    1.45 +    _FixId cols;
    1.46 +
    1.47    public:
    1.48  
    1.49      ///Possible outcomes of an LP solving procedure
    1.50 @@ -164,6 +175,10 @@
    1.51  
    1.52      static inline bool isNaN(const Value& v) { return v!=v; }
    1.53      
    1.54 +    friend class Col;
    1.55 +    friend class ColIt;
    1.56 +    friend class Row;
    1.57 +    
    1.58      ///Refer to a column of the LP.
    1.59  
    1.60      ///This type is used to refer to a column of the LP.
    1.61 @@ -189,6 +204,23 @@
    1.62        bool operator!=(Col c) const  {return id!=c.id;}
    1.63      };
    1.64  
    1.65 +    class ColIt : public Col {
    1.66 +      LpSolverBase *_lp;
    1.67 +      ColIt() {}
    1.68 +      ColIt(LpSolverBase &lp) : _lp(&lp)
    1.69 +      {
    1.70 +	id = _lp->cols.cross.empty()?-1:
    1.71 +	  _lp->cols.fixId(_lp->cols.firstIndex());
    1.72 +      }
    1.73 +      ColIt(const Invalid&) : Col(INVALID) {}
    1.74 +      ColIt &operator++() 
    1.75 +      {
    1.76 +	int fid = _lp->cols.floatingId(id)+1;
    1.77 +	id = unsigned(fid)<_lp->cols.cross.size() ? _lp->cols.fixId(fid) : -1;
    1.78 +	return *this;
    1.79 +      }
    1.80 +    };
    1.81 +      
    1.82      ///Refer to a row of the LP.
    1.83  
    1.84      ///This type is used to refer to a row of the LP.
    1.85 @@ -564,8 +596,6 @@
    1.86      
    1.87  
    1.88    protected:
    1.89 -    _FixId rows;
    1.90 -    _FixId cols;
    1.91  
    1.92      //Abstract virtual functions
    1.93      virtual LpSolverBase &_newLp() = 0;
    1.94 @@ -579,7 +609,7 @@
    1.95      };
    1.96  
    1.97      virtual int _addCol() = 0;
    1.98 -    virtual int _addRow() = 0;
    1.99 +    virtual int _addRow() = 0; 
   1.100      virtual void _eraseCol(int col) = 0;
   1.101      virtual void _eraseRow(int row) = 0;
   1.102      virtual void _getColName(int col,       std::string & name) = 0;