# HG changeset patch # User marci # Date 1101114753 0 # Node ID f588efc6d607c51c4dea58528b15ecca4ef40f49 # Parent 18d009b23e42cdd5c0999f354a37e60440f4f165 Generalized flow by lp diff -r 18d009b23e42 -r f588efc6d607 src/work/marci/lp/makefile --- a/src/work/marci/lp/makefile Mon Nov 22 09:09:18 2004 +0000 +++ b/src/work/marci/lp/makefile Mon Nov 22 09:12:33 2004 +0000 @@ -1,9 +1,9 @@ #INCLUDEDIRS ?= -I.. -I. -I./{marci,jacint,alpar,klao,akos} -GLPKROOT = /usr/local/glpk-4.4 -INCLUDEDIRS ?= -I../../{marci,alpar,klao,akos,athos} -I. -I../../.. -I../.. -I.. -I$(GLPKROOT)/include +#GLPKROOT = /usr/local/glpk-4.4 +INCLUDEDIRS ?= -I../../{marci,alpar,klao,akos,athos} -I. -I../../.. -I../.. -I..# -I$(GLPKROOT)/include #INCLUDEDIRS ?= -I../.. -I../.. -I../../{marci,jacint,alpar,klao,akos} -I/usr/local/glpk-4.4/include CXXFLAGS = -g -O2 -W -Wall $(INCLUDEDIRS) -ansi -pedantic -LDFLAGS = -L$(GLPKROOT)/lib -lglpk +LDFLAGS = -lglpk# -L$(GLPKROOT)/lib BINARIES = max_flow_by_lp# sample sample2 sample11 sample15 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:" < +//#include + +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +#include + +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:" <