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

# Download the instance and solution to a local file
vrplib.download_instance("X-n101-k25", "/path/to/X-n101-k25.vrp")
vrplib.download_solution("X-n101-k25", "/path/to/X-n101-k25.sol")

# List all 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.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

vrplib-1.0.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vrplib-1.0.1.tar.gz
  • Upload date:
  • Size: 18.8 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.1.tar.gz
Algorithm Hash digest
SHA256 3076eff6630d116bc4bc7cc917e7ce582ba82fa0bcc4535d2920f518483192c1
MD5 557191e50548b9d205574f2423a593c1
BLAKE2b-256 830390b9eb264c4f7562651b15af9c893b8fe9a2bd5250182e8da442f10cf520

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vrplib-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a79c70836b99e11e8b887ff49d762c0d594f8a386bd8749bae9112ad0869d5f1
MD5 a265acfcdf90b4edd745919c844b4994
BLAKE2b-256 b0868c0a7d27c891d4eea0d56e6c6652848ddb70a4cfa0b8fd869ce5e89f820a

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