# introduce sets for indexing: the set set V of nodes and the set A of arcs,
# whose elements are pairs of nodes.
set V;
set A within V cross V ;
# declare parameters:
param u{A} >=0; # upper capacities (nonnegative) on the arcs.
param s symbolic in V; # one node has the special role of being the source node
param t symbolic in V; # one node has the special role of being the target node
# the actual value of the parameters, as well as the sets, are defined in a separate data (.dat) file.
# variable declarations:
# we have one variable for each arc of the network,
# representing the amount of flow along that arc.
var x{A} >= 0;
# objective function: maximize the total flow out of the source node s.
# Equivalently, we could maximize the total flow into the target node t (as we did in maxflow0.mod).
maximize TotalFlow:
sum{(s,w) in A} x[s,w] - sum{(v,s) in A} x[v,s];
# flow conservation constraints for all inner nodes, i.e. nodes different from s and t
subject to FlowCons{v in V: v <> s and v <> t}:
sum{(w,v) in A} x[w,v] = sum{(v,r) in A} x[v,r];
# constraints for upper capacities on the flow value;
# lower capacities are enforced as bound constraints along with the variable declarations.
subject to UpperCap{(w,v) in A}: x[w,v] <= u[w,v];