Skip to main content

A solver for real-time vehicle routing problems

Project description

Online-RTV

Installation

pip install rtv-solver

Code example

Initialize

from rtv_solver import OnlineRTVSolver

# Initialize the RTV solver with the URL of the OSRM server
online_rtv_solver = OnlineRTVSolver("http://127.0.0.1:50000/")

Check feasibility of time slots

payload = {
    "requests": [
    {
        'am': int,
        'wc': int,
        'time_windows' : [
            {'pickup_time_window_start': int, 'pickup_time_window_end': int, 'dropoff_time_window_start': int, 'dropoff_time_window_end': int,},
        ],
        'pickup_pt': {'lat': float, 'lon': float, 'node_id': int},
        'booking_id': int,
        'dropoff_time_window_start': int,
        'dropoff_time_window_end': int,
        'dropoff_pt': {'lat': float, 'lon': float, 'node_id': int}
    }],
    "driver_runs": driver_runs
}

feasibility = online_rtv_solver.check_feasibility(payload)


feasibility <-- [(feasible_window,vmt/pmt ratio)]

Generating a manifest (algorithm automatically selected)

current_time = 5*3600+30*60 # 05:30:00 pm
driver_runs, unserved_requests = online_rtv_solver.solve_pdptw(new_payload)

unserved_requests <-- [list of ids of the requests that are not feasible to serve]

Generating a manifest with RTV algorithm

current_time = 5*3600+30*60 # 05:30:00 pm
driver_runs, unserved_requests = online_rtv_solver.solve_pdptw_rtv(new_payload)

unserved_requests <-- [list of ids of the requests that are not feasible to serve]

Fast option with Insertion Heuristic

driver_runs, unserved_requests = online_rtv_solver.solve_pdptw_heuristic(new_payload)

unserved_requests <-- [list of ids of the requests that are not feasible to serve]

Serve a request as soon as possible

new_payload = {
    "depot": {},
    "requests": [],
    "driver_runs": []
}

driver_runs, unserved_requests = online_rtv_solver.serve_asap(new_payload)

Simulate the vehicles

current_time = 5*3600+40*60+00 # Simulate to 05:40:00 pm
new_driver_runs = online_rtv_solver.simulate_manifest(current_time, driver_runs)

Regenerating a manifest

payload = {
    "driver_runs": driver_runs,
    "depot": depot
}

driver_runs = online_rtv_solver.resolve_pdptw_rtv(payload)

Get stats from the manifest

depot = {
    "pt": {"lat": val, "lon": val}
}

driver_runs <- generated driver runs

feasibility, stats = online_rtv_solver.get_stats(depot, driver_runs)

feasibility {true or false} <- Is this schedule feasibile

stats = {
    "vmt": ,
    "pmt": ,
    "serviced": ,
    "wait_time": [wait time for each request],
    "detour": [detour for each request]
}

Payload format

Common format

{
    
    'depot': {
        'loc': {'lat': float, 'lon': float, 'node_id': int}
    }, 
    'date': 'yyyy-mm-dd', 
    'driver_runs': [],
    'requests': []
    
}

Requests

{
    
    'requests': [ {
        'am': int,
        'wc': int,
        'pickup_time_window_start': int,
        'pickup_time_window_end': int,
        'pickup_pt': {'lat': float, 'lon': float, 'node_id': int},
        'booking_id': int,
        'dropoff_time_window_start': int,
        'dropoff_time_window_end': int,
        'dropoff_pt': {'lat': float, 'lon': float, 'node_id': int}
    }] 
    
}

DriverRun

{
    
    'DriverRun': [ {
        'state': {
            'run_id': int,
            'start_time': int,
            'end_time': int,
            'am_capacity': int,
            'wc_capacity': int,
            'locations_already_serviced': int,
            'locations_dt_seconds': int,
            'loc': {'lat': float, 'lon': float, 'node_id': int},
            'total_locations': int,
        },
        'manifest': Stop[list]
    }] 
    
}

Stop

{
    
    'Stop': [ {
        'run': int,
        'booking_id': int,
        'order': int,
        'action': string,
        'loc': {'lat': float, 'lon': float, 'node_id': int}
        'scheduled_time': int,
        'am': int,
        'wc': int,
        'time_window_start': int,
        'time_window_end': int,
    }] 
    
}

Set up the OSRM Server

wget https://download.geofabrik.de/north-america/us/north-carolina-latest.osm.pbf
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend osrm-extract -p /opt/car.lua /data/north-carolina-latest.osm.pbf || echo "osrm-extract failed"
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend osrm-partition /data/north-carolina-latest.osrm || echo "osrm-partition failed"
docker run -t -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend osrm-customize /data/north-carolina-latest.osrm || echo "osrm-customize failed"
docker run -t -i -p 5000:5000 -v "${PWD}:/data" ghcr.io/project-osrm/osrm-backend osrm-routed --algorithm mld /data/north-carolina-latest.osrm

Building

python -m build
twine upload dist/rtv_solver-[version]*

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

rtv_solver-0.1.42.tar.gz (71.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rtv_solver-0.1.42-py3-none-any.whl (97.2 kB view details)

Uploaded Python 3

File details

Details for the file rtv_solver-0.1.42.tar.gz.

File metadata

  • Download URL: rtv_solver-0.1.42.tar.gz
  • Upload date:
  • Size: 71.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for rtv_solver-0.1.42.tar.gz
Algorithm Hash digest
SHA256 9a7e05b800f9dc104c7c9992553bb574fdca0a115dad9b01028ea255951d22fc
MD5 767161053af7c68c4888afed18b1cee4
BLAKE2b-256 27329d279c6ce2cb18c12f3a9a674b97163c807ce449628d917b05b69928b5b9

See more details on using hashes here.

File details

Details for the file rtv_solver-0.1.42-py3-none-any.whl.

File metadata

  • Download URL: rtv_solver-0.1.42-py3-none-any.whl
  • Upload date:
  • Size: 97.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for rtv_solver-0.1.42-py3-none-any.whl
Algorithm Hash digest
SHA256 852e35d08bd8487fc9bbc0db640675bb8c45d916127c35dfd9c5002264b53571
MD5 6dc4db415caa13ef1957a84637d0ede2
BLAKE2b-256 8179f6357f7cdfbb3cedad1b0cc03255038e51381c9539cb825e239f2472e234

See more details on using hashes here.

Supported by

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