diff -r 28e117c5bddf -r 3b1ad8bc21da src/work/marci/lp/min_cost_gen_flow.h --- a/src/work/marci/lp/min_cost_gen_flow.h Mon Nov 29 16:11:51 2004 +0000 +++ b/src/work/marci/lp/min_cost_gen_flow.h Mon Nov 29 17:55:46 2004 +0000 @@ -1,17 +1,18 @@ // -*- c++ -*- #ifndef LEMON_MIN_COST_GEN_FLOW_H #define LEMON_MIN_COST_GEN_FLOW_H -//#include +#include //#include -//#include -//#include +#include +#include //#include //#include //#include -//#include +#include //#include //#include +#include <../merge_node_graph_wrapper.h> #include namespace lemon { @@ -51,6 +52,71 @@ const CostMap& _cost) : g(_g), excess(_excess), lcapacity(_lcapacity), capacity(_capacity), flow(_flow), cost(_cost) { } + bool feasible() { + // 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 GW::EdgeIt e(gw); e!=INVALID; ++e) + translated_cap.set(typename GWWW::Edge(e,INVALID,false), + capacity[e]-lcapacity[e]); + + Num expected=0; + + // std::cout << "making new edges 2..." << std::endl; + for (typename Graph::NodeIt n(g); n!=INVALID; ++n) { + Num a=0; + for (typename Graph::InEdgeIt e(g, n); e!=INVALID; ++e) + a+=lcapacity[e]; + for (typename Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) + a-=lcapacity[e]; + if (excess[n]>a) { + typename GWW::Edge e= + gww.addEdge(typename GW::Node(n,INVALID,false), t); + translated_cap.set(typename GWWW::Edge(INVALID, e, true), + excess[n]-a); + } + if (excess[n] translated_flow(gwww, 0); + Preflow preflow(gwww, s, t, + translated_cap, translated_flow); + preflow.run(); + // std::cout << "fv: " << preflow.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); + flow.set(e, translated_flow[ewww]+lcapacity[e]); + } + return (expected>=preflow.flowValue()); + } void run() { LPSolverWrapper lp; lp.setMinimize();