Skip to main content

Python wrapper for the AILS-II metaheuristic (INFORMS JoC 2023) for the Capacitated Vehicle Routing Problem

Project description

PyAILSII

CI

A Python wrapper for the AILS-II Capacitated Vehicle Routing Problem solver.

PyAILSII provides a thin Python interface to the AILS-II metaheuristic (Máximo, Cordeau, Nascimento, INFORMS JoC 2023; upstream source at INFORMSJoC/2023.0106).

The public API deliberately mirrors PyHygese (a sibling wrapper around HGS-CVRP), so you can compare or swap solvers by changing only the import.

Install

pip install ailsii
  • Build-time requirements: a JDK with javac and jar on PATH. The install step downloads the upstream Java sources, compiles them, and bundles the resulting AILSII.jar into the package. On macOS, brew install openjdk is enough; on Debian/Ubuntu, sudo apt install default-jdk.
  • Runtime requirement: a JRE on PATH. Once installed, PyAILSII shells out to java -jar for each solve.

Quick start

import ailsii

data = {
    "x_coordinates": [0.0, 1.0,  1.0, -1.0, -1.0, 0.5, -0.5],
    "y_coordinates": [0.0, 1.0, -1.0,  1.0, -1.0, 0.0,  0.0],
    "demands":       [0,   3,    3,    3,    3,    3,    3],
    "vehicle_capacity": 9,
}

params = ailsii.AlgorithmParameters(timeLimit=2.0, rounded=False)
solver = ailsii.Solver(parameters=params, verbose=True)
result = solver.solve_cvrp(data)

print("cost:", result.cost)
print("routes:", result.routes)  # customer ids in the input dict's index space; depot (0) excluded

Solving a CVRPLIB instance

Standard benchmark instances from CVRPLIB ship in TSPLIB CVRP format (.vrp files). The vrplib package reads them into NumPy-friendly dicts whose layout maps directly onto PyAILSII's input shape.

pip install vrplib
import urllib.request
import vrplib
import ailsii

# Grab a benchmark instance. The AILS-II authors' INFORMSJoC companion repo
# mirrors all CMT and Uchoa X instances at predictable raw URLs; CVRPLIB itself
# is also fine if you already have the file locally.
url = "https://raw.githubusercontent.com/INFORMSJoC/2023.0106/main/data/CMT1.vrp"
urllib.request.urlretrieve(url, "CMT1.vrp")

# vrplib returns coordinates as an (n, 2) ndarray with the depot at index 0,
# which is exactly the layout PyAILSII expects.
instance = vrplib.read_instance("CMT1.vrp")

data = {
    "x_coordinates": instance["node_coord"][:, 0],
    "y_coordinates": instance["node_coord"][:, 1],
    "demands":       instance["demand"],
    "vehicle_capacity": instance["capacity"],
}

params = ailsii.AlgorithmParameters(timeLimit=10.0, rounded=False)
result = ailsii.Solver(parameters=params, verbose=True).solve_cvrp(data)

print(f"cost: {result.cost:.4f}  (CMT1 best-known: 524.61)")
print(f"routes: {result.routes}")
print(f"time: {result.time} sec")

Use rounded=True for the X benchmark suite (Uchoa et al.), which is defined on rounded integer Euclidean distances; use rounded=False for the CMT and classic instances, which use real-valued distances.

Input data shape

PyAILSII v1 supports coordinate input only (TSPLIB EUC_2D). The expected dict keys match PyHygese's:

key required meaning
x_coordinates, y_coordinates yes length-n sequences; index 0 is the depot
demands yes length-n; demands[0] must be 0
vehicle_capacity yes homogeneous integer capacity
depot optional must be 0 (AILS-II requires the depot at index 0)

Passing distance_matrix raises NotImplementedError — explicit distance-matrix support (TSPLIB EDGE_WEIGHT_TYPE: EXPLICIT) is on the roadmap. For arbitrary cost matrices today, use PyHygese.

Algorithm parameters

ailsii.AlgorithmParameters(
    timeLimit=10.0,           # -limit  (seconds when stoppingCriterion="Time")
    stoppingCriterion="Time", # or "Iteration"
    rounded=True,             # -rounded  (Euclidean distances rounded to int)
    best=None,                # -best     (best-known value; for gap reporting only)
    varphi=40,                # -varphi   (k-NN granular set size)
    gamma=30,                 # -gamma    (iterations between ω adjustments)
    dMax=30,                  # -dMax     (initial reference perturbation degree)
    dMin=15,                  # -dMin     (final reference perturbation degree)
)

Field names track the upstream Java CLI flags so the original paper's parameter discussion applies unchanged. AILS-II's CLI is documented in the upstream README.

Result shape

@dataclass
class RoutingSolution:
    cost: float          # best objective value found
    time: float          # AILS-II's own clock (seconds)
    n_routes: int        # number of vehicle routes
    routes: list[list[int]]  # customer ids per vehicle (input dict index space); depot (0) excluded

This matches PyHygese's RoutingSolution so user code is portable between the two packages.

How it works

PyAILSII wraps a java -jar subprocess. The bundled JAR is built from upstream Java sources at install time with one tiny wrapper class added (AILSIIEntry.AILSIIMain) whose only purpose is to print the final routes between sentinel markers — upstream's own main prints progress metrics but not the resulting routes, so the Python wrapper has nothing to parse without this shim.

The PyPI distribution and Python import name is ailsii (lowercase). Whenever this README refers to "PyAILSII," it means the project / repo; code always uses import ailsii.

Citing

If you use PyAILSII in academic work, please cite the upstream paper:

@article{Maximo2024AILSII,
  author  = {V. R. M{\'a}ximo and J.-F. Cordeau and M. C. V. Nascimento},
  title   = {AILS-II: An Adaptive Iterated Local Search Heuristic for the Large-Scale Capacitated Vehicle Routing Problem},
  journal = {INFORMS Journal on Computing},
  year    = {2024},
  doi     = {10.1287/ijoc.2023.0106}
}

License

MIT, with upstream attribution preserved. See LICENSE.

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

ailsii-0.1.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

ailsii-0.1.0-py3-none-any.whl (77.7 kB view details)

Uploaded Python 3

File details

Details for the file ailsii-0.1.0.tar.gz.

File metadata

  • Download URL: ailsii-0.1.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ailsii-0.1.0.tar.gz
Algorithm Hash digest
SHA256 879111d47e8a8e053be92baac808d92138206606b0d7f10979264eec5c653ccf
MD5 0d62eebe830dbf1dfa4b94362183f4ba
BLAKE2b-256 22b7ae40fe484c4a1d15aa79bc4031d685a2def5ecd0852434b41885d225be2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ailsii-0.1.0.tar.gz:

Publisher: release.yml on chkwon/PyAILSII

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ailsii-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ailsii-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 77.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ailsii-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8458d5a8d3d1063d98ec892455e23b921207383a2858d4d525c4a3ad0e59c2d
MD5 5129139072041cee9d5fdc3f33898f27
BLAKE2b-256 0a534a9f9865091a31c083fe6666ebb38ab3864cb8e7ab5519c79feab8847fd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ailsii-0.1.0-py3-none-any.whl:

Publisher: release.yml on chkwon/PyAILSII

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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