from vroom import Input, Vehicle, Shipment, ShipmentStep, TimeWindow from datetime import timedelta def calcul_routes(dfp, ladr, mat_dist, mat_dur, durée_max_taxi=45, durée_max_ecole=10, capacité=3): vrm = Input() vrm.set_distances_matrix("car", mat_dist) vrm.set_durations_matrix("car", mat_dur) def deltaepoch(time, deltamin=0): return int((time-timedelta(minutes=deltamin)).timestamp()) def tw(fin, delta): return [TimeWindow(deltaepoch(fin, delta), deltaepoch(fin))] for (irow, row) in dfp.iterrows(): idxp=ladr.index(row["suggestion"]) idxd=ladr.index(row["ECOLE"]) vrm.add_job( Shipment( pickup=ShipmentStep(id=irow, location=idxp, time_windows=tw(row["arrivée_max"], durée_max_taxi)), delivery=ShipmentStep(id=irow, location=idxd, time_windows=tw(row["arrivée_max"], durée_max_ecole)), amount=[1], # skills ) ) vrm.add_vehicle(Vehicle(id=irow, capacity=[capacité], end=idxd)) sol = vrm.solve(exploration_level=20, nb_threads=4) return sol