A food delivery platform is facing a shortage of delivery capacity during peak hours. To address this, it plans to adopt a crowdsourcing model by recruiting gig workers ("crowdsourced riders") to complete a portion of the orders. The platform has found that the number of crowdsourced riders willing to accept orders is related to the compensation structure, which consists of a base delivery fee and an additional bonus per order. The specific relationship is modeled as:

Number of available riders = 0.8 * (base delivery fee)² + 17 * (additional bonus)

During the peak period, there are 1,500 orders that need to be delivered by crowdsourced riders., and each available crowdsourced rider can complete an average of 12 orders. The platform earns an average revenue of $15 for each completed order. The platform has two key requirements: 1) A minimum of 1,000 orders must be completed; 2) The base delivery fee offered to riders must be at least $3. The platform needs to design an optimal "base delivery fee + additional bonus" compensation plan to maximize its profit, while ensuring the minimum order completion target is met.

Problem type: NLP (Toy: 3 variables, 0 constraints, 0 nonzeros)

Mathematical model:
Set:
This problem does not involve discrete sets.

Parameter:
1.  TotalOrdersAvailable
    The total number of orders that need to be delivered by crowdsourced riders during the peak period.
    1500
2.  OrdersPerRider
    The average number of orders a single crowdsourced rider can complete.
    12
3.  RevenuePerOrder
    The average revenue the platform earns for each completed order.
    15 # in dollars
4.  MinOrdersRequired
    The minimum number of orders that must be completed.
    1000
5.  MinBaseFee
    The minimum allowed base delivery fee for riders.
    3 # in dollars
6.  RiderModelCoeff_BaseFee
    The coefficient for the base delivery fee in the rider availability model.
    0.8
7.  RiderModelCoeff_Bonus
    The coefficient for the additional bonus in the rider availability model.
    17.0

Decision variable:
1.  BaseFee
    Continuous variable, \( b \), representing the base delivery fee offered per order.
2.  Bonus
    Continuous variable, \( p \), representing the additional bonus offered per order.
3.  OrdersCompleted
    Integer variable, \( c \), representing the total number of orders successfully completed.

Objective:
1.  Maximize the total profit.
    The objective is to maximize the total revenue from completed orders minus the total compensation paid to riders.
    max: \( c \times \text{RevenuePerOrder} - c \times (b + p) \)

Constraint:
1.  Rider Capacity Constraint
    The number of orders completed cannot exceed the total capacity of the available riders. The number of riders is determined by the compensation plan.
    \( c \leq \text{OrdersPerRider} \times (\text{RiderModelCoeff\_BaseFee} \times b^2 + \text{RiderModelCoeff\_Bonus} \times p) \)
2.  Order Availability Constraint
    The number of orders completed cannot be more than the total orders available.
    \( c \leq \text{TotalOrdersAvailable} \)
3.  Minimum Completion Constraint
    The number of completed orders must meet the platform's minimum target.
    \( c \geq \text{MinOrdersRequired} \)
4.  Minimum Fee Constraint
    The base delivery fee must meet the minimum requirement.
    \( b \geq \text{MinBaseFee} \)
5.  Non-negativity Constraint
    The additional bonus cannot be negative.
    \( p \geq 0 \)

Type:
Mixed, Non-linear, Non-linear
NLP

Gurobi implementation:
import gurobipy as gp
from gurobipy import GRB
from typing import Dict

def solve_delivery_optimization(
    TotalOrdersAvailable: int = 1500,
    OrdersPerRider: int = 12,
    RevenuePerOrder: float = 15.0,
    MinOrdersRequired: int = 1000,
    MinBaseFee: float = 3.0,
    RiderModelCoeffs: Dict[str, float] = {'base_fee_sq': 0.8, 'bonus': 17.0}
):
    """
    Solves the food delivery platform's compensation optimization problem.

    Args:
        TotalOrdersAvailable (int): Total orders needing delivery.
        OrdersPerRider (int): Average orders a rider can complete.
        RevenuePerOrder (float): Revenue earned per completed order.
        MinOrdersRequired (int): Minimum number of orders that must be completed.
        MinBaseFee (float): Minimum allowed base delivery fee.
        RiderModelCoeffs (Dict[str, float]): Coefficients for the rider availability model.
    """
    
    # --- Model Initialization ---
    model = gp.Model("DeliveryPlatformOptimization")

    # --- Decision Variables ---
    # base_fee (b): The base delivery fee per order.
    base_fee = model.addVar(name="BaseFee", vtype=GRB.CONTINUOUS, lb=MinBaseFee)
    
    # bonus (p): The additional bonus per order.
    bonus = model.addVar(name="Bonus", vtype=GRB.CONTINUOUS, lb=0.0)
    
    # orders_completed (c): The total number of orders completed.
    orders_completed = model.addVar(
        name="OrdersCompleted", 
        vtype=GRB.INTEGER, 
        lb=MinOrdersRequired, 
        ub=TotalOrdersAvailable
    )

    # --- Objective Function ---
    # Maximize: Total Revenue - Total Rider Payout
    # Maximize: c * RevenuePerOrder - c * (base_fee + bonus)
    total_profit = orders_completed * (RevenuePerOrder - base_fee - bonus)
    model.setObjective(total_profit, GRB.MAXIMIZE)

    # --- Constraints ---
    # Rider Capacity Constraint:
    # Completed orders <= Total rider capacity
    # Rider capacity = (Number of riders) * (Orders per rider)
    # Number of riders = 0.8 * b^2 + 15 * p
    num_riders = RiderModelCoeffs['base_fee_sq'] * base_fee * base_fee + RiderModelCoeffs['bonus'] * bonus
    rider_capacity = num_riders * OrdersPerRider
    model.addConstr(orders_completed <= rider_capacity, "RiderCapacity")

    # --- Solver Configuration ---
    # This is a non-convex quadratic problem (objective and constraint).
    # We must set the 'NonConvex' parameter to 2 for Gurobi to solve it.
    model.setParam('NonConvex', 2)

    # --- 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__":
    # Call the function with the problem's default parameters.
    result = solve_delivery_optimization()
    print(result)


Solution status: OPTIMAL
Optimal objective value: 7871.548039215685