Skip to main content

Package to use Ortools combine with Osrm for routing

Project description

Routing coverage report

Description

Package to use Ortools combine with Osrm for routing.

Install

  • You should have a OSRM server with the right data section

Options

You can set local search options with params in https://developers.google.com/optimization/routing/routing_options#local_search_options

Usage

  • import package and set the host
from routingoo.routing_data_matrix import RoutingDataMatrix
from routingoo.vrp_solver import VrpSolver

HOST=my_host # eg "localhost:5000" or "router.project-osrm.org"
  • Set location address in one list
add1 = '15 Rue Basse Monaco'
add2 = '1 Avenue des Pins Monaco'
add3 = """ Maison de Stéphanie de Monaco, Avenue Saint-Martin,
Monaco-Ville, Monaco, 98000 """
locations = [add1, add2, add3]
  • Retrive coordinates and distance and duration infos with Nominatim and OSRM
routing_data_matrix = RoutingDataMatrix(host=HOST)
coordinates, points = routing_data_matrix.coordinate_infos(locations)
distance_matrix, duration_matrix = routing_data_matrix.distance_duration_matrix_simple_route(points)
  • Use solver to find a heuristic
num_vehicles = 1
vrp_solver = VrpSolver(num_vehicles)
route = vrp_solver.solver_guided_local_search(distance_matrix, time_max)[0]
  • Retrieve the total distance if needed
total_distance = vrp_solver.compute_total_distance(route, distance_matrix)

Model methods

  • RoutingDataMatrix

    • init(self, host="localhost:5000")
    • coordinate_infos(self, locations)
    • distance_duration_matrix_simple_route(self, points)
  • VrpSolver

    • init(self, num_vehicles)
    • create_data_model(self, distance_matrix)
    • compute_total_distance(self, route, distance_matrix, unite_mesure="m", show_log=False)
    • print_solution(self, manager, routing, solution)
    • get_routes(self, manager, routing, solution)
    • solver_guided_local_search(self, distance_matrix, time_max, heuristic_type="FirstSolutionStrategy", heuristic="PATH_CHEAPEST_ARC",max_travel_distance=False, show_log=False)

Sample for Osrm server with Monaco data on localhost:5OOO

  • Retrieve the data :

wget http://download.geofabrik.de/europe/monaco-latest.osm.pbf

  • Extract data :

docker run -t -v $(pwd):/data osrm/osrm-backend:latest osrm-extract -p /opt/car.lua /data/monaco-latest.osm.pbf

  • Contract data :

docker run -t -v $(pwd):/data osrm/osrm-backend:latest osrm-contract /data/monaco-latest.osrm

  • Run your server on localhost:5000 :

docker run -t -i -p 5000:5000 -v $(pwd):/data osrm/osrm-backend:latest osrm-routed /data/monaco-latest.osrm

Testing

  • use python -m unittest discover -v
  • :warning: the tests use VCR if you want fresh call to Nominatim and Osrm remove the folder vcr_cassettes

Resources :

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

routing-ortools-osrm-1.0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

routing_ortools_osrm-1.0.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file routing-ortools-osrm-1.0.1.tar.gz.

File metadata

  • Download URL: routing-ortools-osrm-1.0.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for routing-ortools-osrm-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7bf24105880178e573d98016362a08a515b386dcbdc5f30018413550f3847b3f
MD5 affcdbef978f3e1acf25ed375a4c4291
BLAKE2b-256 810ddf17a7c95eb96e1a086ab7c2ae228eb6dc54ce5eecf455c27c0cf9c00372

See more details on using hashes here.

File details

Details for the file routing_ortools_osrm-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: routing_ortools_osrm-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for routing_ortools_osrm-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6fb28ccce2f8d75549990239784cf86420c8ab968815d34aad28e418c1eeaf0d
MD5 a137d3236cc0013fa16eb488f621d9d0
BLAKE2b-256 b597bf0088dae4384773fad27f271d13e20cbee51abefb99776b1741efdb2ad6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page