Route optimization with multiple vehicles and traffic

Hi there,

I am new to routing / optimization and a bit lost with all the APIs available with Graphhopper. I hope i can get some guidance from the community.

I am building a solution for countryside veterinarians to optimize their route when going in remote areas.

The inputs:

  • A list of clients to visit (already geocoded)
    
  • A departure time and date
    
  • An average time spent at client location
    
  • A number of veterinary/vehicles 
    

The expected result:

  • The best route to visit all of the listed client
    
  • An estimated arrival time for each client location (taking into consideration the time spent at previous client location and ideally the traffic based on date and time)
    

Requirements:

  • When sending the location of each client, we need to be able to provide an ID with it so when displaying the results on the website/app we can display them using their name and not lat/long.
    

Is that feasible with Graphhopper ? Which API should i use ?

Thanks for your help,

Hi Edouard,
Actually what you would need is the ‘route optimization api’. Thats the api that can create multiple routes based on the vehicles available and delivery/pickup specifications.
Documentation can be found here:
Documentation - GraphHopper Directions API
This is a perfect use case for it :slight_smile:
If you have more specific questions, be happy to help.

1 Like

@Anthony i have a specific case as below.

  1. 100 drop points.
  2. far end of the points would be around 30 km.
  3. 10 vehicles would be there.

my issue is that optimization api doesn’t use all of 10 vehicles. if it finds a way to use say 5 vehicles, it returns that which is great for some use cases, but not for us… is there any solution to this problem?

There are several ways to do that:

  • You can use the objective “min-max” which tries to minimize the longest route, e.g. by adding another vehicle
  • You can specify “min_jobs”, e.g. “min_jobs”: 5 for each vehicle. It then tries to assign at least 5 jobs to each vehicle
  • You can constraint your problem by specifying “max_jobs” (e.g. “max_jobs”: 10 for your example) or you can limit the operating time of your vehicles or their capacity

Maybe @Anthony even knows another way.

1 Like

Thanks for your answer, from what i see the Route Optimization API only returns some information such as cost, completion time, distance …
What i need is a multiple stop routing.

thanks for that @stefan ,do you have any sample requests for this

Now I don’t know exactly what you mean by multiple stop routing, but the Route Optimization API basically does the following: Assuming you have only one driver and an unordered list of stops that the driver should drive to. You send the driver and this list to the Optimization API and get back a sorted list of stops or a route. This is usually the route where the total cost (consisting of transport time and distance) is as low as possible (optimally, the total cost is even minimized). And if you want to have the route geometry for this route, you can also get it.
You can also solve problems with multiple vehicles. Then you get not only one, but for each vehicle a route.

Here is an example with “min_jobs”: min-jobs-example.json · GitHub

You should get a nice solution with 10 vehicles. If you remove “min_jobs”, you should get a solution with 1 or 2 vehicles.

there is some issue. using that json file i got error

‘{“message”:“com.fasterxml.jackson.core.JsonParseException: Unrecognized token ‘objectives’: was expecting (JSON String, Number, Array, Object or token ‘null’, ‘true’ or ‘false’)\n at [Source: (String)\“objectives=type&objectives=value&vehicles=vehicle_id&vehicles=start_address&vehicles=type_id&vehicles=earliest_start&vehicles=latest_end&vehicles=min_jobs&vehicles=vehicle_id&vehicles=start_address&vehicles=type_id&vehicles=earliest_start&vehicles=latest_end&vehicles=min_jobs&vehicles=vehicle_id&vehicles=start_address&vehicles=type_id&vehicles=earliest_start&vehicles=latest_end&vehicles=min_jobs&vehicles=vehicle_id&vehicles=start_address&vehicles=type_id&vehicles=earliest_start&vehicles=latest_e\”[truncated 10496 chars]; line: 1, column: 11]”}’

removed objective(which is essential for the test) got the below error.
'{“message”:"com.fasterxml.jackson.core.JsonParseException: Unrecognized token ‘vehicles’:

I am using python requests library (which is for unix curl command i believe)
url=‘https://graphhopper.com/api/1/vrp?key=api-key
val = requests.post(url,data=input_jason,headers={‘Content-Type’: ‘application/json’})

it is resolved. i had to use json.dumps the value. thanks for the time!

AFAIK Stefan’s answer covers all possible options. :slight_smile: