int: nNoeuds; int: nAretes; array[1..nAretes, 1..2] of 1..nNoeuds: A; %Each edge has the form (i,j) where i is the source vertex and j is the destination vertex array[1..nAretes] of int: u; % capacity of each edge array[1..nAretes] of int: c; % cost of each edge int: source; int: dest; array[1..nAretes] of var int: x; % Variable corresponding to the flow passing through each edge var int: max_flow; constraint forall(i in 1..nAretes)(x[i] >= 0); %all flows must be positive constraint forall(i in 1..nAretes)(x[i] <= u[i]); %all flows must be less than the capacity of the edge constraint forall(i in 1..nNoeuds) (sum(j in 1..nAretes where A[j,2] == i) (x[j]) - sum(j in 1..nAretes where A[j,1] == i) (x[j]) == 0);%out = in constraint max_flow = sum(i in 1..nAretes)(c[i] * x[i]); %objective solve maximize max_flow;