ORS python library for optimization : How to avoid Highways?

Hello there,

I am struggling with an optimization problem. I used this tutorial but I replaced the coordinates with mine : Leverage fleet scheduling for disaster response | Openrouteservice

Everything is working so far, but since my vehicles are tractors (with an average speed of 28 km/h), I MUST avoid Highways. I guess there are multiple workarounds to do so, but I am trying to use the vehicle profile ‘hgv-driving’.

Should it make the trick ? Is there a better altrernative to handle my problem ?

Here is my code, if it is needed :

import os
import requests
import time
import folium
from folium.plugins import BeautifyIcon
import pandas as pd
import openrouteservice as ors

# Get destinations coord
url = 'http://our-api.com/exploitations/latlong'
r = requests.get(url)
exploitations = r.json()
# Get depot coord
url = 'http://our-api.com/biogas/latlong'
r = requests.get(url)
biogas = r.json()

# Set vehicles list
vehicles = list()
for idx in range(3):
            profile='hgv-driving', # Here is my profile
            time_window=[1553241600, 1553284800], # I kept the values of the example

# Set jobs list
deliveries = list()
for index, delivery in enumerate(exploitations):
            location=[delivery[2], delivery[1]],
            amount=[0], # zero for the example
                1553241600,  # I kept the values of the example

# Run optimization
client = ors.Client(key=''private-api-key') 
result = client.optimization(

Thanks in advance for helping !

Let me UP my post :slight_smile:

Hi @julienreichenb,

currently there are no such options for the matrix endopint.
I think there is some an in our backend repo regarding that (matrix with core alt).
But i’m not sure of the status in our live API.

Will check and get back to you
Best regards

Hello @amandus

Thanks for your answer.

I see three acceptable alternatives to solve my problem :

  1. Set a maximum speed constraint of 28km/h
  2. Optimize distance instead of speed
  3. Avoid highways

Is there a way to achieve one of these ? I guess I am not the first one to have that kind of needs but I cannot find a good solution on Google… Any idea ?


none of these solutions is feasible with just the optimization endpoint.

The service running the optimization is VROOM. It uses a time/distance matrix for all locations to calculate the best vehicle-distribution.

The /optimization endpoint internally queries the “/matrix” endpoint and then passes this matrix to VROOM.
This can also be done “manually”, by using the "matrix" parameter to the /optimization endpoint.

When you query the /matrix endpoint “manually”, to expand on what @amandus said, you cannot use any dynamic constraint, so setting “maximum speed” or “avoid higways” is not feasible. What you could do is change the metrics used in matrix calculation to distance and pass that matrix to the optimization endpoint.

There might be other solutions, but that is highly dependent on the size of your problem (i.e., how many locations you’re using). Could you elaborate on that?

Best regards

Hi @jschnell

I am working on clusters of farm parcels of my region, which can contain ~10’000 locations (= parcels), where tractors must spread manure. We want to optimize their paths, knowing that they have an average speed of 28km/h - that’s way they must avoir highways.

Using ORS for Python, I have noticed that the limit is 70 locations per computation. So I guess my approach is not correct…


the limit should be a bit higher - here’s an overview on the number of request you can make per day and minute. You might be running into the minutely timeout.
Check the response for HTTP response code `429 Too Many Requests’ and adapt accordingly.

If not, you might be encountering the api restrictions for single requests listed here.

You’re stating you’re working on “clusters of parcels”, which can contain up to 10’000 parcels. Is this the location for one “cluster”, or is this one dataset consisting of multiple clusters which in total add up to 10’000 locations?

How many jobs were included in your original query?

Best regards