Route Optimization: Getting Google Cloud and OSRM set up

Driving vs “straight-line” distances

How can you calculate this information?

Introducing Open Source Routing Machine “OSRM”

Now let’s get OSRM installed and set up

Click here for the Docker install tutorial.
$ mkdir -p ~/osrm/maps && cd ~/osrm/maps$ wget https://download.geofabrik.de/north-america-latest.osm.pbf maps/
$ sudo docker pull osrm/osrm-backend
$ gcloud compute instances stop <instance name> --zone <zone>
$ gcloud compute instances start <instance name> --zone <zone>
$ tmux new -s osrm$ cd ~/osrm/maps$ sudo docker run -t -v “${PWD}:/data” osrm/osrm-backend osrm-extract –-threads 8 -p /opt/car.lua /data/north-america-latest.osm.pbf
[error] [exception] std::bad_alloc[error] Please provide more memory or consider using a larger swapfile
$ tmux a -t osrm
$ sudo docker run -t -v “${PWD}:/data” osrm/osrm-backend osrm-contract –-thread 8 /data/north-america-latest.osrm

Using OSRM from the terminal/browser

$ sudo docker run -d -p 80:5000 –-rm –-name osrm -v “${PWD}:/data” osrm/osrm-backend osrm-routed --max-table-size 1000 --algorithm ch /data/north-america-latest.osrm
sudo docker run # run a docker image-d         # run in “detached” mode so the terminal output doesn’t clutter the screen-p 80:5000         # publish the container port (5000) to the host port (80) so the container can communicate with the “outside world”. Remember when we were saying to check the “allow HTTP traffic” box earlier?--rm      # delete the container after exit--name osrm     # name the container “osrm”-v “${PWD}:/data”          # create a filesystem internal to the container with the directory structure “/data” which maps to $PWDosrm/osrm-backend      # the name of the docker imageosrm-routed      # start the OSRM server--max-table-size 1000    # set the max allowed table size to 1000x1000 locations--algorithm ch    # use the contraction hierarchies algorithm/data/north-america-latest.osrm  # use the preprocessed map file we put in the /data directory
$ curl “http://localhost:80/route/v1/driving/-80.868670,35.388501;-80.974886,35.236367?steps=true”
$ export EXTERNAL_IP=$(gcloud compute instances describe <instance name> --zone=<zone> --format=’get(networkInterfaces[0].accessConfigs[0].natIP’)

Understanding OSRM’s services

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store