diff -r b3bdd856faf4 -r aae850a2394d src/work/marci/lp/max_flow_by_lp.cc --- a/src/work/marci/lp/max_flow_by_lp.cc Sat Nov 20 14:09:27 2004 +0000 +++ b/src/work/marci/lp/max_flow_by_lp.cc Sat Nov 20 14:23:27 2004 +0000 @@ -2,15 +2,14 @@ #include #include -#include #include +#include #include #include //#include -#include +#include #include //#include -#include #include using namespace lemon; @@ -33,9 +32,8 @@ int main(int, char **) { - typedef SageGraph MutableGraph; - //typedef SmartGraph Graph; - typedef SageGraph Graph; + typedef ListGraph MutableGraph; + typedef SmartGraph Graph; typedef Graph::Node Node; typedef Graph::EdgeIt EdgeIt; @@ -47,7 +45,7 @@ readDimacs(std::cin, g, cap, s, t); Timer ts; Graph::EdgeMap flow(g); //0 flow - MaxFlow, Graph::EdgeMap > + Preflow, Graph::EdgeMap > max_flow_test(g, s, t, cap, flow); AugmentingFlow, Graph::EdgeMap > augmenting_flow_test(g, s, t, cap, flow); @@ -60,9 +58,9 @@ max_flow_test.run(); std::cout << "elapsed time: " << ts << std::endl; std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; - max_flow_test.actMinCut(cut); + max_flow_test.minCut(cut); - FOR_EACH_LOC(Graph::EdgeIt, e, g) { + for (Graph::EdgeIt e(g); e!=INVALID; ++e) { if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e]) std::cout << "Slackness does not hold!" << std::endl; if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0) @@ -74,7 +72,7 @@ // std::cout << "preflow ..." << std::endl; // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); // ts.reset(); -// max_flow_test.preflow(MaxFlow, Graph::EdgeMap >::GEN_FLOW); +// max_flow_test.preflow(Preflow, Graph::EdgeMap >::GEN_FLOW); // std::cout << "elapsed time: " << ts << std::endl; // std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; @@ -97,7 +95,7 @@ { std::cout << "physical blocking flow augmentation ..." << std::endl; - FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); + for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); ts.reset(); int i=0; while (augmenting_flow_test.augmentOnBlockingFlow()) { ++i; } @@ -105,7 +103,7 @@ std::cout << "number of augmentation phases: " << i << std::endl; std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl; - FOR_EACH_LOC(Graph::EdgeIt, e, g) { + for (Graph::EdgeIt e(g); e!=INVALID; ++e) { if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e]) std::cout << "Slackness does not hold!" << std::endl; if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0) @@ -126,7 +124,7 @@ { std::cout << "on-the-fly blocking flow augmentation ..." << std::endl; - FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); + for (Graph::EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0); ts.reset(); int i=0; while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; } @@ -134,7 +132,7 @@ std::cout << "number of augmentation phases: " << i << std::endl; std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl; - FOR_EACH_LOC(Graph::EdgeIt, e, g) { + for (Graph::EdgeIt e(g); e!=INVALID; ++e) { if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e]) std::cout << "Slackness does not hold!" << std::endl; if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0) @@ -186,37 +184,28 @@ typedef Graph::EdgeMap EdgeIndexMap; EdgeIndexMap edge_index_map(g); PrimalMap lp_flow(lp, edge_index_map); - Graph::EdgeIt e; - for (g.first(e); g.valid(e); g.next(e)) { + for (Graph::EdgeIt e(g); e!=INVALID; ++e) { ColIt col_it=lp.addCol(); edge_index_map.set(e, col_it); lp.setColBounds(col_it, LPX_DB, 0.0, cap[e]); } - Graph::NodeIt n; - for (g.first(n); g.valid(n); g.next(n)) { + for (Graph::NodeIt n(g); n!=INVALID; ++n) { if (n!=s) { //hurokelek miatt Graph::EdgeMap coeffs(g, 0); - { - Graph::InEdgeIt e; - for (g.first(e, n); g.valid(e); g.next(e)) coeffs.set(e, coeffs[e]+1); - } - { - Graph::OutEdgeIt e; - for (g.first(e, n); g.valid(e); g.next(e)) coeffs.set(e, coeffs[e]-1); - } + for (Graph::InEdgeIt e(g, n); e!=INVALID; ++e) + coeffs.set(e, coeffs[e]+1); + for (Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) + coeffs.set(e, coeffs[e]-1); if (n==t) { - Graph::EdgeIt e; - //std::vector< std::pair > row; - for (g.first(e); g.valid(e); g.next(e)) { + for (Graph::EdgeIt e(g); e!=INVALID; ++e) { if (coeffs[e]!=0) lp.setObjCoef(edge_index_map[e], coeffs[e]); } } else { RowIt row_it=lp.addRow(); - Graph::EdgeIt e; std::vector< std::pair > row; - for (g.first(e); g.valid(e); g.next(e)) { + for (Graph::EdgeIt e(g); e!=INVALID; ++e) { if (coeffs[e]!=0) row.push_back(std::make_pair(edge_index_map[e], coeffs[e])); }