jacint@833: #include jacint@833: #include "test_tools.h" jacint@833: #include jacint@833: #include jacint@833: #include jacint@833: #include jacint@833: #include jacint@833: using namespace hugo; jacint@833: jacint@833: void check_Preflow() jacint@833: { jacint@833: typedef int VType; jacint@833: typedef skeleton::StaticGraphSkeleton Graph; jacint@833: jacint@833: typedef Graph::Node Node; jacint@833: typedef Graph::Edge Edge; jacint@833: typedef skeleton::ReadMap CapMap; jacint@833: typedef skeleton::ReadWriteMap FlowMap; jacint@833: typedef skeleton::ReadWriteMap CutMap; jacint@833: jacint@833: typedef Preflow PType; jacint@833: jacint@833: Graph G; jacint@833: Node n; jacint@833: CapMap cap; jacint@833: FlowMap flow; jacint@833: CutMap cut; jacint@833: jacint@833: PType preflow_test(G,n,n,cap,flow); jacint@833: jacint@833: preflow_test.run(); jacint@833: preflow_test.flowValue(); jacint@833: preflow_test.setSource(n); jacint@833: preflow_test.setFlow(flow); jacint@833: jacint@833: preflow_test.phase1(PType::NO_FLOW); jacint@833: preflow_test.minCut(cut); jacint@833: jacint@833: preflow_test.phase2(); jacint@833: preflow_test.setTarget(n); jacint@833: preflow_test.setCap(cap); jacint@833: preflow_test.minMinCut(cut); jacint@833: preflow_test.maxMinCut(cut); jacint@833: } jacint@833: jacint@833: int cut_value ( SmartGraph& G, SmartGraph::NodeMap& cut, jacint@833: SmartGraph::EdgeMap& cap) { jacint@833: jacint@833: int c=0; jacint@833: for(SmartGraph::EdgeIt e(G); e!=INVALID; ++e) { jacint@833: if (cut[G.tail(e)] && !cut[G.head(e)]) c+=cap[e]; jacint@833: } jacint@833: return c; jacint@833: } jacint@833: jacint@833: int main() { jacint@833: jacint@833: typedef SmartGraph Graph; jacint@833: alpar@842: typedef Graph::Node Node; jacint@833: typedef Graph::NodeIt NodeIt; jacint@833: typedef Graph::EdgeIt EdgeIt; jacint@833: typedef Graph::EdgeMap CapMap; jacint@833: typedef Graph::EdgeMap FlowMap; jacint@833: typedef Graph::NodeMap CutMap; jacint@833: jacint@833: typedef Preflow PType; jacint@833: ladanyi@845: std::ifstream file("preflow_graph.out"); jacint@833: jacint@833: Graph G; alpar@842: Node s, t; jacint@833: CapMap cap(G); jacint@833: readDimacs(file, G, cap, s, t); jacint@833: jacint@833: FlowMap flow(G,0); jacint@833: jacint@833: PType preflow_test(G, s, t, cap, flow); jacint@833: preflow_test.run(PType::ZERO_FLOW); jacint@833: jacint@833: jacint@833: CutMap mincut(G,false); jacint@833: preflow_test.minCut(mincut); jacint@833: int min_cut_value=cut_value(G,mincut,cap); jacint@833: jacint@833: CutMap minmincut(G,false); jacint@833: preflow_test.minMinCut(minmincut); jacint@833: int min_min_cut_value=cut_value(G,minmincut,cap); jacint@833: jacint@833: CutMap maxmincut(G,false); jacint@833: preflow_test.maxMinCut(maxmincut); jacint@833: int max_min_cut_value=cut_value(G,maxmincut,cap); jacint@833: jacint@833: check(preflow_test.flowValue() == min_cut_value && jacint@833: min_cut_value == min_min_cut_value && jacint@833: min_min_cut_value == max_min_cut_value, jacint@833: "The max flow value is not equal to the three min cut values."); jacint@833: jacint@833: int flow_value=preflow_test.flowValue(); jacint@833: jacint@833: jacint@833: for(EdgeIt e(G); e!=INVALID; ++e) cap[e]=2*cap[e]; jacint@833: preflow_test.setCap(cap); alpar@842: alpar@842: NodeIt tmp_node(G,t); alpar@842: ++tmp_node; alpar@842: t=tmp_node; alpar@842: alpar@842: preflow_test.setTarget(t); //the max flow value remains 2*flow_value jacint@833: //warning: ++t must be a valid node. In preflow_graph, it is. jacint@833: jacint@833: preflow_test.phase1(PType::PRE_FLOW); jacint@833: jacint@833: CutMap mincut1(G,false); jacint@833: preflow_test.minCut(mincut1); jacint@833: min_cut_value=cut_value(G,mincut1,cap); jacint@833: jacint@833: check(preflow_test.flowValue() == min_cut_value && jacint@833: min_cut_value == 2*flow_value, jacint@833: "The max flow value or the min cut value is wrong."); jacint@833: jacint@833: preflow_test.phase2(); jacint@833: jacint@833: CutMap mincut2(G,false); jacint@833: preflow_test.minCut(mincut2); jacint@833: min_cut_value=cut_value(G,mincut2,cap); jacint@833: jacint@833: CutMap minmincut2(G,false); jacint@833: preflow_test.minMinCut(minmincut2); jacint@833: min_min_cut_value=cut_value(G,minmincut2,cap); jacint@833: jacint@833: jacint@833: preflow_test.maxMinCut(maxmincut); jacint@833: jacint@833: max_min_cut_value=cut_value(G,maxmincut,cap); jacint@833: jacint@833: check(preflow_test.flowValue() == min_cut_value && jacint@833: min_cut_value == min_min_cut_value && jacint@833: min_min_cut_value == max_min_cut_value && jacint@833: min_cut_value == 2*flow_value, jacint@833: "The max flow value or the three min cut values were not doubled"); jacint@833: jacint@833: EdgeIt e(G); jacint@833: for( int i=1; i==1000; ++i ) { jacint@833: flow[e]=0; jacint@833: ++e; jacint@833: } jacint@833: jacint@833: preflow_test.setFlow(flow); jacint@833: preflow_test.setSource(s); jacint@833: jacint@833: preflow_test.run(); jacint@833: jacint@833: CutMap mincut3(G,false); jacint@833: preflow_test.minCut(mincut3); jacint@833: min_cut_value=cut_value(G,mincut3,cap); jacint@833: jacint@833: CutMap minmincut3(G,false); jacint@833: preflow_test.minMinCut(minmincut3); jacint@833: min_min_cut_value=cut_value(G,minmincut3,cap); jacint@833: jacint@833: preflow_test.maxMinCut(maxmincut); jacint@833: max_min_cut_value=cut_value(G,maxmincut,cap); jacint@833: jacint@833: check(preflow_test.flowValue() == min_cut_value && jacint@833: min_cut_value == min_min_cut_value && jacint@833: min_min_cut_value == max_min_cut_value, jacint@833: "The max flow value or the three min cut values are incorrect."); jacint@833: } jacint@833: jacint@833: jacint@833: