diff -r 4ec35d1cd897 -r 2497336d7e14 src/work/marci/lp/min_cost_gen_flow.h --- a/src/work/marci/lp/min_cost_gen_flow.h Thu Dec 02 17:36:07 2004 +0000 +++ b/src/work/marci/lp/min_cost_gen_flow.h Thu Dec 02 19:59:30 2004 +0000 @@ -10,10 +10,11 @@ //#include //#include #include +#include //#include //#include -#include <../merge_node_graph_wrapper.h> -#include +#include +#include namespace lemon { @@ -30,7 +31,7 @@ } }; - // excess: rho-delta + // excess: rho-delta egyelore csak =0-ra. template , typename LCapMap=typename Graph::template EdgeMap, @@ -74,9 +75,12 @@ // std::cout << "making new edges..." << std::endl; typename GWWW::template EdgeMap translated_cap(gwww); - for (typename GW::EdgeIt e(gw); e!=INVALID; ++e) - translated_cap.set(typename GWWW::Edge(e,INVALID,false), - capacity[e]-lcapacity[e]); + for (typename GW::EdgeIt e(gw); e!=INVALID; ++e) { + translated_cap.set(typename GWWW::Edge(e,INVALID,false), + capacity[e]-lcapacity[e]); + // cout << "t_cap " << gw.id(e) << " " + // << translated_cap[typename GWWW::Edge(e,INVALID,false)] << endl; + } Num expected=0; @@ -92,6 +96,7 @@ gww.addEdge(typename GW::Node(n,INVALID,false), t); translated_cap.set(typename GWWW::Edge(INVALID, e, true), excess[n]-a); + // std::cout << g.id(n) << "->t " << excess[n]-a << std::endl; } if (excess[n]" << g.id(n) << " "<< a-excess[n] <=preflow.flowValue()); } - void run() { + // for nonnegative costs + bool run() { + // std::cout << "making new vertices..." << std::endl; + typedef ListGraph Graph2; + Graph2 g2; + typedef MergeEdgeGraphWrapper GW; + // std::cout << "merging..." << std::endl; + GW gw(g, g2); + typename GW::Node s(INVALID, g2.addNode(), true); + typename GW::Node t(INVALID, g2.addNode(), true); + typedef SmartGraph Graph3; + // std::cout << "making extender graph..." << std::endl; + typedef NewEdgeSetGraphWrapper2 GWW; +// { +// checkConcept(); +// } + GWW gww(gw); + typedef AugmentingGraphWrapper GWWW; + GWWW gwww(gw, gww); + + // std::cout << "making new edges..." << std::endl; + typename GWWW::template EdgeMap translated_cap(gwww); + + for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) { + typename GW::Edge ew(e, INVALID, false); + typename GWWW::Edge ewww(ew, INVALID, false); + translated_cap.set(ewww, capacity[e]-lcapacity[e]); + // cout << "t_cap " << g.id(e) << " " + // << translated_cap[ewww] << endl; + } + + Num expected=0; + + // std::cout << "making new edges 2..." << std::endl; + for (typename Graph::NodeIt n(g); n!=INVALID; ++n) { + // std::cout << "node: " << g.id(n) << std::endl; + Num a=0; + for (typename Graph::InEdgeIt e(g, n); e!=INVALID; ++e) { + a+=lcapacity[e]; + // std::cout << "bee: " << g.id(e) << " " << lcapacity[e] << std::endl; + } + for (typename Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) { + a-=lcapacity[e]; + // std::cout << "kie: " << g.id(e) << " " << lcapacity[e] << std::endl; + } + // std::cout << "excess " << g.id(n) << ": " << a << std::endl; + if (0>a) { + typename GWW::Edge e= + gww.addEdge(typename GW::Node(n,INVALID,false), t); + translated_cap.set(typename GWWW::Edge(INVALID, e, true), + -a); + // std::cout << g.id(n) << "->t " << -a << std::endl; + } + if (0" << g.id(n) << " "<< a < translated_cost(gwww, 0); + for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) { + translated_cost.set(typename GWWW::Edge( + typename GW::Edge(e, INVALID, false), INVALID, false), cost[e]); + } + // typename GWWW::template EdgeMap translated_flow(gwww, 0); + MinCostFlow, + typename GWWW::template EdgeMap > + min_cost_flow(gwww, translated_cost, translated_cap, + s, t); + while (min_cost_flow.augment()) { } + std::cout << "fv: " << min_cost_flow.flowValue() << std::endl; + std::cout << "expected: " << expected << std::endl; + + for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) { + typename GW::Edge ew(e, INVALID, false); + typename GWWW::Edge ewww(ew, INVALID, false); + // std::cout << g.id(e) << " " << flow[e] << std::endl; + flow.set(e, lcapacity[e]+ + min_cost_flow.getFlow()[ewww]); + } + return (expected>=min_cost_flow.flowValue()); + } + void runByLP() { LPSolverWrapper lp; lp.setMinimize(); typedef LPSolverWrapper::ColIt ColIt;