A regional distribution center needs to optimize its daily delivery routes for 5 stores located at different distances. The center has 3 available delivery trucks with capacities of 8, 10, and 12 tons respectively. The daily demands of the stores are: Store1 (3 tons), Store2 (4 tons), Store3 (5 tons), Store4 (2 tons), and Store5 (6 tons). The distance matrix (in km) between the distribution center (DC) and stores is: DC-Store1: 15, DC-Store2: 20, DC-Store3: 25, DC-Store4: 30, DC-Store5: 35. Each truck can visit multiple stores but cannot exceed its capacity. The objective is to minimize the total distance traveled by all trucks while ensuring all store demands are met.

Problem type: MILP (Small: 21 variables, 26 constraints, 78 nonzeros)

Mathematical model:
Set:
1. Trucks
The set of available trucks, \( T = \{1, 2, 3\} \)
2. Stores
The set of stores to be served, \( S = \{1, 2, 3, 4, 5\} \)

Parameter:
1. TruckCapacities
[8, 10, 12]  # Capacity of each truck in tons
2. StoreDemands
[3, 4, 5, 2, 6]  # Demand of each store in tons
3. Distances
[15, 20, 25, 30, 35]  # Distance from DC to each store in km
4. BigM
1000  # A large constant for linearization

Decision variable:
1. TruckUsed
Binary variable \( u_t \in \{0, 1\} \) for all \( t \in T \), where \( u_t = 1 \) if truck \( t \) is used, and \( u_t = 0 \) otherwise
2. StoreAssignment
Binary variable \( x_{st} \in \{0, 1\} \) for all \( s \in S, t \in T \), where \( x_{st} = 1 \) if store \( s \) is assigned to truck \( t \), and \( x_{st} = 0 \) otherwise
3. RouteDistance
Continuous variable \( d_t \geq 0 \) for all \( t \in T \), representing the total distance traveled by truck \( t \)

Objective:
Minimize the total distance traveled by all trucks
min: \sum_{t\in T}d_t

Constraint:
1. Each store must be assigned to exactly one truck
\sum_{t\in T}x_{st} = 1, \forall s \in S
2. Truck capacity cannot be exceeded
\sum_{s\in S}StoreDemands_s \cdot x_{st} \leq TruckCapacities_t, \forall t \in T
3. Distance calculation for each truck (using farthest store visited)
d_t \geq Distances_s \cdot x_{st}, \forall s \in S, t \in T
4. Truck usage constraint (if any store is assigned)
\sum_{s\in S}x_{st} \leq |S| \cdot u_t, \forall t \in T

Type:
Mixed, Linear, Linear
MILP

Gurobi implementation:
import gurobipy as gp
from gurobipy import GRB

def solve_delivery_routing(
    trucks=[1, 2, 3],
    stores=[1, 2, 3, 4, 5],
    truck_capacities={1: 8, 2: 10, 3: 12},
    store_demands={1: 3, 2: 4, 3: 5, 4: 2, 5: 6},
    distances={1: 15, 2: 20, 3: 25, 4: 30, 5: 35}
):
    """
    Solves the delivery routing optimization problem using Gurobi.
    Minimizes total distance traveled by trucks while meeting store demands and truck capacity constraints.
    """
    # Create model
    model = gp.Model("DeliveryRouting")

    # Decision variables
    # Binary variable indicating if truck t is used
    truck_used = model.addVars(trucks, vtype=GRB.BINARY, name="truck_used")
    # Binary variable indicating if store s is assigned to truck t
    store_assignment = model.addVars(stores, trucks, vtype=GRB.BINARY, name="store_assignment")
    # Continuous variable for distance traveled by each truck
    route_distance = model.addVars(trucks, lb=0, vtype=GRB.CONTINUOUS, name="route_distance")

    # Objective: Minimize total distance traveled by all trucks
    model.setObjective(
        gp.quicksum(route_distance[t] for t in trucks),
        GRB.MINIMIZE
    )

    # Constraints
    # 1. Each store must be assigned to exactly one truck
    model.addConstrs(
        (store_assignment.sum(s, '*') == 1 for s in stores),
        name="store_assignment"
    )

    # 2. Truck capacity cannot be exceeded
    model.addConstrs(
        (gp.quicksum(store_demands[s] * store_assignment[s, t] for s in stores) <= truck_capacities[t]
         for t in trucks),
        name="truck_capacity"
    )

    # 3. Distance calculation (truck distance is distance to farthest store visited)
    model.addConstrs(
        (route_distance[t] >= distances[s] * store_assignment[s, t]
         for s in stores for t in trucks),
        name="distance_calc"
    )

    # 4. Truck usage constraint (if any store is assigned to truck)
    model.addConstrs(
        (gp.quicksum(store_assignment[s, t] for s in stores) <= len(stores) * truck_used[t]
         for t in trucks),
        name="truck_usage"
    )

    # Optimize model
    model.optimize()

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


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

Solution status: OPTIMAL
Optimal objective value: 60