jacint@33: #include jacint@33: #include jacint@33: #include jacint@33: jacint@33: #include jacint@33: #include jacint@33: #include jacint@33: #include jacint@33: #include jacint@33: #include jacint@33: #include jacint@33: alpar@107: using namespace hugo; jacint@33: jacint@33: jacint@33: int main (int, char*[]) jacint@33: { jacint@33: typedef graph_traits::node_iterator node_iterator; jacint@33: typedef graph_traits::edge_iterator edge_iterator; jacint@33: typedef graph_traits::each_node_iterator each_node_iterator; jacint@33: typedef graph_traits::each_edge_iterator each_edge_iterator; jacint@33: typedef graph_traits::out_edge_iterator out_edge_iterator; jacint@33: typedef graph_traits::in_edge_iterator in_edge_iterator; jacint@33: typedef graph_traits::sym_edge_iterator sym_edge_iterator; jacint@33: jacint@33: list_graph flow_test; jacint@33: jacint@33: //Ahuja könyv példája, maxflowvalue=13 jacint@33: node_iterator s=flow_test.add_node(); jacint@33: node_iterator v1=flow_test.add_node(); jacint@33: node_iterator v2=flow_test.add_node(); jacint@33: node_iterator v3=flow_test.add_node(); jacint@33: node_iterator v4=flow_test.add_node(); jacint@33: node_iterator v5=flow_test.add_node(); jacint@33: node_iterator t=flow_test.add_node(); jacint@33: jacint@33: node_property_vector node_name(flow_test); jacint@33: node_name.put(s, "s"); jacint@33: node_name.put(v1, "v1"); jacint@33: node_name.put(v2, "v2"); jacint@33: node_name.put(v3, "v3"); jacint@33: node_name.put(v4, "v4"); jacint@33: node_name.put(v5, "v5"); jacint@33: node_name.put(t, "t"); jacint@33: jacint@33: edge_iterator s_v1=flow_test.add_edge(s, v1); jacint@33: edge_iterator s_v2=flow_test.add_edge(s, v2); jacint@33: edge_iterator s_v3=flow_test.add_edge(s, v3); jacint@33: edge_iterator v2_v4=flow_test.add_edge(v2, v4); jacint@33: edge_iterator v2_v5=flow_test.add_edge(v2, v5); jacint@33: edge_iterator v3_v5=flow_test.add_edge(v3, v5); jacint@33: edge_iterator v4_t=flow_test.add_edge(v4, t); jacint@33: edge_iterator v5_t=flow_test.add_edge(v5, t); jacint@33: edge_iterator v2_s=flow_test.add_edge(v2, s); jacint@33: jacint@33: edge_property_vector cap(flow_test); jacint@33: cap.put(s_v1, 0); jacint@33: cap.put(s_v2, 10); jacint@33: cap.put(s_v3, 10); jacint@33: cap.put(v2_v4, 5); jacint@33: cap.put(v2_v5, 8); jacint@33: cap.put(v3_v5, 5); jacint@33: cap.put(v4_t, 8); jacint@33: cap.put(v5_t, 8); jacint@33: cap.put(v2_s, 0); jacint@33: jacint@33: jacint@33: jacint@33: //Marci példája, maxflowvalue=23 jacint@33: /* node_iterator s=flow_test.add_node(); jacint@33: node_iterator v1=flow_test.add_node(); jacint@33: node_iterator v2=flow_test.add_node(); jacint@33: node_iterator v3=flow_test.add_node(); jacint@33: node_iterator v4=flow_test.add_node(); jacint@33: node_iterator t=flow_test.add_node(); jacint@33: node_iterator w=flow_test.add_node(); jacint@33: jacint@33: jacint@33: node_property_vector node_name(flow_test); jacint@33: node_name.put(s, "s"); jacint@33: node_name.put(v1, "v1"); jacint@33: node_name.put(v2, "v2"); jacint@33: node_name.put(v3, "v3"); jacint@33: node_name.put(v4, "v4"); jacint@33: node_name.put(t, "t"); jacint@33: node_name.put(w, "w"); jacint@33: jacint@33: edge_iterator s_v1=flow_test.add_edge(s, v1); jacint@33: edge_iterator s_v2=flow_test.add_edge(s, v2); jacint@33: edge_iterator v1_v2=flow_test.add_edge(v1, v2); jacint@33: edge_iterator v2_v1=flow_test.add_edge(v2, v1); jacint@33: edge_iterator v1_v3=flow_test.add_edge(v1, v3); jacint@33: edge_iterator v3_v2=flow_test.add_edge(v3, v2); jacint@33: edge_iterator v2_v4=flow_test.add_edge(v2, v4); jacint@33: edge_iterator v4_v3=flow_test.add_edge(v4, v3); jacint@33: edge_iterator v3_t=flow_test.add_edge(v3, t); jacint@33: edge_iterator v4_t=flow_test.add_edge(v4, t); jacint@33: edge_iterator v3_v3=flow_test.add_edge(v3, v3); jacint@33: edge_iterator s_w=flow_test.add_edge(s, w); jacint@33: // edge_iterator v2_s=flow_test.add_edge(v2, s); jacint@33: jacint@33: jacint@33: jacint@33: edge_property_vector cap(flow_test); //serves as length in dijkstra jacint@33: cap.put(s_v1, 16); jacint@33: cap.put(s_v2, 13); jacint@33: cap.put(v1_v2, 10); jacint@33: cap.put(v2_v1, 4); jacint@33: cap.put(v1_v3, 12); jacint@33: cap.put(v3_v2, 9); jacint@33: cap.put(v2_v4, 14); jacint@33: cap.put(v4_v3, 7); jacint@33: cap.put(v3_t, 20); jacint@33: cap.put(v4_t, 4); jacint@33: cap.put(v3_v3, 4); jacint@33: cap.put(s_w, 4); jacint@33: // cap.put(v2_s, 0); jacint@33: jacint@33: */ jacint@33: jacint@33: //pelda 3, maxflowvalue=4 jacint@33: /* node_iterator s=flow_test.add_node(); jacint@33: node_iterator v1=flow_test.add_node(); jacint@33: node_iterator v2=flow_test.add_node(); jacint@33: node_iterator t=flow_test.add_node(); jacint@33: node_iterator w=flow_test.add_node(); jacint@33: jacint@33: node_property_vector node_name(flow_test); jacint@33: node_name.put(s, "s"); jacint@33: node_name.put(v1, "v1"); jacint@33: node_name.put(v2, "v2"); jacint@33: node_name.put(t, "t"); jacint@33: node_name.put(w, "w"); jacint@33: jacint@33: edge_iterator s_v1=flow_test.add_edge(s, v1); jacint@33: edge_iterator v1_v2=flow_test.add_edge(v1, v2); jacint@33: edge_iterator v2_t=flow_test.add_edge(v2, t); jacint@33: edge_iterator v1_v1=flow_test.add_edge(v1, v1); jacint@33: edge_iterator s_w=flow_test.add_edge(s, w); jacint@33: jacint@33: jacint@33: edge_property_vector cap(flow_test); jacint@33: jacint@33: cap.put(s_v1, 16); jacint@33: cap.put(v1_v2, 10); jacint@33: cap.put(v2_t, 4); jacint@33: cap.put(v1_v1, 3); jacint@33: cap.put(s_w, 5); jacint@33: */ jacint@33: jacint@33: jacint@33: jacint@33: jacint@33: std::cout << "Testing reverse_bfs..." << std::endl; jacint@33: jacint@33: reverse_bfs bfs_test(flow_test, t); jacint@33: jacint@33: bfs_test.run(); jacint@33: jacint@33: for (each_node_iterator w=flow_test.first_node(); w.valid(); ++w) { jacint@33: std::cout <<"The distance of " << w << " is " << bfs_test.dist(w) < preflow_push_test(flow_test, s, t, cap); jacint@33: jacint@33: preflow_push_test.run(); jacint@33: jacint@33: std::cout << "Maximum flow value is: " << preflow_push_test.maxflow() << "."< flow=preflow_push_test.allflow(); jacint@33: for (each_edge_iterator e=flow_test.first_edge(); e.valid(); ++e) { jacint@33: std::cout <<"Flow on edge " << flow_test.tail(e) <<"-" << flow_test.head(e)<< " is " < mincut=preflow_push_test.mincut(); jacint@33: jacint@33: for (each_node_iterator v=flow_test.first_node(); v.valid(); ++v) { jacint@33: if (mincut.get(v)) std::cout < max_flow_test(flow_test, s, t, cap); jacint@33: jacint@33: max_flow_test.run(); jacint@33: jacint@33: std::cout << "Maximum flow value is: " << max_flow_test.maxflow() << "."<< std::endl; jacint@33: jacint@33: std::cout << "A minimum cut: " < mincut2=max_flow_test.mincut(); jacint@33: jacint@33: for (each_node_iterator v=flow_test.first_node(); v.valid(); ++v) { jacint@33: if (mincut2.get(v)) std::cout < dijkstra_test(flow_test, root, cap); jacint@33: jacint@33: dijkstra_test.run(); jacint@33: jacint@33: for (each_node_iterator w=flow_test.first_node(); w.valid(); ++w) { jacint@33: if (dijkstra_test.reach(w)) { jacint@33: std::cout <<"The distance of " << w << " is " << dijkstra_test.dist(w); jacint@33: if (dijkstra_test.pred(w).valid()) { jacint@33: std::cout <<", a shortest path from the root ends with edge " << dijkstra_test.pred(w) <