Skip to main content

A library for performing fast random insertion on TSP and SHPP instances

Project description

random-insertion

PyPI PyPI - Wheel GitHub Repo stars

random-insertion is a Python library for performing fast random insertion on TSP (Travelling Salesman Problem) and SHPP (Shortest Hamiltonian Path Problem) instances, originally a part of the GLOP* codebase.

* Ye, H., Wang, J., Liang, H., Cao, Z., Li, Y., & Li, F. (2024). GLOP: Learning Global Partition and Local Construction for Solving Large-Scale Routing Problems in Real-Time. Proceedings of the AAAI Conference on Artificial Intelligence, 38(18), 20284-20292. https://doi.org/10.1609/aaai.v38i18.30009

Installation

Supported environments

  • python >= 3.7
  • numpy >= 1.21
  • Linux and Windows

Install from PyPI

$ pip install random-insertion

Build from source

$ git clone https://github.com/Furffico/random-insertion.git
$ cd random-insertion
$ pip install . # add `-e` for development mode

Usages

For performing random insertion on multiple TSP instances in parallel:

import numpy as np
import random_insertion as insertion

problem_scale = 50
num_instances = 10
coordinates = np.random.randn(num_instances, problem_scale, 2)
routes = insertion.tsp_random_insertion_parallel(coordinates, threads=4)
for route in routes:
    print(*route)

Despite the name, the program itself is deterministic in nature. Given the same instances and insertion orders, the program will output identical routes. If you would like to add stochasticity to the outputs, please provide shuffled insertion orders like this:

...
coordinates = np.random.randn(1, problem_scale, 2).repeat(num_instances, 0)
orders = np.arange(problem_scale, dtype=np.uint32).reshape(1, -1).repeat(num_instances, 0)
for i in range(num_instances):
    np.random.shuffle(orders[i])
routes = insertion.tsp_random_insertion_parallel(coordinates, orders)

Available methods

# Recommended (threads=0 to automatically determine suitable values):
routes = tsp_random_insertion_parallel(coords, orders, threads=0)
routes = shpp_random_insertion_parallel(coords, orders, threads=0)
routes = atsp_random_insertion_parallel(distances, orders, threads=0)
routes = ashpp_random_insertion_parallel(distances, orders, threads=0)
routes = cvrp_random_insertion_parallel(coords, depot_coords, demands, capacity, order, threads=0)

# For backward compatibility with GLOP:
route, cost = tsp_random_insertion(coords, order)
route, cost = atsp_random_insertion(distances, order)
route = cvrp_random_insertion(coords, depot_pos, demands, capacity, order)
route = cvrplib_random_insertion(coords, demands, capacity, order)

Running tests

$ git clone https://github.com/Furffico/random-insertion.git
$ cd random-insertion
$ pip install -e . pytest
$ pytest                  # run tests

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

random_insertion-0.3.0.post1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distributions

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

random_insertion-0.3.0.post1-cp313-cp313-win_amd64.whl (23.7 kB view details)

Uploaded CPython 3.13Windows x86-64

random_insertion-0.3.0.post1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

random_insertion-0.3.0.post1-cp312-cp312-win_amd64.whl (23.7 kB view details)

Uploaded CPython 3.12Windows x86-64

random_insertion-0.3.0.post1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

random_insertion-0.3.0.post1-cp311-cp311-win_amd64.whl (23.7 kB view details)

Uploaded CPython 3.11Windows x86-64

random_insertion-0.3.0.post1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

random_insertion-0.3.0.post1-cp310-cp310-win_amd64.whl (23.7 kB view details)

Uploaded CPython 3.10Windows x86-64

random_insertion-0.3.0.post1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

random_insertion-0.3.0.post1-cp39-cp39-win_amd64.whl (23.8 kB view details)

Uploaded CPython 3.9Windows x86-64

random_insertion-0.3.0.post1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

random_insertion-0.3.0.post1-cp38-cp38-win_amd64.whl (23.6 kB view details)

Uploaded CPython 3.8Windows x86-64

random_insertion-0.3.0.post1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

random_insertion-0.3.0.post1-cp37-cp37m-win_amd64.whl (23.1 kB view details)

Uploaded CPython 3.7mWindows x86-64

