diff -r eb37b9774ef6 -r 2aabce558574 lemon/lp_base.h --- a/lemon/lp_base.h Thu Feb 15 13:06:23 2007 +0000 +++ b/lemon/lp_base.h Thu Feb 15 14:22:08 2007 +0000 @@ -27,93 +27,16 @@ #include #include -#include #include #include +#include +#include ///\file ///\brief The interface of the LP solver interface. ///\ingroup gen_opt_group namespace lemon { - - ///Internal data structure to convert floating id's to fix one's - - ///\todo This might be implemented to be also usable in other places. - class _FixId - { - protected: - int _first_index; - int first_free; - public: - std::vector index; - std::vector cross; - _FixId() : _first_index(-1), first_free(-1) {}; - ///Convert a floating id to a fix one - - ///\param n is a floating id - ///\return the corresponding fix id - int fixId(int n) const {return cross[n];} - ///Convert a fix id to a floating one - - ///\param n is a fix id - ///\return the corresponding floating id - int floatingId(int n) const { return index[n];} - ///Add a new floating id. - - ///\param n is a floating id - ///\return the fix id of the new value - ///\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) { - cross[n]=index.size(); - index.push_back(n); - } - else { - cross[n]=first_free; - int next=index[first_free]; - index[first_free]=n; - first_free=next; - } - return cross[n]; - } - else { - ///\todo Create an own exception type. - throw LogicError(); //floatingId-s must form a continuous range; - } - } - ///Remove a fix id. - - ///\param n is a fix id - /// - void erase(int n) - { - int fl=index[n]; - index[n]=first_free; - first_free=n; - for(int i=fl+1;icols.cross.empty()?-1: - _lp->cols.fixId(_lp->cols.firstIndex()); + _lp->cols.firstFix(id); } 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; + _lp->cols.nextFix(id); return *this; } }; @@ -746,8 +668,6 @@ virtual Value _getColLowerBound(int i) = 0; virtual void _setColUpperBound(int i, Value value) = 0; virtual Value _getColUpperBound(int i) = 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 _getRowBounds(int i, Value &lower, Value &upper)=0; @@ -795,7 +715,7 @@ ///@{ ///Add a new empty column (i.e a new variable) to the LP - Col addCol() { Col c; c.id=cols.insert(_addCol()); return c;} + Col addCol() { Col c; _addCol(); c.id = cols.addId(); return c;} ///\brief Adds several new columns ///(i.e a variables) at once @@ -887,7 +807,7 @@ ///This function adds a new empty row (i.e a new constraint) to the LP. ///\return The created row - Row addRow() { Row r; r.id=rows.insert(_addRow()); return r;} + Row addRow() { Row r; _addRow(); r.id = rows.addId(); return r;} ///\brief Add several new rows ///(i.e a constraints) at once @@ -965,8 +885,6 @@ e.simplify(); _setRowCoeffs(_lpId(r), LpRowIterator(e.begin(), *this), LpRowIterator(e.end(), *this)); -// _setRowLowerBound(_lpId(r),l-e.constComp()); -// _setRowUpperBound(_lpId(r),u-e.constComp()); _setRowBounds(_lpId(r),l-e.constComp(),u-e.constComp()); } @@ -1008,7 +926,7 @@ ///\todo Please check this void eraseCol(Col c) { _eraseCol(_lpId(c)); - cols.erase(c.id); + cols.eraseId(c.id); } ///Erase a row (i.e a constraint) from the LP @@ -1016,7 +934,7 @@ ///\todo Please check this void eraseRow(Row r) { _eraseRow(_lpId(r)); - rows.erase(r.id); + rows.eraseId(r.id); } /// Get the name of a column @@ -1216,31 +1134,14 @@ } #endif -// /// Set the lower bound of a row (i.e a constraint) - -// /// The lower bound of a linear expression (row) has to be given by an -// /// extended number of type Value, i.e. a finite number of type -// /// Value or -\ref INF. -// void rowLowerBound(Row r, Value value) { -// _setRowLowerBound(_lpId(r),value); -// }; -// /// Set the upper bound of a row (i.e a constraint) - -// /// The upper bound of a linear expression (row) has to be given by an -// /// extended number of type Value, i.e. a finite number of type -// /// Value or \ref INF. -// void rowUpperBound(Row r, Value value) { -// _setRowUpperBound(_lpId(r),value); -// }; /// Set the lower and the upper bounds of a row (i.e a constraint) - /// The lower and the upper bound of - /// a constraint (row) have to be given by an - /// extended number of type Value, i.e. a finite number of type - /// Value, -\ref INF or \ref INF. There is no separate function for the - /// lower and the upper bound because that would have been hard to implement - /// for CPLEX. + /// The lower and the upper bound of a constraint (row) have to be + /// given by an extended number of type Value, i.e. a finite + /// number of type Value, -\ref INF or \ref INF. There is no + /// separate function for the lower and the upper bound because + /// that would have been hard to implement for CPLEX. void rowBounds(Row c, Value lower, Value upper) { _setRowBounds(_lpId(c),lower, upper); }