@@ -32,26 +32,39 @@ namespace MaximumFlowRelabelToFront
3232 }
3333 }
3434
35+ // Discharges the excess flow from nodeU
3536 void Graph::Discharge (int nodeU)
3637 {
38+ // Check if excess flow of nodeU is > 0
3739 while (this ->_excessFlow [nodeU] > 0 )
3840 {
41+ // Falg to check if any amount of excess flow is pushed to any neighbour vertex
3942 bool hasPushed = false ;
43+
44+ // Iterating over all of the vertices
4045 for (int nodeV = 0 ; nodeV < this ->_noOfVertices ; nodeV++)
4146 {
47+ // For G'.Adj[nodeU] check if edge (nodeU, nodeV) is admissible
4248 if (this ->_residualGraph [nodeU][nodeV] > 0 && this ->_height [nodeU] == 1 + this ->_height [nodeV])
4349 {
50+ // Push excess flow along the admissible edge (nodeU, nodeV)
4451 this ->Push (nodeU, nodeV);
52+ // Set the hasPushed flag to true
4553 hasPushed = true ;
54+ // Check if there is no excess flow left in nodeU then no need to check any more admissible edge going from nodeU
4655 if (this ->_excessFlow [nodeU] == 0 )
4756 {
57+ // Then break from iterating over G'.Adj[nodeU]
4858 break ;
4959 }
5060 }
5161 }
5262
63+ // Check if Push operation is not done yet
5364 if (!hasPushed)
5465 {
66+ // Then it indicates that all the outgoing edges from nodeU are inadmissible
67+ // so perform the Relabel operation on nodeU
5568 this ->Relabel (nodeU);
5669 }
5770 }
@@ -70,7 +83,6 @@ namespace MaximumFlowRelabelToFront
7083 // Adjust the excess flows in nodeU and nodeV
7184 this ->_excessFlow [nodeU] = this ->_excessFlow [nodeU] - minimumFlow;
7285 this ->_excessFlow [nodeV] = this ->_excessFlow [nodeV] + minimumFlow;
73-
7486 }
7587
7688 // Relabels height of vertex nodeU when there are outgoing non-saturated edges available
@@ -119,6 +131,7 @@ namespace MaximumFlowRelabelToFront
119131 // Initialize Pre-flow
120132 this ->InitializePreflow ();
121133
134+ // Make the list L = G.V - {source, sink}
122135 for (int i = 0 ; i < this ->_noOfVertices ; i++)
123136 {
124137 if (i != this ->_source && i != this ->_sink )
@@ -127,21 +140,27 @@ namespace MaximumFlowRelabelToFront
127140 }
128141 }
129142
143+ // Set current vertex = L.head
130144 list<int >::iterator nodeUiterator = this ->_nodeList .begin ();
131145
146+ // Iterate over all of the elements in the list L
132147 while (nodeUiterator != this ->_nodeList .end ())
133148 {
149+ // Get the height of current vertex
134150 int oldHeight = this ->_height [*nodeUiterator];
151+
152+ // Discharge the excess flow of current vertex
135153 this ->Discharge (*nodeUiterator);
154+
155+ // Check if the height of current vertex increases which means the current vertex got relabeled
136156 if (this ->_height [*nodeUiterator] > oldHeight)
137157 {
158+ // Then move current vertex to the front of the list L
138159 this ->_nodeList .splice (this ->_nodeList .begin (), this ->_nodeList , nodeUiterator);
139- nodeUiterator++;
140- }
141- else
142- {
143- nodeUiterator++;
144160 }
161+
162+ // Go to the next vertex of current vertex in L
163+ nodeUiterator++;
145164 }
146165
147166 // Return the excess flow in the sink vertex which is actually the maximum flow along the given flow network
0 commit comments