Index: test/preflow_test.cc
===================================================================
--- test/preflow_test.cc	(revision 2391)
+++ test/preflow_test.cc	(revision 2514)
@@ -29,5 +29,5 @@
 using namespace lemon;
 
-void check_Preflow() 
+void checkPreflow() 
 {
   typedef int VType;
@@ -38,33 +38,38 @@
   typedef concepts::ReadMap<Edge,VType> CapMap;
   typedef concepts::ReadWriteMap<Edge,VType> FlowMap;
-  typedef concepts::ReadWriteMap<Node,bool> CutMap;
+  typedef concepts::WriteMap<Node,bool> CutMap;
  
-  typedef Preflow<Graph, int, CapMap, FlowMap> PType;
-
   Graph g;
   Node n;
+  Edge e;
   CapMap cap;
   FlowMap flow;
   CutMap cut;
 
-  PType preflow_test(g,n,n,cap,flow);
-
+  Preflow<Graph, CapMap>::DefFlowMap<FlowMap>::Create preflow_test(g,cap,n,n);
+
+  preflow_test.capacityMap(cap);
+  flow = preflow_test.flowMap();
+  preflow_test.flowMap(flow);
+  preflow_test.source(n);
+  preflow_test.target(n);
+  
+  preflow_test.init();
+  preflow_test.flowInit(cap);
+  preflow_test.startFirstPhase();
+  preflow_test.startSecondPhase();
   preflow_test.run();
+  preflow_test.runMinCut();
+
   preflow_test.flowValue();
-  preflow_test.source(n);
-  preflow_test.flowMap(flow);
-
-  preflow_test.phase1(PType::NO_FLOW);
-  preflow_test.minCut(cut);
-
-  preflow_test.phase2();
-  preflow_test.target(n);
-  preflow_test.capacityMap(cap);
-  preflow_test.minMinCut(cut);
-  preflow_test.maxMinCut(cut);
-}
-
-int cut_value ( SmartGraph& g, SmartGraph::NodeMap<bool>& cut, 
-		SmartGraph::EdgeMap<int>& cap) {
+  preflow_test.minCut(n);
+  preflow_test.minCutMap(cut);
+  preflow_test.flow(e);
+
+}
+
+int cutValue (const SmartGraph& g, 
+	      const SmartGraph::NodeMap<bool>& cut, 
+	      const SmartGraph::EdgeMap<int>& cap) {
   
   int c=0;
@@ -73,4 +78,27 @@
   }
   return c;
+}
+
+bool checkFlow(const SmartGraph& g, 
+	       const SmartGraph::EdgeMap<int>& flow, 
+	       const SmartGraph::EdgeMap<int>& cap, 
+	       SmartGraph::Node s, SmartGraph::Node t) {
+
+  for (SmartGraph::EdgeIt e(g); e != INVALID; ++e) {
+    if (flow[e] < 0 || flow[e] > cap[e]) return false;
+  }
+
+  for (SmartGraph::NodeIt n(g); n != INVALID; ++n) {
+    if (n == s || n == t) continue;
+    int sum = 0;
+    for (SmartGraph::OutEdgeIt e(g, n); e != INVALID; ++e) {
+      sum += flow[e];
+    }
+    for (SmartGraph::InEdgeIt e(g, n); e != INVALID; ++e) {
+      sum -= flow[e];
+    }
+    if (sum != 0) return false;
+  }
+  return true;
 }
 
@@ -86,5 +114,5 @@
   typedef Graph::NodeMap<bool> CutMap;
 
-  typedef Preflow<Graph, int> PType;
+  typedef Preflow<Graph, CapMap> PType;
 
   std::string f_name;
@@ -103,40 +131,29 @@
   readDimacs(file, g, cap, s, t);
 
-  FlowMap flow(g,0);
-
- 
-
-  PType preflow_test(g, s, t, cap, flow);
-  preflow_test.run(PType::ZERO_FLOW);
+  PType preflow_test(g, cap, s, t);
+  preflow_test.run();
     
