diff -r 18d009b23e42 -r f588efc6d607 src/work/marci/lp/max_flow_by_lp.cc --- a/src/work/marci/lp/max_flow_by_lp.cc Mon Nov 22 09:09:18 2004 +0000 +++ b/src/work/marci/lp/max_flow_by_lp.cc Mon Nov 22 09:12:33 2004 +0000 @@ -11,96 +11,13 @@ #include //#include #include +#include // Use a DIMACS max flow file as stdin. // max_flow_demo < dimacs_max_flow_file using namespace lemon; -namespace lemon { - - template - class PrimalMap { - protected: - LPSolverWrapper* lp; - EdgeIndexMap* edge_index_map; - public: - PrimalMap(LPSolverWrapper& _lp, EdgeIndexMap& _edge_index_map) : - lp(&_lp), edge_index_map(&_edge_index_map) { } - double operator[](Edge e) const { - return lp->getPrimal((*edge_index_map)[e]); - } - }; - - // excess: rho-delta - template , - typename LCapMap=typename Graph::template EdgeMap, - typename CapMap=typename Graph::template EdgeMap, - typename FlowMap=typename Graph::template EdgeMap, - typename CostMap=typename Graph::template EdgeMap > - class MinCostGenFlow { - protected: - const Graph& g; - const Excess& excess; - const LCapMap& lcapacity; - const CapMap& capacity; - FlowMap& flow; - const CostMap& cost; - public: - MinCostGenFlow(const Graph& _g, const Excess& _excess, - const LCapMap& _lcapacity, const CapMap& _capacity, - FlowMap& _flow, - const CostMap& _cost) : - g(_g), excess(_excess), lcapacity(_lcapacity), - capacity(_capacity), flow(_flow), cost(_cost) { } - void run() { - LPSolverWrapper lp; - lp.setMinimize(); - typedef LPSolverWrapper::ColIt ColIt; - typedef LPSolverWrapper::RowIt RowIt; - typedef typename Graph::template EdgeMap EdgeIndexMap; - EdgeIndexMap edge_index_map(g); - PrimalMap lp_flow(lp, edge_index_map); - for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) { - ColIt col_it=lp.addCol(); - edge_index_map.set(e, col_it); - if (lcapacity[e]==capacity[e]) - lp.setColBounds(col_it, LPX_FX, lcapacity[e], capacity[e]); - else - lp.setColBounds(col_it, LPX_DB, lcapacity[e], capacity[e]); - lp.setObjCoef(col_it, cost[e]); - } - for (typename Graph::NodeIt n(g); n!=INVALID; ++n) { - typename Graph::template EdgeMap coeffs(g, 0); - for (typename Graph::InEdgeIt e(g, n); e!=INVALID; ++e) - coeffs.set(e, coeffs[e]+1); - for (typename Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) - coeffs.set(e, coeffs[e]-1); - RowIt row_it=lp.addRow(); - typename std::vector< std::pair > row; - //std::cout << "node:" <