File size: 1,149 Bytes
ff39e1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223e856
 
ff39e1a
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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