Flow conservation constraints

Flow conservation constraints

The next set of constraints are the flow conservation constraints. They require that, for each commodity and node, the sum of the flow into the node plus the quantity of external inflow at that node must be equal to the sum of the flow out of the node:

for h in commodities:
  for j in nodes:
    m.addConstr(
      quicksum(flow[h,i,j] for i,j in arcs.select('*',j)) + inflow[h,j] ==
      quicksum(flow[h,j,k] for j,k in arcs.select(j,'*')),
               'node_%s_%s' % (h, j))