A regional water distribution company needs to optimize its pipeline network to maximize the daily water supply from Reservoir A (source) to City D (sink). The network consists of 5 pumping stations (nodes B, C, E, F, G) connected by pipelines with the following capacities (in thousand cubic meters/day): A→B (15), A→C (10), B→C (5), B→D (10), C→E (8), C→F (12), E→D (7), F→D (20), G→D (0, currently inactive). Pumping station G is temporarily out of service. The system must maintain flow conservation at all intermediate nodes while respecting pipeline capacities.

Problem type: LP (Small: 8 variables, 13 constraints, 19 nonzeros)

Mathematical model:
Set:
1. Nodes
The set of all nodes \( N = \{A, B, C, D, E, F, G\} \), where A is source and D is sink
2. Arcs
The set of directed arcs \( A = \{(A,B), (A,C), (B,C), (B,D), (C,E), (C,F), (E,D), (F,D), (G,D)\} \)

Parameter:
1. Capacity
Pipeline capacity limits \( u_{ij} \): 
\( u_{AB} = 15 \), \( u_{AC} = 10 \), \( u_{BC} = 5 \), \( u_{BD} = 10 \), \( u_{CE} = 8 \), \( u_{CF} = 12 \), \( u_{ED} = 7 \), \( u_{FD} = 20 \), \( u_{GD} = 0 \)

Decision variable:
1. Flow
Non-negative variable \( x_{ij} \geq 0 \) representing flow through arc \( (i,j) \in A \)

Objective:
Maximize total flow from source to sink
max: \( x_{AB} + x_{AC} \) 
(Equivalent to maximizing inflow at sink D)

Constraint:
1. Capacity constraints
\( x_{ij} \leq u_{ij}, \forall (i,j) \in A \)
2. Flow conservation
\( \sum_{(i,k) \in A} x_{ik} = \sum_{(k,j) \in A} x_{kj}, \forall k \in N \setminus \{A,D\} \)
3. Non-negativity
\( x_{ij} \geq 0, \forall (i,j) \in A \)

Type:
Continuous, Linear, Linear
LP

Gurobi implementation:
import gurobipy as gp
from gurobipy import GRB

def solve_max_flow(
    nodes=['A', 'B', 'C', 'D', 'E', 'F', 'G'],
    arcs={
        ('A', 'B'): 15,
        ('A', 'C'): 10,
        ('B', 'C'): 5,
        ('B', 'D'): 10,
        ('C', 'E'): 8,
        ('C', 'F'): 12,
        ('E', 'D'): 7,
        ('F', 'D'): 20,
        ('G', 'D'): 0
    }
):
    """Solve the maximum flow problem for water distribution network."""
    
    model = gp.Model("WaterDistributionMaxFlow")
    
    active_arcs = {k: v for k, v in arcs.items() if v > 0}
    
    flow = model.addVars(active_arcs.keys(), name="flow")
    
    model.setObjective(flow.sum('A', '*'), GRB.MAXIMIZE)
    
    model.addConstrs((flow[i,j] <= active_arcs[i,j] for i,j in active_arcs), "capacity")
    
    intermediate_nodes = [n for n in nodes if n not in ['A', 'D']]
    
    for node in intermediate_nodes:
        inflow = gp.quicksum(flow[i,j] for i,j in active_arcs if j == node)
        outflow = gp.quicksum(flow[i,j] for i,j in active_arcs if i == node)
        model.addConstr(inflow == outflow, f"flow_conserv_{node}")
    
    model.optimize()
    
    if model.status == GRB.OPTIMAL:
        return {"status": "optimal", "obj": model.objVal}
    else:
        return {"status": f"{model.status}"}

if __name__ == "__main__":
    result = solve_max_flow()
    print(result)

Solution status: OPTIMAL
Optimal objective value: 25