A regional logistics company needs to optimize its cargo transportation network involving 3 supply points (S1, S2, S3), 2 transshipment hubs (H1, H2), and 4 demand points (D1, D2, D3, D4). The supply capacities are 200, 150, and 180 units respectively. Demand requirements are 120, 90, 110, and 130 units respectively. Transportation costs (per unit) between nodes are: S1-H1=5, S1-H2=7, S2-H1=6, S2-H2=8, S3-H1=4, S3-H2=5, H1-D1=3, H1-D2=4, H1-D3=5, H1-D4=6, H2-D1=4, H2-D2=3, H2-D3=6, H2-D4=5. All routes have unlimited capacity. The objective is to minimize total transportation costs while meeting all supply and demand constraints.

Problem type: LP (Small: 14 variables, 9 constraints, 28 nonzeros)

Mathematical model:
Set:
1. SupplyNodes
The set of supply nodes, \( S = \{S1, S2, S3\} \)
2. HubNodes
The set of transshipment hubs, \( H = \{H1, H2\} \)
3. DemandNodes
The set of demand nodes, \( D = \{D1, D2, D3, D4\} \)

Parameter:
1. SupplyCapacity
\( [200, 150, 180] \) units for \( S1, S2, S3 \) respectively
2. DemandRequirement
\( [120, 90, 110, 130] \) units for \( D1, D2, D3, D4 \) respectively
3. TransportationCost
Cost matrix \( c_{ij} \) where \( i \in S \cup H, j \in H \cup D \):
- \( c_{S1,H1}=5 \), \( c_{S1,H2}=7 \)
-S \( c_{S2,H1}=6 \), \( c_{S2,H2}=8 \)
- \( c_{S3,H1}=4 \), \( c_{S3,H2}=5 \)
- \( c_{H1,D1}=3 \), \( c_{H1,D2}=4 \), \( c_{H1,D3}=5 \), \( c_{H1,D4}=6 \)
- \( c_{H2,D1}=4 \), \( c_{H2,D2}=3 \), \( c_{H2,D3}=6 \), \( c_{H2,D4}=5 \)

Decision variable:
1. FlowAmount
continuous variable \( x_{ij} \geq 0 \) representing the flow from node \( i \) to node \( j \), where \( i \in S \cup H, j \in H \cup D \)

Objective:
Minimize total transportation cost
min: \( \sum_{i \in S} \sum_{j \in H} c_{ij}x_{ij} + \sum_{i \in H} \sum_{j \in D} c_{ij}x_{ij} \)

Constraint:
1. Supply constraints: Outflow from each supply node cannot exceed its capacity
\( \sum_{j \in H} x_{ij} \leq SupplyCapacity_i, \forall i \in S \)
2. Hub balance: Inflow equals outflow at each hub
\( \sum_{i \in S} x_{ih} = \sum_{j \in D} x_{hj}, \forall h \in H \)
3. Demand constraints: Inflow to each demand node must meet its requirement
\( \sum_{i \in H} x_{ij} = DemandRequirement_j, \forall j \in D \)

Type:
Continuous, Linear, Linear
LP

Gurobi implementation:
import gurobipy as gp
from gurobipy import GRB


def solve_transportation_problem(
    supply_nodes=['S1', 'S2', 'S3'],
    hub_nodes=['H1', 'H2'],
    demand_nodes=['D1', 'D2', 'D3', 'D4'],
    supply_capacity={'S1': 200, 'S2': 150, 'S3': 180},
    demand_requirement={'D1': 120, 'D2': 90, 'D3': 110, 'D4': 130},
    transport_cost={
        ('S1', 'H1'): 5, ('S1', 'H2'): 7,
        ('S2', 'H1'): 6, ('S2', 'H2'): 8,
        ('S3', 'H1'): 4, ('S3', 'H2'): 5,
        ('H1', 'D1'): 3, ('H1', 'D2'): 4, ('H1', 'D3'): 5, ('H1', 'D4'): 6,
        ('H2', 'D1'): 4, ('H2', 'D2'): 3, ('H2', 'D3'): 6, ('H2', 'D4'): 5,
    }
):
    """Solve the cargo transportation network optimization problem."""
    model = gp.Model("CargoTransportation")

    flow = model.addVars(transport_cost.keys(), lb=0, vtype=GRB.CONTINUOUS, name="flow")

    model.setObjective(
        gp.quicksum(flow[i, j] * transport_cost[i, j] for i, j in transport_cost.keys()),
        GRB.MINIMIZE
    )

    for s in supply_nodes:
        model.addConstr(gp.quicksum(flow[s, h] for h in hub_nodes) <= supply_capacity[s])

    for h in hub_nodes:
        model.addConstr(
            gp.quicksum(flow[s, h] for s in supply_nodes) == gp.quicksum(flow[h, d] for d in demand_nodes)
        )

    for d in demand_nodes:
        model.addConstr(gp.quicksum(flow[h, d] for h in hub_nodes) == demand_requirement[d])

    model.optimize()

    if model.status == GRB.OPTIMAL:
        return {"status": "optimal", "obj": model.ObjVal}
    else:
        return {"status": f"{model.status}"}


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

Solution status: OPTIMAL
Optimal objective value: 4190