-  CutMap min_cut(g,false);
-  preflow_test.minCut(min_cut); 
-  int min_cut_value=cut_value(g,min_cut,cap);
-   
-  CutMap min_min_cut(g,false);
-  preflow_test.minMinCut(min_min_cut); 
-  int min_min_cut_value=cut_value(g,min_min_cut,cap);
-   
-  CutMap max_min_cut(g,false);
-  preflow_test.maxMinCut(max_min_cut); 
-  int max_min_cut_value=cut_value(g,max_min_cut,cap);
-
-  check(preflow_test.flowValue() == min_cut_value &&
-	min_cut_value == min_min_cut_value &&
-	min_min_cut_value == max_min_cut_value,
+  check(checkFlow(g, preflow_test.flowMap(), cap, s, t),
+	"The flow is not feasible.");
+
+  CutMap min_cut(g);
+  preflow_test.minCutMap(min_cut); 
+  int min_cut_value=cutValue(g,min_cut,cap);
+  
+  check(preflow_test.flowValue() == min_cut_value,
 	"The max flow value is not equal to the three min cut values.");
 
+  FlowMap flow(g);
+  flow = preflow_test.flowMap();
+
   int flow_value=preflow_test.flowValue();
 
-
-
   for(EdgeIt e(g); e!=INVALID; ++e) cap[e]=2*cap[e]; 
-  preflow_test.capacityMap(cap);  
-
-  preflow_test.phase1(PType::PRE_FLOW);
-
-  CutMap min_cut1(g,false);
-  preflow_test.minCut(min_cut1); 
-  min_cut_value=cut_value(g,min_cut1,cap);
+  preflow_test.flowInit(flow);
+  preflow_test.startFirstPhase();
+
+  CutMap min_cut1(g);
+  preflow_test.minCutMap(min_cut1); 
+  min_cut_value=cutValue(g,min_cut1,cap);
    
   check(preflow_test.flowValue() == min_cut_value &&
@@ -144,30 +161,17 @@
 	"The max flow value or the min cut value is wrong.");
 
-  preflow_test.phase2();
-
-  CutMap min_cut2(g,false);
-  preflow_test.minCut(min_cut2); 
-  min_cut_value=cut_value(g,min_cut2,cap);
+  preflow_test.startSecondPhase();
+
+  check(checkFlow(g, preflow_test.flowMap(), cap, s, t),
+	"The flow is not feasible.");
+
+  CutMap min_cut2(g);
+  preflow_test.minCutMap(min_cut2); 
+  min_cut_value=cutValue(g,min_cut2,cap);
    
-  CutMap min_min_cut2(g,false);
-  preflow_test.minMinCut(min_min_cut2); 
-  min_min_cut_value=cut_value(g,min_min_cut2,cap);
- 
-  preflow_test.maxMinCut(max_min_cut); 
-  max_min_cut_value=cut_value(g,max_min_cut,cap);
-
   check(preflow_test.flowValue() == min_cut_value &&
-	min_cut_value == min_min_cut_value &&
-	min_min_cut_value == max_min_cut_value &&
 	min_cut_value == 2*flow_value,
 	"The max flow value or the three min cut values were not doubled");
 
-
-
-  EdgeIt e(g);
-  for( int i=1; i==10; ++i ) {
-    flow.set(e,0);
-    ++e;
-  }
 
   preflow_test.flowMap(flow); 
@@ -186,18 +190,12 @@
   preflow_test.run();
 
-  CutMap min_cut3(g,false);
-  preflow_test.minCut(min_cut3); 
-  min_cut_value=cut_value(g,min_cut3,cap);
+  CutMap min_cut3(g);
+  preflow_test.minCutMap(min_cut3); 
+  min_cut_value=cutValue(g,min_cut3,cap);
    
-  CutMap min_min_cut3(g,false);
-  preflow_test.minMinCut(min_min_cut3); 
-  min_min_cut_value=cut_value(g,min_min_cut3,cap);
-   
-  preflow_test.maxMinCut(max_min_cut); 
-  max_min_cut_value=cut_value(g,max_min_cut,cap);
-
-  check(preflow_test.flowValue() == min_cut_value &&
-	min_cut_value == min_min_cut_value &&
-	min_min_cut_value == max_min_cut_value,
+
+  check(preflow_test.flowValue() == min_cut_value,
 	"The max flow value or the three min cut values are incorrect.");
-}
+  
+  return 0;
+}
