Skip to content

An example of constructing a VRP request in Python from scratch and returning solve results

License

Notifications You must be signed in to change notification settings

rConger/Esri-Python-VRP-From-Scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Esri-Python-VRP-From-Scratch

An example of constructing a VRP request in Python from scratch and returning solve results

Example VRP Constructed in Scratch using Python

R Conger. January 2024

Requirements:

  • ArcGIS Pro 3.1 or later. If you are using an earlier version of ArcGIS Pro, set vrp_overrides to an empty string in the “Settings Block” configuration mentioned below: e.g. vrp_overrides = ""
  • A local Streetmap Premium network dataset. Please send me a note if you need an example of constructing a request that works with Enterprise or AGOL based service endpoints
  • Network Analyst extension for ArcGIS Pro

What it does:

  1. Reads order and depot input data from plain text CSV files and creates input features from coordinates (Lat/Lon values).
  2. Creates Route records from scratch using parameters from input Orders and Depots along with settings block parameters.
  3. Constructs a VRP and loads input depot, order, and route classes into the VRP.
  4. Solves the VRP.
  5. Outputs successful or failed VRP solve output to disk.

To configure:

Adjust values in the Settings Block to match your local environment. Please start with using the provided Orders and Depot CSV files for testing. You may need to adjust the coordinate values to match locations in your region. This example is in North America. It also assumes you have access to a local copy of the Streetmap data file geodatabase. It would also be possible to configure this script to point to the VRP service hosted by Portal. An example of a Portal-solve configuration can be provided on-request.

To use:

Once the input parameters are adjusted, run the script from an IDE (like Visual Studio Code) or from the command prompt. You’ll need to know where your Python runtime is located to execute the python interpreter. If ArcGIS Pro is installed locally, you can run from the command line as follows:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3>python C:<your project workspace>\VRPFromScratch.py

Output:

The script will create two output objects on success: • C:\temp\scratch.gdb – a file geodatabase containing all input and output generated by the solve. • PythonVRP_Example.lpkx – a layer package from the solve that can be added directly to ArcGIS Pro. Files included:

  1. This file: “VRP_Jumpstart.docx”
  2. The script itself: “VRPFromScratch.py”
  3. Plain text orders: “Orders.csv”
  4. Plain text depots: “Depot.csv”
  5. Empty inputs schemas used by the script: “Templates.gdb”

About

An example of constructing a VRP request in Python from scratch and returning solve results

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages