Valhalla & Vroom
Introduction
Valhalla
Valhalla is an open source routing engine and accompanying libraries for use with OpenStreetMap data. Valhalla also includes tools like time+distance matrix computation, isochrones, elevation sampling, map matching and tour optimization (Travelling Salesman).
Vroom
VROOM is an open-source optimization engine written in C++20 that aim at providing good solutions to various real-life vehicle routing problems (VRP) within a small computing time. The project has been initiated by Verso to power its route optimization API.
Valhalla's docker packages are no longer maintained in the Docker Hub; instead, beginning from 17.03.2023, Valhalla's Docker packages can be found on their Github page.
| Deployment environment | Nightly | Stable |
|---|---|---|
| Dockerized? | Yes | Yes |
| Location | 2x Valhalla & 1x Vroomattracs.tms.nightly.1GCP Name: att-nightly-tms-backend-1b-nightly2x Valhalla & 1x Vroom attracs.tms.nightly.2GCP Name: att-nightly-tms-backend-1b-nightly |
2x Valhalla & 1x Vroomattracs-frontend-core-3GCP Name: attracs-core-backends-multi-zone-34662x Valhalla & 1x Vroom attracs-frontend-core-3GCP Name: attracs-core-backends-multi-zone-nng82x Valhalla & 1x Vroom tms-valhalla-1 (not in actual use yet) |
Future of Valhalla
Koste has asked if in the future all customers could have their own Valhalla instances, so that each customer can manage the routing weights by themselves.
Also possible avenues of improvements just generally for routing:
Written by AI:
Your current build flags are a great starting point for a lean Valhalla instance focused on Finland for taxi routing. The primary areas for further consideration would be:
1. Traffic Data Integration: If you have access to traffic data, building with build_traffic_speeds=True and feeding that data to Valhalla would be the biggest improvement for ETA accuracy.
2. Fine-tuning costing_options via API: Experiment with use_highways, ferry_cost, and service_penalty in your routing requests to get the most optimal routes for your specific taxi operation in Finland.
3. Real-time Avoidances: Implement the use of avoid_locations or avoid_polygons in your routing requests for dynamic route adjustments based on current road conditions.
By combining efficient data building with flexible runtime API options, you can create a robust and accurate routing solution for your Finnish taxi service.
Installation
attracs-linux-playbooks/docker/docker-valhalla/docker-valhalla.yml
This ansible playbook will install the Valhalla and vroom with the configs defined in the docker-valhalla folder.
attracs-linux-playbooks/docker/docker-valhalla/docker-valhalla/config.yml
This is Vroom config file
attracs-linux-playbooks/docker/docker-valhalla/docker-valhalla/docker-compose.yml
#THIS IS JUST FOR EXAMPLE DON'T USE THIS FOR ANYTHING ELSE, USE .YML FROM REPOSITORY!
version: '3.0'
volumes:
docker-valhalla-1:
docker-valhalla-2:
services:
valhalla-1:
image: ghcr.io/gis-ops/docker-valhalla/valhalla:3.3.0
container_name: valhalla-1
ports:
- "4086:8002"
volumes:
- docker-valhalla-1:/custom_files
environment:
# The tile_file must be located in the `custom_files` folder.
# The tile_file has priority and is used when valid.
# If the tile_file doesn't exist, the url is used instead.
# Don't blank out tile_url when you use tile_file and vice versa.
- tile_urls=https://download.geofabrik.de/europe/finland-latest.osm.pbf
# Get correct bounding box from e.g. https://boundingbox.klokantech.com/
# - min_x=18 # -> Albania | -180 -> World
# - min_y=38 # -> Albania | -90 -> World
# - max_x=22 # -> Albania | 180 -> World
# - max_y=43 # -> Albania | 90 -> World
- use_tiles_ignore_pbf=True
- force_rebuild=False
- force_rebuild_elevation=False
- build_elevation=False
- build_admins=True
- build_time_zones=True
restart: always
valhalla-2:
image: ghcr.io/gis-ops/docker-valhalla/valhalla:3.3.0
container_name: valhalla-2
ports:
- "4087:8002"
volumes:
- docker-valhalla-2:/custom_files
environment:
# The tile_file must be located in the `custom_files` folder.
# The tile_file has priority and is used when valid.
# If the tile_file doesn't exist, the url is used instead.
# Don't blank out tile_url when you use tile_file and vice versa.
- tile_urls=https://download.geofabrik.de/europe/finland-latest.osm.pbf
# Get correct bounding box from e.g. https://boundingbox.klokantech.com/
# - min_x=18 # -> Albania | -180 -> World
# - min_y=38 # -> Albania | -90 -> World
# - max_x=22 # -> Albania | 180 -> World
# - max_y=43 # -> Albania | 90 -> World
- use_tiles_ignore_pbf=True
- force_rebuild=False
- force_rebuild_elevation=False
- build_elevation=False
- build_admins=True
- build_time_zones=True
restart: always
vroom_http:
image: vroomvrp/vroom-docker:v1.12.0
container_name: vroom_http
ports:
- "4108:3000"
volumes:
- ./vroom-conf/:/conf
environment:
- VROOM_ROUTER=valhalla
restart: always
depends_on:
- valhalla-1
logging:
driver: gcplogs
Docker-compose for the Valhalla installation. This contains 2x Valhalla and 1x vroom containers. TMS taxi is using valhalla-1:port to connect to the Valhalla so make sure you use container name valhalla-1 and valhalla-2
Installing new Valhalla instance can be done with command:
ansible-playbook docker/docker-valhalla/docker-valhalla.yml -l tms-valhalla-1
In this example installation is limited to tms-valhalla-1 server. Without -l (limit) ansible playbook will try to install it to all the servers put to hosts: section in the playbook.
Testing
Tailing Container Logs
First, log in to the server. For example, use nightly:
ssh user@attracs.tms.nightly.1- Or, if you're using GCP ssh:
gcloud beta compute ssh att-nightly-tms-backend-1b-nightly --project=att-nightly --tunnel-through-iap
Next, check the containers with:
sudo docker ps -a
You'll see a list of containers.
To follow the logs of a specific container, use this command:
sudo docker logs -f --tail 10 valhalla-1-nightly
This shows you the latest logs for the valhalla-1-nightly container.
Testing CURL
Run this command to test routes:
curl http://localhost:5086/route --data '{"locations":[{"lat":63.535891,"lon":23.687500},{"lat":63.831270,"lon":23.139631}],"costing":"auto","directions_options":{"units":"miles"}}' | jq '.'
Change the coordinates to test different routes. Use a different port to test another Valhalla instance.
TMS taxi testing
TMS has "Optimize route" button which will send query to Valhalla and can be seen from Valhalla logs.
TODO: More testing tips from TMS how to make sure new versions of Valhalla are working correctly.
Troubleshooting
Valhalla is spamming No suitable edges near location
1183 2024/08/14 09:36:37.535674 POST /route HTTP/1.1
2024/08/14 09:36:37.53625 [INFO] Got Loki Request 1183
2024/08/14 09:36:37.56808 [WARN] 400::No suitable edges near location request_id=1183
1183 2024/08/14 09:36:37.568576 400 252
1184 2024/08/14 09:36:38.817411 POST /route HTTP/1.1
2024/08/14 09:36:38.81769 [INFO] Got Loki Request 1184
2024/08/14 09:36:38.82190 [WARN] 400::No suitable edges near location request_id=1184
Possible root causes
Optimization has failed
Sometimes, when you rebuild both of the Valhalla docker containers at the same time, the instance runs out of memory and the process fails quietly. The resulting docker container will still run just fine, but the output will not be correct and logs will get No suitable edges near location spam.