2 %> Algorithm 24.2: Ford-Fulkerson. Implementation of algorithm 24.2 of \cite Bier15-book
4 %> @note Tested with \ref run2402.m
7 %> @author Michel Bierlaire
8 %> @date Thu Apr 9 18:43:39 2015
12 %> Find the maximum flow between two nodes
using the Ford Fulkerson algorithm
13 %> @param adj adjacency matrix of the network. Each nonzero entry corresponds to an arc. The value of the entry is the ID of the arc.
14 %> @param orig the origin node
15 %> @param dest the destination node
16 %> @param lb the lower bound on the flow
17 %> @param ub the upper bound on the flow
18 %> @
return flow the optimal flow vector
19 %> @
return total the total flow sent
22 narcs = max(max(adj)) ;
23 if (columns(adj) != nnodes)
24 error(
"Adjacency matrix must be square\n") ;
26 if (length(lb) != narcs)
27 error(
"lb vector has incorrect size %f instead of %d\n",length(lb),narcs) ;
30 if (length(ub) != narcs)
31 error(
"ub vector has incorrect size %f instead of %d\n",length(ub),narcs) ;
36 error(
"Incompatible bounds [%f,%f]\n",lb(i),ub(i)) ;
40 flow = zeros(narcs,1) ;
45 printf(
"%d\t",1:narcs) ;
46 printf(
"Flow sent\tPath\n") ;
48 printf(
"%d\t", iter) ;
53 % printf(
"Unsaturated path found\n") ;
55 for i = 1:length(path.arcs)
56 theArc = path.arcs(i) ;
58 f = ub(theArc) - flow(theArc) ;
63 f = flow(theArc) - lb(theArc) ;
70 % printf("Send %f units of flows along path ",send)
72 printf("%d\t",path.arcs)
75 for i = 1:length(path.arcs)
76 theArc = path.arcs(i) ;
78 flow(theArc) += send ;
80 flow(theArc) -= send ;
86 printf("Cut found: ") ;
function unsaturatedPath(in adj, in orig, in dest, in lb, in ub, in flow, in printlevel)
Find an unsaturated path from o to d.
function fordFulkerson(in adj, in orig, in dest, in lb, in ub)
Find the maximum flow between two nodes using the Ford Fulkerson algorithm.