random_insertion-0.3.0.post1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (208.0 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

File details

Details for the file random_insertion-0.3.0.post1.tar.gz.

File metadata

  • Download URL: random_insertion-0.3.0.post1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for random_insertion-0.3.0.post1.tar.gz
Algorithm Hash digest
SHA256 275f05a97df6bbfdb6d39bf41314257c9b1d227b4f0271b8276c155d996f3b0d
MD5 671e4f42ddfc22b15df17eed1cf68ad3
BLAKE2b-256 6161147bbacfccdf242a0e4e9d5f865fee375f6582856c71a060dc8b579366fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1.tar.gz:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 aa342ef0a0153efa8c2b1a89420a66af8254da554749842878547e8ceff23072
MD5 a7ffd3908f37668b2b710f17161ff05a
BLAKE2b-256 308744c8f83779b7f0e80a358e573fe6bb366b02acab582db636e5461db71640

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp313-cp313-win_amd64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d39c203016519d0795f4f8d1ac3f98179e7efbf6d163c01ddbedbb40ede18d1e
MD5 cf8284d24c91c060ed73d5ff08c98418
BLAKE2b-256 07c09f7f05ec8dd2b3a3b15897170880a426dc3b293118d274420816617ac67a

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 537206a2c37d556fc5f3ee63f33656b6cb481e6f5e88784a02c3465c22bbd975
MD5 797bb668e449821dbd6b89f9c6e054c0
BLAKE2b-256 8026332022408eb624297115e0f85d17cc40e8325b22daac2925786940f94c87

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp312-cp312-win_amd64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1748f3d23f5ed094f66c4a4182bc2fba46f7853a1a41854c8b82a1b14390550b
MD5 6206d008afff910f05aebc997bf6cf71
BLAKE2b-256 ce434406de2b5271860d34773a128f4ce239556658d2261f12c75e9cf928e830

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1f006ade3ff89eda5fdfa3016ad9fc3400947e88560af11d2119694f163ba293
MD5 e41e77803165ebcb4361be93f1fcb3dc
BLAKE2b-256 9fec4b47d9af0c97aafb0a863e2a92ca3fb89413f076c50823707b31a28bb0ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp311-cp311-win_amd64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b218da8f7ac17b1fbd3c9df7891bd688abb1073c9e45ddd6c21838fbf10d4805
MD5 db8d520196b832386b2b3051ac002cc6
BLAKE2b-256 03192db3cbba00f1a8b0f819c9a8afb94b085b03970000e328f5ff9394692255

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ab4fefd825fc275f56c68aeceab01cf2a3ae95cd5ba96809198a916080988fe9
MD5 c8e1589f9a790a1f7fb1ba53af5796b3
BLAKE2b-256 3634315190aebeb94f5fd20ed44d4d67ae97367217ae77fe3aa88d715c5420ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp310-cp310-win_amd64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c7d7ea3b2292eefe37dbc4296b7da0b14b6d539afd8af11ceceab22abaa9fa7d
MD5 ebbb8bbfc37d97e9dec72eeb5474f548
BLAKE2b-256 566e223bfc9ba75d87f6207b32db84b7b2689dd040ba23042d5d3a703eee602b

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d30c32ce862cf0cd544f6284cc01aeaae7eb0f9488b20b564c517f8babe2bce7
MD5 b520c5be3f18f34222c0c7889da6d7e3
BLAKE2b-256 29889fcd801df09d9872a72afce3f72bdcfb2d8f2bb295299da8e29039cc5b44

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp39-cp39-win_amd64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce57e1735d24dc93fb45c4d4610fee503db359954fd78f12d812d32d8a8ebdb1
MD5 cb0c1312eb2ca7e644742dee2c9e143a
BLAKE2b-256 b07220b3e4b151c6ae63e19d9fc54b07ce90ba852c637c93362be18453f666bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 cca8f963bbfe21a5966dcc039737a5e56b66799a7be8683ec58fc71ab56ecd84
MD5 96255ce04fff8ddf706a66b7c30b83ae
BLAKE2b-256 2d557d2ffcc31fc6ff36ddde2b46e38594a6a1e29f9492a25abb928dfd70ba0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp38-cp38-win_amd64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e53b50cc131070b16d1df7a2540b41dca04c93db5b6ad9aad32b961b90d40c1
MD5 bd25aaa15bd95091a3c1558ee35c0777
BLAKE2b-256 e2f89f5968b55b2a042a524edd3e693772360e1bb2325e78636d82a743207b91

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 9fb4460c6010cd3cd3bec0e3ce05059b13fbe9551b837aaa095a35ad747eea52
MD5 a5db848fad0846acbafd5e286957fc3e
BLAKE2b-256 c1bb098619b158bcd00f1de39dbebcd1e299120fa03f8cce06f33b365362ef2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp37-cp37m-win_amd64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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

File details

Details for the file random_insertion-0.3.0.post1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for random_insertion-0.3.0.post1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 619cf76e9629f88c386df42caf100247595b2e8fd98d585da9e867fc92bfb491
MD5 bff959304de50da76186dade85405ae9
BLAKE2b-256 f1a880bf4ce9fa1e35f141e1bef4d70c0d4882ebc5b2aed019f9caa42c84d158

See more details on using hashes here.

Provenance

The following attestation bundles were made for random_insertion-0.3.0.post1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_and_publish.yml on Furffico/random-insertion

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