marci@181: // -*- c++ -*- marci@181: #include <iostream> marci@181: #include <fstream> marci@181: marci@181: #include <LEDA/graph.h> marci@189: #include <leda_graph_wrapper.h> marci@181: #include <dimacs.h> marci@181: #include <time_measure.h> marci@181: #include <edmonds_karp.h> marci@181: marci@181: using namespace hugo; marci@181: marci@181: using std::cout; marci@181: using std::endl; marci@181: marci@181: int main() { marci@181: leda::graph g; marci@189: typedef LedaGraphWrapper<leda::graph> Graph; marci@181: Graph G(g); marci@181: // G.addNode(); marci@181: // G.addNode(); marci@181: // std::cout << G.nodeNum() << std::endl; marci@181: marci@181: typedef Graph::Node Node; marci@181: typedef Graph::NodeIt NodeIt; marci@181: typedef Graph::Edge Edge; marci@181: typedef Graph::EdgeIt EdgeIt; marci@181: typedef Graph::OutEdgeIt OutEdgeIt; marci@181: typedef Graph::InEdgeIt InEdgeIt; marci@181: marci@181: Node s, t; marci@181: Graph::EdgeMap<int> cap(G); marci@181: readDimacsMaxFlow(std::cin, G, s, t, cap); marci@181: marci@181: marci@181: // cout << "bfs and dfs iterator demo on the directed graph" << endl; marci@181: // for(NodeIt n=G.first<NodeIt>(); G.valid(n); G.next(n)) { marci@181: // cout << G.id(n) << ": "; marci@181: // cout << "out edges: "; marci@181: // for(OutEdgeIt e=G.first<OutEdgeIt>(n); G.valid(e); G.next(e)) marci@181: // cout << G.id(G.tail(e)) << "-" << cap.get(e) << "->" << G.id(G.head(e)) << " "; marci@181: // cout << "in edges: "; marci@181: // for(InEdgeIt e=G.first<InEdgeIt>(n); G.valid(e); G.next(e)) marci@181: // cout << G.id(G.tail(e)) << "-" << cap.get(e) << "->" << G.id(G.head(e)) << " "; marci@181: // cout << endl; marci@181: // } marci@181: marci@181: // int i=0; marci@181: // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e)) { cap.set(e, i); i+=3; } marci@181: // for(EdgeIt e=G.first<EdgeIt>(); G.valid(e); G.next(e)) { cout << cap.get(e) << " "; } marci@181: // cout << endl; marci@181: marci@181: { marci@181: //std::cout << "SmartGraph..." << std::endl; marci@181: std::cout << "on-the-fly edmonds karp demo on wrapped leda graph..." << std::endl; marci@181: Graph::EdgeMap<int> flow(G); //0 flow marci@181: marci@181: marci@181: Timer ts; marci@181: ts.reset(); marci@181: marci@181: MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap); marci@181: //max_flow_test.augmentWithBlockingFlow<Graph>(); marci@181: int i=0; marci@181: while (max_flow_test.augmentOnShortestPath()) { marci@181: // for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { marci@181: // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; marci@181: // } marci@181: // std::cout<<std::endl; marci@181: ++i; marci@181: } marci@181: marci@181: // std::cout << "maximum flow: "<< std::endl; marci@181: // for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { marci@181: // std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") "; marci@181: // } marci@181: // std::cout<<std::endl; marci@181: std::cout << "elapsed time: " << ts << std::endl; marci@181: std::cout << "number of augmentation phases: " << i << std::endl; marci@181: std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; marci@181: } marci@181: marci@181: marci@181: return 0; marci@181: }