diff -r 4fb22cfa5759 -r 1cfabf245433 src/work/marci/lp/lp_solver_base.h --- a/src/work/marci/lp/lp_solver_base.h Tue Feb 08 17:47:19 2005 +0000 +++ b/src/work/marci/lp/lp_solver_base.h Thu Feb 10 18:53:30 2005 +0000 @@ -193,18 +193,18 @@ /// \e typedef _Value Value; /// \e - typedef IterablePartition::ClassIt RowIt; + typedef IterablePartition::ClassIt Row; /// \e - typedef IterablePartition::ClassIt ColIt; + typedef IterablePartition::ClassIt Col; public: /// \e IterablePartition row_iter_map; /// \e IterablePartition col_iter_map; /// \e - std::vector int_row_map; + std::vector int_row_map; /// \e - std::vector int_col_map; + std::vector int_col_map; /// \e const int VALID_CLASS; /// \e @@ -271,12 +271,12 @@ virtual int getDualStatus() = 0; /// \e virtual void printDualStatus(int i) = 0; - /// Returns the status of the slack variable assigned to row \c row_it. - virtual int getRowStat(const RowIt& row_it) = 0; + /// Returns the status of the slack variable assigned to row \c row. + virtual int getRowStat(const Row& row) = 0; /// \e virtual void printRowStatus(int i) = 0; - /// Returns the status of the variable assigned to column \c col_it. - virtual int getColStat(const ColIt& col_it) = 0; + /// Returns the status of the variable assigned to column \c col. + virtual int getColStat(const Col& col) = 0; /// \e virtual void printColStatus(int i) = 0; @@ -375,41 +375,41 @@ //MATRIX MANIPULATING FUNCTIONS /// \e - ColIt addCol() { + Col addCol() { int i=_addCol(); - ColIt col_it; - col_iter_map.first(col_it, INVALID_CLASS); - if (col_iter_map.valid(col_it)) { //van hasznalhato hely - col_iter_map.set(col_it, INVALID_CLASS, VALID_CLASS); - col_iter_map[col_it]=i; + Col col; + col_iter_map.first(col, INVALID_CLASS); + if (col_iter_map.valid(col)) { //van hasznalhato hely + col_iter_map.set(col, INVALID_CLASS, VALID_CLASS); + col_iter_map[col]=i; } else { //a cucc vegere kell inzertalni mert nincs szabad hely - col_it=col_iter_map.push_back(i, VALID_CLASS); + col=col_iter_map.push_back(i, VALID_CLASS); } - int_col_map.push_back(col_it); - return col_it; + int_col_map.push_back(col); + return col; } /// \e - RowIt addRow() { + Row addRow() { int i=_addRow(); - RowIt row_it; - row_iter_map.first(row_it, INVALID_CLASS); - if (row_iter_map.valid(row_it)) { //van hasznalhato hely - row_iter_map.set(row_it, INVALID_CLASS, VALID_CLASS); - row_iter_map[row_it]=i; + Row row; + row_iter_map.first(row, INVALID_CLASS); + if (row_iter_map.valid(row)) { //van hasznalhato hely + row_iter_map.set(row, INVALID_CLASS, VALID_CLASS); + row_iter_map[row]=i; } else { //a cucc vegere kell inzertalni mert nincs szabad hely - row_it=row_iter_map.push_back(i, VALID_CLASS); + row=row_iter_map.push_back(i, VALID_CLASS); } - int_row_map.push_back(row_it); - return row_it; + int_row_map.push_back(row); + return row; } /// \e - void eraseCol(const ColIt& col_it) { - col_iter_map.set(col_it, VALID_CLASS, INVALID_CLASS); + void eraseCol(const Col& col) { + col_iter_map.set(col, VALID_CLASS, INVALID_CLASS); int cols[2]; - cols[1]=col_iter_map[col_it]; + cols[1]=col_iter_map[col]; _eraseCol(cols[1]); - col_iter_map[col_it]=0; //glpk specifikus, de kell ez?? - ColIt it; + col_iter_map[col]=0; //glpk specifikus, de kell ez?? + Col it; for (col_iter_map.first(it, VALID_CLASS); col_iter_map.valid(it); col_iter_map.next(it)) { if (col_iter_map[it]>cols[1]) --col_iter_map[it]; @@ -417,13 +417,13 @@ int_col_map.erase(int_col_map.begin()+cols[1]); } /// \e - void eraseRow(const RowIt& row_it) { - row_iter_map.set(row_it, VALID_CLASS, INVALID_CLASS); + void eraseRow(const Row& row) { + row_iter_map.set(row, VALID_CLASS, INVALID_CLASS); int rows[2]; - rows[1]=row_iter_map[row_it]; + rows[1]=row_iter_map[row]; _eraseRow(rows[1]); - row_iter_map[row_it]=0; //glpk specifikus, de kell ez?? - RowIt it; + row_iter_map[row]=0; //glpk specifikus, de kell ez?? + Row it; for (row_iter_map.first(it, VALID_CLASS); row_iter_map.valid(it); row_iter_map.next(it)) { if (row_iter_map[it]>rows[1]) --row_iter_map[it]; @@ -431,71 +431,51 @@ int_row_map.erase(int_row_map.begin()+rows[1]); } /// \e - template - void setRowCoeffs(RowIt row_it, Begin begin, End end) { - std::vector > coeffs; - for ( ; begin!=end; ++begin) { - coeffs.push_back(std:: - make_pair(col_iter_map[begin->first], begin->second)); - } - _setRowCoeffs(row_iter_map[row_it], coeffs); + void setColLowerBound(Col col, _Value lo) { + _setColLowerBound(col_iter_map[col], lo); } /// \e - template - void setColCoeffs(ColIt col_it, Begin begin, End end) { - std::vector > coeffs; - for ( ; begin!=end; ++begin) { - coeffs.push_back(std:: - make_pair(row_iter_map[begin->first], begin->second)); - } - _setColCoeffs(col_iter_map[col_it], coeffs); + _Value getColLowerBound(Col col) { + return _getColLowerBound(col_iter_map[col]); } /// \e - void setColLowerBound(ColIt col_it, _Value lo) { - _setColLowerBound(col_iter_map[col_it], lo); + void setColUpperBound(Col col, _Value up) { + _setColUpperBound(col_iter_map[col], up); } /// \e - _Value getColLowerBound(ColIt col_it) { - return _getColLowerBound(col_iter_map[col_it]); + _Value getColUpperBound(Col col) { + return _getColUpperBound(col_iter_map[col]); } /// \e - void setColUpperBound(ColIt col_it, _Value up) { - _setColUpperBound(col_iter_map[col_it], up); + void setRowLowerBound(Row row, _Value lo) { + _setRowLowerBound(row_iter_map[row], lo); } /// \e - _Value getColUpperBound(ColIt col_it) { - return _getColUpperBound(col_iter_map[col_it]); + _Value getRowLowerBound(Row row) { + return _getRowLowerBound(row_iter_map[row]); } /// \e - void setRowLowerBound(RowIt row_it, _Value lo) { - _setRowLowerBound(row_iter_map[row_it], lo); + void setRowUpperBound(Row row, _Value up) { + _setRowUpperBound(row_iter_map[row], up); } /// \e - _Value getRowLowerBound(RowIt row_it) { - return _getRowLowerBound(row_iter_map[row_it]); + _Value getRowUpperBound(Row row) { + return _getRowUpperBound(row_iter_map[row]); } /// \e - void setRowUpperBound(RowIt row_it, _Value up) { - _setRowUpperBound(row_iter_map[row_it], up); + void setObjCoef(const Col& col, _Value obj_coef) { + _setObjCoef(col_iter_map[col], obj_coef); } /// \e - _Value getRowUpperBound(RowIt row_it) { - return _getRowUpperBound(row_iter_map[row_it]); - } - /// \e - void setObjCoef(const ColIt& col_it, _Value obj_coef) { - _setObjCoef(col_iter_map[col_it], obj_coef); - } - /// \e - _Value getObjCoef(const ColIt& col_it) { - return _getObjCoef(col_iter_map[col_it]); + _Value getObjCoef(const Col& col) { + return _getObjCoef(col_iter_map[col]); } //SOLUTION RETRIEVING FUNCTIONS /// \e - _Value getPrimal(const ColIt& col_it) { - return _getPrimal(col_iter_map[col_it]); + _Value getPrimal(const Col& col) { + return _getPrimal(col_iter_map[col]); } //@} @@ -508,47 +488,63 @@ //EXPRESSION TYPES /// \e - typedef Expr Expression; + typedef Expr Expression; /// \e - typedef Expr DualExpression; + typedef Expr DualExpression; + /// \e + typedef Constr Constraint; //MATRIX MANIPULATING FUNCTIONS /// \e - void setRowCoeffs(RowIt row_it, const Expression& expr) { + void setRowCoeffs(Row row, const Expression& expr) { std::vector > row_coeffs; for(typename Expression::Data::const_iterator i=expr.data.begin(); i!=expr.data.end(); ++i) { row_coeffs.push_back(std::make_pair (col_iter_map[(*i).first], (*i).second)); } - _setRowCoeffs(row_iter_map[row_it], row_coeffs); + _setRowCoeffs(row_iter_map[row], row_coeffs); + } + /// \e + void setRow(Row row, const Constraint& constr) { + setRowCoeffs(row, constr.expr); + setRowLowerBound(row, constr.lo); + setRowUpperBound(row, constr.up); + } + /// \e + Row addRow(const Constraint& constr) { + Row row=addRow(); + setRowCoeffs(row, constr.expr); + setRowLowerBound(row, constr.lo); + setRowUpperBound(row, constr.up); + return row; } /// \e /// This routine modifies \c expr by only adding to it. - void getRowCoeffs(RowIt row_it, Expression& expr) { + void getRowCoeffs(Row row, Expression& expr) { std::vector > row_coeffs; - _getRowCoeffs(row_iter_map[row_it], row_coeffs); + _getRowCoeffs(row_iter_map[row], row_coeffs); for(typename std::vector >::const_iterator i=row_coeffs.begin(); i!=row_coeffs.end(); ++i) { expr+= (*i).second*int_col_map[(*i).first]; } } /// \e - void setColCoeffs(ColIt col_it, const DualExpression& expr) { + void setColCoeffs(Col col, const DualExpression& expr) { std::vector > col_coeffs; for(typename DualExpression::Data::const_iterator i=expr.data.begin(); i!=expr.data.end(); ++i) { col_coeffs.push_back(std::make_pair (row_iter_map[(*i).first], (*i).second)); } - _setColCoeffs(col_iter_map[col_it], col_coeffs); + _setColCoeffs(col_iter_map[col], col_coeffs); } /// \e /// This routine modifies \c expr by only adding to it. - void getColCoeffs(ColIt col_it, DualExpression& expr) { + void getColCoeffs(Col col, DualExpression& expr) { std::vector > col_coeffs; - _getColCoeffs(col_iter_map[col_it], col_coeffs); + _getColCoeffs(col_iter_map[col], col_coeffs); for(typename std::vector >::const_iterator i=col_coeffs.begin(); i!=col_coeffs.end(); ++i) { expr+= (*i).second*int_row_map[(*i).first]; @@ -589,8 +585,8 @@ /// \e LPGLPK() : Parent(), lp(lpx_create_prob()) { - int_row_map.push_back(RowIt()); - int_col_map.push_back(ColIt()); + int_row_map.push_back(Row()); + int_col_map.push_back(Col()); lpx_set_int_parm(lp, LPX_K_DUAL, 1); } /// \e @@ -991,9 +987,9 @@ case LPX_D_NOFEAS: cout << "LPX_D_NOFEAS" << endl; break; } } - /// Returns the status of the slack variable assigned to row \c row_it. - int getRowStat(const RowIt& row_it) { - return lpx_get_row_stat(lp, row_iter_map[row_it]); + /// Returns the status of the slack variable assigned to row \c row. + int getRowStat(const Row& row) { + return lpx_get_row_stat(lp, row_iter_map[row]); } /// \e void printRowStatus(int i) { @@ -1005,9 +1001,9 @@ case LPX_NS: cout << "LPX_NS" << endl; break; } } - /// Returns the status of the variable assigned to column \c col_it. - int getColStat(const ColIt& col_it) { - return lpx_get_col_stat(lp, col_iter_map[col_it]); + /// Returns the status of the variable assigned to column \c col. + int getColStat(const Col& col) { + return lpx_get_col_stat(lp, col_iter_map[col]); } /// \e void printColStatus(int i) {