This code implements a mathematical optimization model to solve a transportation problem involving assigning taxis to customer requests. The goal is to maximize a reward function that considers the time taken for a taxi to reach a customer, the customer's waiting time, and the distance traveled.

The code iterates through a list of values for a parameter 'eta', representing the relative importance of customer waiting time in the reward function. For each 'eta' value, the code calculates the reward function and solves the optimization problem using the Gurobi solver. The model's objective is to maximize the reward function while adhering to constraints, such as each taxi being assigned to only one request and vice versa.

The optimization results are stored in an array named 'obj_function_val' and plotted against 'eta' values. This plot reveals how the reward function value changes as the relative importance of customer waiting time varies. The analysis aids in understanding the trade-off between customer satisfaction (waiting time) and taxi efficiency (distance and time traveled).

#analysis - reward fxn vs eta
eta_list = np.round_(np.arange(0, 2.1, 0.1).tolist(), decimals = 2)
obj_function_val = np.array([])

for eta in eta_list:
    customer_waiting_time = deepcopy(pickup_distance)
    for each_taxi in taxi_index:
        for each_request in request_index:
            customer_waiting_time[each_taxi][each_request] = eta * request[each_request]['customer_waiting_time(mins)']
    reward_function = deepcopy(pickup_distance)
    for each_taxi in taxi_index:
        for each_request in request_index:
            reward_function[each_taxi][each_request] = max_pickup_time - pickup_time_in_mins[each_taxi][each_request] + customer_waiting_time[each_taxi][each_request]

    model = Model()
    model.setParam('OutputFlag', 0)

    #variables
    x = model.addVars(taxi_index, request_index, vtype=GRB.BINARY, name='x')
    obj = quicksum(x[i,j] * reward_function[i][j] for i,j in path)
    model.setObjective(obj, GRB.MAXIMIZE)

    for each_taxi in taxi_index:
        for each_request in request_index:
            if (pickup_occupied_CS_distance[each_taxi][each_request] > (taxi[each_taxi]['soc'] * EAV_range)):
                model.addConstr(x[each_taxi, each_request] == 0) #taxi does not accept request if range is not enough
            if(pickup_time_in_mins[each_taxi][each_request] > max_pickup_time):
                model.addConstr(x[each_taxi, each_request] == 0) #taxi does not accept request if pickup time is more than max
            if(customer_waiting_time[each_taxi][each_request] > max_wait_time):
                model.addConstr(x[each_taxi, each_request] == 0) #taxi does not accept request if waiting time is more than max

    model.addConstrs(x.sum(i, '*') <= 1 for i in taxi_index)
    model.addConstrs(x.sum('*', j) <= 1 for j in request_index)

    #solve
    model.optimize()
    # print('Obj:', model.objVal)
    obj_function_val = np.append(obj_function_val, model.objVal)

plt.plot(eta_list, obj_function_val)
plt.xlabel('customer equity trade-off')
plt.ylabel('reward function value')
plt.show()
Analyzing the Impact of Customer Equity on Taxi Dispatch Optimization

原文地址: https://www.cveoy.top/t/topic/m2AI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录