Duplicate Job id error

Hey,

Have setup a local instance of ORS with vroom trying to work on optimization. It is part of a code block that works on a list of coordinates that come from an online file. The code gets split based on areas, but only 1 car will service the areas. There are 6 areas, but the code fails after the first item of the area list throwing the code:2 Duplicate job id: 0. The code block is below:

for i in uni_areas:
    cord_lst = []
    for k in dfs[f'locs_{i}']['locs']:
        k = ast.literal_eval(k)
        cord_lst.append(k)
    cord_lst = [[y, x] for x, y in cord_lst]
    for idx, coord in enumerate(cord_lst):
        jobs.append(optimization.Job(id = idx, location = coord))
    vehicles = [optimization.Vehicle(id = 0, profile = 'driving-car', start = start_loc, end = start_loc)]
    route = vroom.optimization(jobs = jobs, vehicles = vehicles, geometry = True)
    print(route)

I get the below output when the loop moves to the 2nd region:

openrouteservice.exceptions.ApiError: 400 ({‘code’: 2, ‘error’: ‘Duplicate job id: 0.’})

Hi @huzzug,

this is a vroom error. It seems you can’t send jobs with the same id.
with

print([j.id for j in jobs])

directly after the jobs.append line, to check the job ids.

My guess is that it fails in the second uni_area because jobs is defined outside of the outer for loop. So as soon as you are in the second iteration of that loop,
the jobs array already contains jobs with ids, and you are adding more jobs with the same ids.

Best regards

That worked. I missed that when copying code online. Thanks