Created
July 15, 2020 08:00
-
-
Save boxfrommars/da7fdfc916fe0fd1214baefe2323fc77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def build_timeline(builder_input, builder_output, solver_output): | |
solver_input = builder_output['solver_input'] | |
courier_map = {c['index']: c['number'] for c in builder_output['maps']['couriers']} | |
points_map = {p['index']: p for p in builder_output['maps']['waypoints']} | |
approved_points = {p[0] for p in solver_input['vehicles_assigned_to_points']} | |
route_points = [] | |
for driver_ind, route in enumerate(solver_output['routes']): | |
cursor = solver_input['vehicle_shifts'][driver_ind][0] + 1 | |
for i in range(len(route)): | |
dist_to = solver_input['time_matrix'][route[i]][route[i - 1]] if not i == 0 else 0 | |
time_open = solver_input['time_windows'][route[i]][0] | |
time_close = solver_input['time_windows'][route[i]][1] | |
arrived_at = cursor + dist_to | |
time_in = max(arrived_at, time_open) | |
if i < len(route) - 1: | |
time_out = time_in + solver_input['service_times'][route[i]][route[i + 1]] | |
else: | |
time_out = time_in | |
route_points.append({ | |
"order_id": points_map[route[i]]["order_id"], | |
"ind": route[i], | |
"kind": points_map[route[i]]["kind"], | |
"dist_to": dist_to, | |
"arrived_at": arrived_at, | |
"open_at": time_open, | |
"close_at": time_close, | |
"time_in": time_in, | |
"time_out": time_out, | |
"time_wait": time_in - arrived_at, | |
"late": max(time_out - time_close, 0), | |
"s_late": max(time_in - (time_close - 1), 0), | |
"vehicle_id": courier_map[driver_ind], | |
"assigned": route[i] in approved_points | |
}) | |
cursor = time_out | |
return pd.DataFrame(route_points) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment