# HG changeset patch # User marci # Date 1107884839 0 # Node ID 4fb22cfa5759139398fb2b7faec270e0bc1af919 # Parent 450f794dca81f1c2efebb8a4280663846cb5f8cb The pair of setSomeThing function is getSomeThing. diff -r 450f794dca81 -r 4fb22cfa5759 src/work/marci/lp/lp_solver_base.h --- a/src/work/marci/lp/lp_solver_base.h Tue Feb 08 11:27:03 2005 +0000 +++ b/src/work/marci/lp/lp_solver_base.h Tue Feb 08 17:47:19 2005 +0000 @@ -171,6 +171,7 @@ /*! \e + \todo kellenene uj iterable structure bele, mert ez nem az igazi \todo A[x,y]-t cserel. Jobboldal, baloldal csere. \todo LEKERDEZESEK!!! \todo DOKSI!!!! Doxygen group!!! @@ -201,6 +202,10 @@ /// \e IterablePartition col_iter_map; /// \e + std::vector int_row_map; + /// \e + std::vector int_col_map; + /// \e const int VALID_CLASS; /// \e const int INVALID_CLASS; @@ -297,8 +302,15 @@ virtual void _setRowCoeffs(int i, const std::vector >& coeffs) = 0; /// \e + /// This routine modifies \c coeffs only by the \c push_back method. + virtual void _getRowCoeffs(int i, + std::vector >& coeffs) = 0; virtual void _setColCoeffs(int i, const std::vector >& coeffs) = 0; + /// \e + /// This routine modifies \c coeffs only by the \c push_back method. + virtual void _getColCoeffs(int i, + std::vector >& coeffs) = 0; public: /// \e enum Bound { FREE, LOWER, UPPER, DOUBLE, FIXED }; @@ -373,6 +385,7 @@ } else { //a cucc vegere kell inzertalni mert nincs szabad hely col_it=col_iter_map.push_back(i, VALID_CLASS); } + int_col_map.push_back(col_it); return col_it; } /// \e @@ -386,6 +399,7 @@ } else { //a cucc vegere kell inzertalni mert nincs szabad hely row_it=row_iter_map.push_back(i, VALID_CLASS); } + int_row_map.push_back(row_it); return row_it; } /// \e @@ -400,6 +414,7 @@ col_iter_map.valid(it); col_iter_map.next(it)) { if (col_iter_map[it]>cols[1]) --col_iter_map[it]; } + int_col_map.erase(int_col_map.begin()+cols[1]); } /// \e void eraseRow(const RowIt& row_it) { @@ -413,6 +428,7 @@ row_iter_map.valid(it); row_iter_map.next(it)) { if (row_iter_map[it]>rows[1]) --row_iter_map[it]; } + int_row_map.erase(int_row_map.begin()+rows[1]); } /// \e template @@ -509,6 +525,16 @@ _setRowCoeffs(row_iter_map[row_it], row_coeffs); } /// \e + /// This routine modifies \c expr by only adding to it. + void getRowCoeffs(RowIt row_it, Expression& expr) { + std::vector > row_coeffs; + _getRowCoeffs(row_iter_map[row_it], 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) { std::vector > col_coeffs; for(typename DualExpression::Data::const_iterator i=expr.data.begin(); @@ -519,12 +545,28 @@ _setColCoeffs(col_iter_map[col_it], col_coeffs); } /// \e + /// This routine modifies \c expr by only adding to it. + void getColCoeffs(ColIt col_it, DualExpression& expr) { + std::vector > col_coeffs; + _getColCoeffs(col_iter_map[col_it], 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]; + } + } + /// \e + /// \bug ez igy nem jo void setObjCoeffs(const Expression& expr) { for(typename Expression::Data::const_iterator i=expr.data.begin(); i!=expr.data.end(); ++i) { setObjCoef((*i).first, (*i).second); } } + /// \e + /// This routine modifies \c expr by only adding to it. + void getObjCoeffs(Expression& expr) { + /// FIXME not yet implemented + } //@} }; @@ -547,6 +589,8 @@ /// \e LPGLPK() : Parent(), lp(lpx_create_prob()) { + int_row_map.push_back(RowIt()); + int_col_map.push_back(ColIt()); lpx_set_int_parm(lp, LPX_K_DUAL, 1); } /// \e @@ -592,15 +636,25 @@ ++length; indices[length]=it->first; doubles[length]=it->second; -// std::cout << " " << indices[length] << " " -// << doubles[length] << std::endl; } -// std::cout << i << " " << length << std::endl; lpx_set_mat_row(lp, i, length, indices, doubles); delete [] indices; delete [] doubles; } /// \e + virtual void _getRowCoeffs(int i, + std::vector >& coeffs) { + int mem_length=1+colNum(); + int* indices = new int[mem_length]; + double* doubles = new double[mem_length]; + int length=lpx_get_mat_row(lp, i, indices, doubles); + for (int i=1; i<=length; ++i) { + coeffs.push_back(std::make_pair(indices[i], doubles[i])); + } + delete [] indices; + delete [] doubles; + } + /// \e virtual void _setColCoeffs(int i, const std::vector >& coeffs) { int mem_length=1+rowNum(); @@ -618,6 +672,19 @@ delete [] doubles; } /// \e + virtual void _getColCoeffs(int i, + std::vector >& coeffs) { + int mem_length=1+rowNum(); + int* indices = new int[mem_length]; + double* doubles = new double[mem_length]; + int length=lpx_get_mat_col(lp, i, indices, doubles); + for (int i=1; i<=length; ++i) { + coeffs.push_back(std::make_pair(indices[i], doubles[i])); + } + delete [] indices; + delete [] doubles; + } + /// \e virtual void _eraseCol(int i) { int cols[2]; cols[1]=i; diff -r 450f794dca81 -r 4fb22cfa5759 src/work/marci/lp/max_flow_expression.cc --- a/src/work/marci/lp/max_flow_expression.cc Tue Feb 08 11:27:03 2005 +0000 +++ b/src/work/marci/lp/max_flow_expression.cc Tue Feb 08 17:47:19 2005 +0000 @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -48,7 +49,9 @@ typedef LPSolver::ColIt ColIt; typedef LPSolver::RowIt RowIt; typedef Graph::EdgeMap EdgeIndexMap; + typedef Graph::NodeMap NodeIndexMap; EdgeIndexMap edge_index_map(g); + NodeIndexMap node_index_map(g); PrimalMap flow(lp, edge_index_map); // nonnegativity of flow and capacity function @@ -75,11 +78,41 @@ // flow conservation constraints if ((n!=s) && (n!=t)) { RowIt row_it=lp.addRow(); + node_index_map.set(n, row_it); lp.setRowCoeffs(row_it, expr); lp.setRowLowerBound(row_it, 0.0); lp.setRowUpperBound(row_it, 0.0); +// cout << expr << endl; +// { +// LPSolver::Expression expr; +// lp.getRowCoeffs(node_index_map[n], expr); +// cout << expr << endl; +// } } } lp.solveSimplex(); +// cout << "num of nodes: " << countNodes(g) << endl; +// cout << "num of edges: " << countEdges(g) << endl; +// cout << "num of rows: " << lp.rowNum() << endl; +// cout << "num of rows: " << lp.int_row_map.size() << endl; +// for (int i=0; i