I started vroom + ors, but I cannot use optimization endpoint

Sorry not to bring this backup but i have been trying for hours to get this to work, I should start with my understanding that is somewhat lacking in this field and i want to learn, that being said i have gotten a docker up of ORS locally and can send and receive requests with correct answers which is amazing, however, i am trying to get vroom to work and that is where i am falling short, I have tried to follow all of the above and i just can’t get a 200 health check from vroom no matter what i do, i check the log and all i can see is “GET /health HTTP/1.1” 404 145" I should add i am trying to do this on windows. Is there anyone who can help me please?

do docker ps on yor terminal to see whether the vroom docker image is healthy

I noticed vroom wasn’t using any ports in the ps check so i went back over my config and could see earlier up in the posts before the one i used to setup with that it defined ports with
ports:
- 3000:3000
so i added that and i can now get a 200 reply. Going to see if i can finish up and get a solve with a request, wish me luck!

So If I may ask, i have two issues i was hoping someone could point me in the right direction,

  1. How to allow for a vehicle to be able to return to reload
  2. My fleet as different sizes of vehicles that if course cant fit everywhere, the area in which we are trying to cover in our efforts is somewhat rural and of course do not want to send a 26T or even an Artic somewhere it will get stuck, is there a way for me to make sure this doesn’t happen?
  1. i think this is rather related to vroom which you might find in their docs or discuss in an issue.

  2. Vehicle dimensions currently can’t be passed as they are not available in the matrix endpoint (which vroom uses). But for this as well you should check if there are issues in vroom.

Best regards

hi, i having same issue in after finish installing vroom+ors
this is the docker-compose.yml

version: '3.8'

services:
  # ----------------- ORS application configuration ------------------- #
  ors-app:
    # Activate the following lines to build the container from the repository
    # You have to add --build to the docker compose command to do so
    build:
      context: ./
    container_name: ors-app
    ports:
      - "8080:8082"  # Expose the ORS API on port 8080
      - "9001:9001"  # Expose additional port for monitoring (optional)
    image: openrouteservice/openrouteservice:v8.0.0
    # Advanced option! If you different ids to 0:0 and 1000:1000, you have to rebuild the container with the build args UID,GID.
    # The user command is useful if you want easier bind mount access or better security.
    #user: "1000:1000" # Run "mkdir -p ors-docker/config ors-docker/elevation_cache ors-docker/files ors-docker/graphs ors-docker/logs && sudo chown -R 1000>
    volumes:  # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section>
      - ./ors-docker:/home/ors  # Mount the ORS application directory (for logs, graphs, elevation_cache, etc.) into its own directory
      #- ./graphs:/home/ors/graphs  # Mount graphs directory individually
      #- ./elevation_cache:/home/ors/elevation_cache  # Mount elevation cache directory individually
      #- ./config:/home/ors/config  # Mount configuration directory individually
      #- ./logs:/home/ors/logs  # Mount logs directory individually
      #- ./files:/home/ors/files  # Mount files directory individually
      #- ./indonesia.osm.pbf:/ors-core/data/osm_file.pbf
    environment:
      REBUILD_GRAPHS: False  # Set to True to rebuild graphs on container start.
      CONTAINER_LOG_LEVEL: INFO  # Log level for the container. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL
      # If you don't want the default ors-config.yml you can specify a custom file name, that should match the file in
      # your 'config' volume mount.
      ORS_CONFIG_LOCATION: /home/ors/config/id-ors-config.yml  # Location of your ORS configuration file in the docker container

      # ------------------ JAVA OPTS ------------------ #
      # Configure the memory settings for JAVA or pass additional opts
      # Fore more available ENV properties see Prepare CATALINA_OPTS and JAVA_OPTS
      # in https://github.com/GIScience/openrouteservice/blob/main/docker-entrypoint.sh
      XMS: 4g  # start RAM assigned to java
      XMX: 10g  # max RAM assigned to java. Rule of Thumb: <PBF-size> * <profiles> * 2

  vroom:
    container_name: vroom2
    network_mode: host
    image: vroomvrp/vroom-docker:v1.14.0-rc.1
    volumes:
      - ./vroom-conf/:/conf
    environment:
      - VROOM_ROUTER=ors  # router to use, osrm, valhalla or ors
    depends_on:
      - ors-app

this is the vroom config.yml

