Skip to main content

GRASP for TSP

Project description

tsp-grasp

Welcome to tsp-grasp! A Python package with Heuristics for solving the Traveling Salesman Problem (TSP).

Documentation

Install

The package tspgrasp is available on PyPI, so you can install it via pip by running the following command line:

pip install tspgrasp

To install the package in development versions, clone it from github using:

git clone https://github.com/bruscalia/tsp-grasp.git

And run one of the two following commands:

pip install .
python setup.py install

Make sure Cython and numpy are also available in your python environment.

Alternatively, you can directly run:

pip install git+https://github.com/bruscalia/tsp-grasp.git

Here is a minimum working example in which a symmetric distance matrix is produced from 2-dimensional coordinates.

Use

# Imports
import numpy as np
from scipy.spatial.distance import pdist, squareform
from tspgrasp import Grasp
# Create distance matrix
X = np.random.random((100, 2))
D = squareform(pdist(X))

# Instantiate algorithm and solve problem
grasp = Grasp(seed=12)
sol = grasp(D, time_limit=10, max_iter=100)

# Display cost and tour
print(f"Cost: {sol.cost}")
print(f"Tour: {sol.tour}")

Theory

Greedy Randomized Adaptive Search Procedures (GRASP) are metaheuristics constituted by a hybridization of a semi-greedy procedure with a local search method. For more details please refer to Resende & Ribeiro (2016).

Local search moves implemented were based on the work of Vidal (2022).

Contact

You can reach out to me at bruscalia12@gmail.com

References

Resende, M. G., & Ribeiro, C. C. (2016). Optimization by GRASP. Springer Science+ Business Media New York. https://doi.org/10.1007/978-1-4939-6530-4

Vidal, T. (2022). Hybrid genetic search for the CVRP: Open-source implementation and SWAP* neighborhood. Computers & Operations Research, 140, 105643. https://doi.org/10.1016/j.cor.2021.105643

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

tspgrasp-0.1.1.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distributions

tspgrasp-0.1.1-cp312-cp312-win_amd64.whl (520.5 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

tspgrasp-0.1.1-cp312-cp312-macosx_10_9_universal2.whl (1.1 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

tspgrasp-0.1.1-cp311-cp311-win_amd64.whl (517.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

tspgrasp-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.8 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

tspgrasp-0.1.1-cp311-cp311-macosx_10_9_universal2.whl (1.1 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

tspgrasp-0.1.1-cp310-cp310-win_amd64.whl (516.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

tspgrasp-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

tspgrasp-0.1.1-cp310-cp310-macosx_11_0_x86_64.whl (584.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ x86-64

tspgrasp-0.1.1-cp39-cp39-win_amd64.whl (605.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

tspgrasp-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

tspgrasp-0.1.1-cp39-cp39-macosx_11_0_x86_64.whl (590.0 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ x86-64

tspgrasp-0.1.1-cp38-cp38-win_amd64.whl (610.4 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

tspgrasp-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

tspgrasp-0.1.1-cp38-cp38-macosx_11_0_x86_64.whl (587.9 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ x86-64

tspgrasp-0.1.1-cp37-cp37m-win_amd64.whl (601.7 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

tspgrasp-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

tspgrasp-0.1.1-cp37-cp37m-macosx_11_0_x86_64.whl (591.6 kB view hashes)

Uploaded CPython 3.7m macOS 11.0+ x86-64

Supported by

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