CargoLink Logistics operates two types of delivery vehicles: Type X and Type Y. New environmental regulations require that the average carbon emissions of all vehicles deployed over the next three years cannot exceed 40 grams per kilometer annually. Each Type X vehicle generates $25,000 in revenue, costs $18,000 to operate, and emits 70 grams of carbon per kilometer. Each Type Y vehicle generates $20,000 in revenue, costs $16,000 to operate, and emits 30 grams of carbon per kilometer. Due to fleet capacity constraints, CargoLink can deploy a maximum of 400 vehicles each year. The maximum number of each vehicle type that can be deployed annually is shown in the table below. For example, at most, 350 Type X vehicles can be deployed in year 3. How can CargoLink Logistics maximize its total profit over the next three years while complying with environmental regulations?

| Year | Maximum Type X Vehicles | Maximum Type Y Vehicles |  
|------|--------------------------|--------------------------|  
| 1    | 300                      | 250                      |  
| 2    | 320                      | 280                      |  
| 3    | 350                      | 300                      |

Problem type: ILP (Small: 6 variables, 12 constraints, 18 nonzeros)

Mathematical model:
Set:
1. VehicleType
The set of vehicle types, \( V = \{1, 2\} \)  # 1: Type X, 2: Type Y
2. Year
The set of years, \( Y = \{1, 2, 3\} \)  # 1: Year 1, 2: Year 2, 3: Year 3

Parameter:
1. AvgCarbonEmissionLimit
40  # in grams per kilometer
2. RevenuePerVehicle
[25000, 20000]  # in dollars
3. OperatingCostPerVehicle
[18000, 16000]  # in dollars
4. CarbonEmissionPerVehicle
[70, 30]  # in grams per kilometer
5. MaxVehiclesPerYear
[[300, 320, 350], [250, 280, 300]] 
6. MaxTotalVehicles
400  # in vehicles

Decision variable:
1. VehiclesDeployed
Integer variable, \( VehiclesDeployed[v][y] \forall v \in V, y \in Y \), the number of vehicles of type \( v \) deployed in year \( y \).

Objective:
1. Maximize the total profit.
max: \sum_{v \in V, y \in Y} (RevenuePerVehicle[v] * VehiclesDeployed[v][y] - OperatingCostPerVehicle[v] * VehiclesDeployed[v][y])

Constraint:
1. Carbon emissions constraint.
\sum_{v \in V} (CarbonEmissionPerVehicle[v] * VehiclesDeployed[v][y]) \leq AvgCarbonEmissionLimit * \sum_{v \in V} VehiclesDeployed[v][y] \forall y \in Y
2. Fleet capacity constraint.
\sum_{v \in V} VehiclesDeployed[v][y] \leq MaxTotalVehicles \forall y \in Y
3. Yearly vehicle limit constraint.
\sum_{v \in V} VehiclesDeployed[v][y] \leq MaxVehiclesPerYear[v][y] \forall v \in V, y \in Y
4. Non-negativity constraint.
VehiclesDeployed[v][y] \geq 0 \forall v \in V, y \in Y

Type:
Integer, Linear, Linear
ILP

Gurobi implementation:
import gurobipy as gp
from gurobipy import GRB


def solve_fleet_optimization(
    avg_carbon_emission_limit=40,
    revenue_per_vehicle=[25000, 20000],
    operating_cost_per_vehicle=[18000, 16000],
    carbon_emission_per_vehicle=[70, 30],
    max_vehicles_per_year=[[300, 320, 350], [250, 280, 300]],
    max_total_vehicles=400
):
    """
    Models and solves the fleet optimization problem.
    """
    # Create a new model
    model = gp.Model("Fleet_Optimization")

    # Define sets
    V = range(2)  # Vehicle types: 0=Type X, 1=Type Y
    Y = range(3)  # Years: 0=Year 1, 1=Year 2, 2=Year 3

    # Decision variables
    vehicles_deployed = {}
    for v in V:
        for y in Y:
            vehicles_deployed[v, y] = model.addVar(
                vtype=GRB.INTEGER,
                lb=0,
                name=f"VehiclesDeployed_{v}_{y}"
            )

    # Objective function: Maximize total profit
    profit = gp.quicksum(
        (revenue_per_vehicle[v] - operating_cost_per_vehicle[v]) * vehicles_deployed[v, y]
        for v in V for y in Y
    )
    model.setObjective(profit, GRB.MAXIMIZE)

    # Constraint 1: Carbon emissions constraint
    for y in Y:
        total_vehicles = gp.quicksum(vehicles_deployed[v, y] for v in V)
        total_emissions = gp.quicksum(carbon_emission_per_vehicle[v] * vehicles_deployed[v, y] for v in V)
        model.addConstr(
            total_emissions <= avg_carbon_emission_limit * total_vehicles,
            name=f"CarbonEmissions_Year_{y}"
        )

    # Constraint 2: Fleet capacity constraint
    for y in Y:
        model.addConstr(
            gp.quicksum(vehicles_deployed[v, y] for v in V) <= max_total_vehicles,
            name=f"FleetCapacity_Year_{y}"
        )

    # Constraint 3: Yearly vehicle limit constraint
    for v in V:
        for y in Y:
            model.addConstr(
                vehicles_deployed[v, y] <= max_vehicles_per_year[v][y],
                name=f"YearlyVehicleLimit_Type_{v}_Year_{y}"
            )

    # Solve the 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_fleet_optimization()
    print(result)


Solution status: OPTIMAL
Optimal objective value: 5252000