cliArgs:
  geometry: false # retrieve geometry (-g)
  planmode: false # run vroom in plan mode (-c) if set to true
  threads: 2 # number of threads to use (-t)
  explore: 5 # exploration level to use (0..5) (-x)
  limit: '1mb' # max request size
  logdir: '/..' # the path for the logs relative to ./src
  logsize: '100M' # max log file size for rotation
  maxlocations: 1000 # max number of jobs/shipments locations
  maxvehicles: 200 # max number of vehicles
  override: true # allow cli options override (-c, -g, -t and -x)
  path: '' # VROOM path (if not in $PATH)
  port: 3000 # expressjs port
  router: 'ors' # routing backend (osrm, libosrm or ors)
  timeout: 300000 # milli-seconds
  baseurl: '/' #base url for api
routingServers:
  osrm:
    car:
      host: '0.0.0.0'
      port: '5000'
    bike:
      host: '0.0.0.0'
      port: '5001'
    foot:
      host: '0.0.0.0'
      port: '5002'
  ors:
    driving-car:
      host: '0.0.0.0'
      port: '8080'
    driving-hgv:
      host: '0.0.0.0'
      port: '8080'
    cycling-regular:
      host: '0.0.0.0'
      port: '8080'
    cycling-mountain:
      host: '0.0.0.0'
      port: '8080'
    cycling-road:
      host: '0.0.0.0'
      port: '8080'
    cycling-electric:
      host: '0.0.0.0'
      port: '8080'
    foot-walking:
      host: '0.0.0.0'
      port: '8080'
    foot-hiking:
      host: '0.0.0.0'
      port: '8080'

vroom is in healthy state

check health via cli

ors status ready

using POST request to get optimization and get 200

but when i using python ors library for optimization,
got error

import folium
import openrouteservice as ors

vroom = ors.Client(base_url='http://localhost:30000')

coords = [
    [106.922564,-6.3866374],
    [106.8754714,-6.2446058],
    [106.9014972,-6.20572789999999],
    [106.9246263,-6.2598575],
    [106.987986,-6.2238243],
    #[106.8939132,-6.2491950],
    [107.0226969,-6.15714039999999],
    #[106.9536585,-6.1905416],
    [107.0263786,-6.2824374],
    [106.9897919,-6.1621882],
    [106.9412024,-6.2448413],
    [106.9845394,-6.1770209],
    [106.9763159,-6.2146392],
    [106.9285088,-6.2250548],
    [107.0431406,-6.28367739999999],
    [106.9402266,-6.2563732],
    [106.9068628,-6.2917713],
    [106.872695,-6.2290735],
    [106.9208421,-6.2214623],
    [106.9079626,-6.292154],
]
vehicle_start = [ 106.913187, -6.227460]
m = folium.Map(location=list(reversed([106.913187, -6.227460])), tiles="cartodbpositron", zoom_start=14)
for coord in coords:
    folium.Marker(location=list(reversed(coord))).add_to(m)
    
folium.Marker(location=list(reversed(vehicle_start)), icon=folium.Icon(color="red")).add_to(m)
m
vehicles = [
    ors.optimization.Vehicle(id=0, profile='driving-car', start=vehicle_start, end=vehicle_start, capacity=[7]),
    ors.optimization.Vehicle(id=1, profile='driving-car', start=vehicle_start, end=vehicle_start, capacity=[7]),
    ors.optimization.Vehicle(id=2, profile='driving-car', start=vehicle_start, end=vehicle_start, capacity=[7]),

]
jobs = [ors.optimization.Job(id=index, location=coords, amount=[1]) for index, coords in enumerate(coords)]
optimized = vroom.optimization(jobs=jobs, vehicles=vehicles, geometry=True)
line_colors = ['green', 'orange', 'blue', 'yellow']
for route in optimized['routes']:
    folium.PolyLine(locations=[list(reversed(coords)) for coords in ors.convert.decode_polyline(route['geometry'])['coordinates']], color=line_colors[route['vehicle']]).add_to(m)
m

error

JSONDecodeError                           Traceback (most recent call last)
File c:\Users\lukman.susanto\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\models.py:971, in Response.json(self, **kwargs)
    970 try:
--> 971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File c:\Users\lukman.susanto\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:

