Skip to main content

Python library for reading vehicle routing problem instances.

Project description

VRPLIB

PyPI version vrplib codecov

vrplib is a Python package for reading Vehicle Routing Problem (VRP) instances. The main features are:

  • reading VRPLIB and Solomon instances and solutions, and
  • downloading instances and best known solutions from CVRPLIB.

Installation

This library works with Python 3.8+ and only depends on numpy. Install the latest version of vrplib:

pip install vrplib

Example usage

Reading instances and solutions

import vrplib

# Read VRPLIB formatted instances (default)
instance = vrplib.read_instance("/path/to/X-n101-k25.vrp")
solution = vrplib.read_solution("/path/to/X-n101-k25.sol")

# Read Solomon formatted instances
instance = vrplib.read_instance("/path/to/C101.txt", instance_format="solomon")
solution = vrplib.read_solution("/path/to/C101.sol") # only 1 solution format

instance and solution are dictionaries that contain all parsed data.

instance.keys()
# dict_keys(['name', 'comment', 'type', 'dimension', ..., 'edge_weight'])

solutions.keys()
# dict_keys(['routes', 'cost'])

Downloading instances from CVRPLIB

import vrplib

instance = vrplib.download_instance("X-n101-k25.vrp")
solution = vrplib.download_solution("X-n101-k25.sol")

# List instance names that can be downloaded 
vrplib.list_names()                      # All instance names
vrplib.list_names(low=100, high=200)     # Instances with between [100, 200] customers
vrplib.list_names(vrp_type='cvrp')       # Only CVRP instances
vrplib.list_names(vrp_type='vrptw')      # Only VRPTW instances

Notes

This section contains additional notes about the vrplib package.

Instance formats

Currently, two VRP instance formats are supported:

  • VRPLIB: this format is most commonly used for Capacitated Vehicle Routing Problem (CVRP) instances. See the X-n101-k25 instance for an example. VRPLIB is an extension of the TSPLIB95 format. Additional information about the VRPLIB format can be found here.
  • Solomon: this format was used to introduce the Solomon instances for the Vehicle Routing Problem with Time Window (VRPTW) and also the extended instance set by Homberger and Gehring. See the C101 instance for an example.

How instances are parsed

vrplib parses an instance and returns a dictionary of keyword-value pairs. There are two types of instance data:

  • Problem specifications, which may contain metadata or problem-specific information such as the max number of vehicles.
  • Problem data, which are often arrays of values describing, for example, customer service times and time windows.

On parsing distances

The vrplib library tries to follow the instance specifications as strictly as possible to compute the distances.

For VRPLIB instances, the distances computation is determined by the EDGE_WEIGHT_TYPE and possibly the EDGE_WEIGHT_FORMAT specifications. We currently support two categories of edge weight types:

  • *_2D: compute the Euclidean distances using the node coordinate data.
    • EUC_2D: Double precision distances without rounding.
    • FLOOR_2D: Round down all distances to down to an integer.
    • EXACT_2D: Multiply the distances by 1000, round to the nearest integer.
  • EXPLICIT: the distance data is explicitly provided, in partial or full form. For explicit matrices, the EDGE_WEIGHT_FORMAT must be specified. We support the following two formats:
    • LOWER_ROW: Lower row triangular matrix without diagonal entries.
    • FULL_MATRIX: Explicit full matrix representation.

More information about how VRPLIB specifications can be found here and here.

Note that there are VRPLIB instances that use different rounding conventions in the literature, which may not be specified in the instance. For example, the X instance set proposed by Uchoa et al. (2017) assumes that the distances are rounded to the nearest integer. When you use the vrplib package to read instances from the X set, it will return unrounded Euclidean distances because the instance specifies the EUC_2D edge weight type, i.e., no rouding. This can be easily solved by rounding the distances matrix manually.

For Solomon-type instances, the distance computation is not specified in the instance file, hence we compute the Euclidean distances without rounding. A recent convention that was proposed during the 2021 DIMACS Vehicle Routing Implementation Challenge is to truncate the Euclidean distances to one decimal. Similar to the X instance set, you can manually modify the distances matrix.

Additional remarks

  • Downloading instances may take up to a few seconds.
  • The XML100 benchmark set is not listed in list_names and cannot be downloaded through this package. You can download these instances directly from CVRPLIB.

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

vrplib-1.0.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

vrplib-1.0.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file vrplib-1.0.0.tar.gz.

File metadata

  • Download URL: vrplib-1.0.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.1 Darwin/21.3.0

File hashes

Hashes for vrplib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cc3984e28e69f3d13693629d09c31d1407121c6d407e821a757ef7ee28ccda50
MD5 07a2440b3f8e373eca758a114f35ec42
BLAKE2b-256 f2bd3dd5441cc0ebe10587c83f37094f8c145e3ec4c2160443cd0ca415357c80

See more details on using hashes here.

File details

Details for the file vrplib-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: vrplib-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.11.1 Darwin/21.3.0

File hashes

Hashes for vrplib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a0a4e0f4b4f5b864a7cf4e31548c6d62acc6302014194f807829f294d5a72e8
MD5 cab899e197966a8fc64ad4b4bfb4a504
BLAKE2b-256 a08d009fe5df24ed453e176eaae66746988fd241fbfa50a86ae6616088969fc9

See more details on using hashes here.

Supported by

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