Changeset 83:efafe79a88d3 in lemon-0.x for src/work/jacint/preflow_push_max_flow.h
- Timestamp:
- 02/17/04 09:59:49 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@110
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/jacint/preflow_push_max_flow.h
r78 r83 3 3 by jacint. 4 4 Runs a preflow push algorithm with the modification, 5 that we do not push on Nodes with level at least n.6 Moreover, if a level gets empty, we .set all Nodes above that5 that we do not push on nodes with level at least n. 6 Moreover, if a level gets empty, we set all nodes above that 7 7 level to level n. Hence, in the end, we arrive at a maximum preflow 8 8 with value of a max flow value. An empty level gives a minimum cut. … … 16 16 T maxflow() : returns the value of a maximum flow 17 17 18 NodeMap< Graph,bool> mincut(): returns a18 NodeMap<bool> mincut(): returns a 19 19 characteristic vector of a minimum cut. 20 20 */ … … 52 52 public: 53 53 54 preflow_push_max_flow(Graph& _G, NodeIt _s, NodeIt _t, typename Graph::EdgeMap<T>& _capacity) : G(_G), s(_s), t(_t), capacity(_capacity), mincutvector(_G, false) { } 54 preflow_push_max_flow ( Graph& _G, NodeIt _s, NodeIt _t, 55 typename Graph::EdgeMap<T>& _capacity) : 56 G(_G), s(_s), t(_t), capacity(_capacity), mincutvector(_G, false) { } 55 57 56 58 57 59 /* 58 The run() function runs a modified version of the highest label preflow-push, which only 60 The run() function runs a modified version of the 61 highest label preflow-push, which only 59 62 finds a maximum preflow, hence giving the value of a maximum flow. 60 63 */ 61 64 void run() { 62 65 63 typename Graph::EdgeMap<T> flow(G, 0); //the flow value, 0 everywhere64 typename Graph::NodeMap<int> level(G); //level of Node65 typename Graph::NodeMap<T> excess(G); //excess of Node66 typename Graph::EdgeMap<T> flow(G, 0); 67 typename Graph::NodeMap<int> level(G); 68 typename Graph::NodeMap<T> excess(G); 66 69 67 int n=G.nodeNum(); //number of Nodes70 int n=G.nodeNum(); 68 71 int b=n-2; 69 /*b is a bound on the highest level of an active Node. In the beginning it is at most n-2.*/ 70 71 std::vector<int> numb(n); //The number of Nodes on level i < n. 72 73 std::vector<std::stack<NodeIt> > stack(2*n-1); //Stack of the active Nodes in level i. 74 75 72 /* 73 b is a bound on the highest level of an active Node. 74 In the beginning it is at most n-2. 75 */ 76 77 std::vector<int> numb(n); //The number of Nodes on level i < n. 78 std::vector<std::stack<NodeIt> > stack(2*n-1); 79 //Stack of the active Nodes in level i. 76 80 77 81 /*Reverse_bfs from t, to find the starting level.*/ 78 79 82 reverse_bfs<Graph> bfs(G, t); 80 83 bfs.run(); … … 86 89 } 87 90 88 /*The level of s is fixed to n*/89 91 level.set(s,n); 90 92 91 92 93 /* Starting flow. It is everywhere 0 at the moment. */ 93 94 for(OutEdgeIt i=G.template first<OutEdgeIt>(s); i.valid(); ++i) 94 for(OutEdgeIt e=G.template first<OutEdgeIt>(s); e.valid(); ++e) 95 95 { 96 NodeIt w=G.head(i); 97 flow.set(i, capacity.get(i)); 98 stack[bfs.dist(w)].push(w); 99 excess.set(w, capacity.get(i)); 96 if ( capacity.get(e) > 0 ) { 97 NodeIt w=G.head(e); 98 flow.set(e, capacity.get(e)); 99 stack[level.get(w)].push(w); 100 excess.set(w, excess.get(w)+capacity.get(e)); 101 } 100 102 } 101 102 103 103 104 /* 104 105 End of preprocessing 105 106 */ 106 107 107 108 108 … … 115 115 while (b) { 116 116 117 /*We decrease the bound if there is no active Node of level b.*/117 /*We decrease the bound if there is no active node of level b.*/ 118 118 if (stack[b].empty()) { 119 119 --b;
Note: See TracChangeset
for help on using the changeset viewer.