File c:\Users\lukman.susanto\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w)
    333 """Return the Python representation of ``s`` (a ``str`` instance
    334 containing a JSON document).
    335 
    336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

File c:\Users\lukman.susanto\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
...
--> 231     raise exceptions.HTTPError(response.status_code)
    233 # error = body.get('error')
    234 status_code = response.status_code

HTTPError: HTTP Error: 404

is there any mis configuration / missing code?
kindly your help

ps. i use virtual box and port forwarding port 8080 to 8088 and 3000 to 30000
and use visual studio code

thanks
Lukman

Please check if you are using a vroom version after this PR:

If you do, you need to adjust your vroom config.yml accordingly.

i did the change

cliArgs:
  geometry: false # retrieve geometry (-g)
  planmode: false # run vroom in plan mode (-c) if set to true
  threads: 2 # number of threads to use (-t)
  explore: 5 # exploration level to use (0..5) (-x)
  limit: '1mb' # max request size
  logdir: '/..' # the path for the logs relative to ./src
  logsize: '100M' # max log file size for rotation
  maxlocations: 1000 # max number of jobs/shipments locations
  maxvehicles: 200 # max number of vehicles
  override: true # allow cli options override (-c, -g, -t and -x)
  path: '' # VROOM path (if not in $PATH)
  port: 3000 # expressjs port
  router: 'ors' # routing backend (osrm, libosrm or ors)
  timeout: 300000 # milli-seconds
  baseurl: '/optimization/' #base url for api
routingServers:
  osrm:
    car:
      host: '0.0.0.0'
      port: '5000'
    bike:
      host: '0.0.0.0'
      port: '5001'
    foot:
      host: '0.0.0.0'
      port: '5002'
  ors:
    driving-car:
      host: '0.0.0.0/ors/v2'
      port: '8080'
    driving-hgv:
      host: '0.0.0.0/ors/v2'
      port: '8080'
    cycling-regular:
      host: '0.0.0.0/ors/v2'
      port: '8080'
    cycling-mountain:
      host: '0.0.0.0/ors/v2'
      port: '8080'

but still facing error

client = ors.Client(base_url='http://localhost:3000/optimization/')

coords = [
    [106.922564,-6.3866374],
    [106.8754714,-6.2446058],
    [106.9014972,-6.20572789999999],
    [106.9246263,-6.2598575],
    [106.987986,-6.2238243],
    #[106.8939132,-6.2491950],
    [107.0226969,-6.15714039999999],
    #[106.9536585,-6.1905416],
    [107.0263786,-6.2824374],
    [106.9897919,-6.1621882],
    [106.9412024,-6.2448413],
    [106.9845394,-6.1770209],
    [106.9763159,-6.2146392],
    [106.9285088,-6.2250548],
    [107.0431406,-6.28367739999999],
    [106.9402266,-6.2563732],
    [106.9068628,-6.2917713],
    [106.872695,-6.2290735],
    [106.9208421,-6.2214623],
    [106.9079626,-6.292154],
]
vehicle_start = [ 106.913187, -6.227460]
m = folium.Map(location=list(reversed([106.913187, -6.227460])), tiles="cartodbpositron", zoom_start=14)
for coord in coords:
    folium.Marker(location=list(reversed(coord))).add_to(m)
    
folium.Marker(location=list(reversed(vehicle_start)), icon=folium.Icon(color="red")).add_to(m)
m
vehicles = [
    ors.optimization.Vehicle(id=0, profile='driving-car', start=vehicle_start, end=vehicle_start, capacity=[7]),
    ors.optimization.Vehicle(id=1, profile='driving-car', start=vehicle_start, end=vehicle_start, capacity=[7]),
    ors.optimization.Vehicle(id=2, profile='driving-car', start=vehicle_start, end=vehicle_start, capacity=[7]),

]
jobs = [ors.optimization.Job(id=index, location=coords, amount=[1]) for index, coords in enumerate(coords)]
optimized = client.optimization(jobs=jobs, vehicles=vehicles, geometry=True)
line_colors = ['green', 'orange', 'blue', 'yellow']
for route in optimized['routes']:
    folium.PolyLine(locations=[list(reversed(coords)) for coords in ors.convert.decode_polyline(route['geometry'])['coordinates']], color=line_colors[route['vehicle']]).add_to(m)
m

JSONDecodeError                           Traceback (most recent call last)
File c:\Users\lukman.susanto\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\models.py:971, in Response.json(self, **kwargs)
    970 try:
--> 971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File c:\Users\lukman.susanto\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:

File c:\Users\lukman.susanto\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w)
    333 """Return the Python representation of ``s`` (a ``str`` instance
    334 containing a JSON document).
    335 
    336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

