VROOM-Project / pyvroom

Vehicle Routing Open-source Optimization Machine
BSD 2-Clause "Simplified" License
67 stars 14 forks source link

Time Windows example? #63

Closed fpolloa closed 2 years ago

fpolloa commented 2 years ago

Excuse me for bringing this in here, couldn't find a forum where to discuss this.

How would one proceed to solve a CVRP with TW using pyvroom?

Thanks!

jcoupey commented 2 years ago

Did you check the readme example? It looks to me that you should simply adjust how the tasks are defined via vroom.Job.

Constructing a job object happens here in python.

fpolloa commented 2 years ago

Hi jcoupey, thanks for getting back! I'll leave my code for future references.

from __future__ import all_feature_names
import vroom

problem_instance = vroom.Input()
d_matrix = []
for i in N:
    matrix_row = []
    for j in N:
        if i != j:
            matrix_row.append(t_ij[(i,j)])
        else:
            matrix_row.append(0)
    d_matrix.append(matrix_row)

problem_instance.set_durations_matrix(
    profile="truck",
    matrix_input= d_matrix)
for i in range(1,nb_trucks+1):
    problem_instance.add_vehicle([vroom.Vehicle(i, start=0, end=0, capacity=[capa], time_window=(0,T))])

for i in N[1:]:
    problem_instance.add_job([vroom.Job(i, location=i, service=s[i],delivery=[q[i]],time_windows=[vroom.TimeWindow(e[i],l[i])])])

solution = problem_instance.solve(exploration_level=5, nb_threads=4)