File c:\Users\lukman.susanto\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
...
--> 231     raise exceptions.HTTPError(response.status_code)
    233 # error = body.get('error')
    234 status_code = response.status_code

HTTPError: HTTP Error: 404

kindly your help.
thanks

It seems you have configured osrm instead of ors as routing server for vroom.

hi, @sascha

i use ors tho in the router
as for orsm i just leave as it is.

and set

ors:
    driving-car:
      host: '0.0.0.0/ors/v2'
      port: '8080'

ors status

vroom health

Sorry, the ors-part was cut off in my browser.

Hi @Lukman_Susanto,

hmm i’m not sure your usage of the ors-js package is correct.

Maybe try like this: GitHub - GIScience/openrouteservice-js: 📌 The JavaScript API to consume openrouteservice(s) painlessly!
but with optimization

Hi @amandus
sorry i forget to mention i using ors python-package

i follow this document to install and trying the package
https://openrouteservice-py.readthedocs.io/en/latest/

with use local ORS Instance

coords = ((106.9897919,-6.1621882),(106.913187, -6.227460))

# key can be omitted for local host
client = ors.Client(base_url='http://localhost:8080/ors')

# Only works if you didn't change the ORS endpoints manually
routes = client.directions(coords)

print(routes)

result

now i want to use optimization from optimization library.

hope this additional info make it clear.

UPDATE:

I trying again from the document and it seems, the base url has to use vroom url and it run nicely.

from openrouteservice import Client, optimization

coordinates = [[107.0263786,-6.2824374], [106.913187, -6.227460]]
jobs, vehicles = list(), list()
for idx, coord in enumerate(coordinates):
  jobs.append(optimization.Job(id=idx, location=coord))
  vehicles.append(optimization.Vehicle(id=idx, start=[106.913187, -6.227460]))
api = Client(base_url='http://localhost:3000')
result = api.optimization(jobs=jobs, vehicles=vehicles)

print (result)

i will seek into my code.

thank you for your assistance…

hi @amandus @sascha
I successfully using the optimization on the libary

import folium
import openrouteservice as ors
from openrouteservice import Client, optimization
import requests

coordinates = [
  [106.922564,-6.3866374],
    [106.8754714,-6.2446058],
    [106.9014972,-6.20572789999999],
    [106.9246263,-6.2598575],
    [106.987986,-6.2238243],
    [107.0226969,-6.15714039999999],
    [107.0263786,-6.2824374],
    [106.9897919,-6.1621882],
    [106.9412024,-6.2448413],
    [106.9845394,-6.1770209],
    [106.9763159,-6.2146392],
    [106.9285088,-6.2250548],
    [107.0431406,-6.28367739999999],
    [106.9402266,-6.2563732],
    [106.9068628,-6.2917713],
    [106.872695,-6.2290735],
    [106.9208421,-6.2214623],
    [106.9079626,-6.292154]
]
jobs, vehicles = list(), list()
vehicle_start = [106.913187, -6.227460]
for idx, coord in enumerate(coordinates):
  jobs.append(optimization.Job(id=idx, location=coord,amount=[1]))

cap = 5

vehicles = [
    optimization.Vehicle(id=0, profile='driving-car', start=vehicle_start, capacity=[cap]),
    optimization.Vehicle(id=1, profile='driving-car', start=vehicle_start, capacity=[cap]),
    optimization.Vehicle(id=2, profile='driving-car', start=vehicle_start, capacity=[cap]),
    optimization.Vehicle(id=3, profile='driving-car', start=vehicle_start, capacity=[cap]),
    optimization.Vehicle(id=4, profile='driving-car', start=vehicle_start, capacity=[cap]),

]

api = Client(base_url='http://localhost:3000')
result = api.optimization(jobs=jobs, vehicles=vehicles, geometry=True)

m = folium.Map(location=list(reversed(vehicle_start)), tiles="cartodbpositron", zoom_start=14)
for coord in coordinates:
    folium.Marker(location=list(reversed(coord))).add_to(m)
    
folium.Marker(location=list(reversed(vehicle_start)), icon=folium.Icon(color="red")).add_to(m)
m

line_colors = ['red', 'green', 'orange', 'blue', 'yellow']
for route in result['routes']:
    folium.PolyLine(locations=[list(reversed(coordinates)) for coordinates in ors.convert.decode_polyline(route['geometry'])['coordinates']], color=line_colors[route['vehicle']]).add_to(m)
m

here my sample code.
hope help others to use optimization using python

thank you

1 Like