A library to solve TSP (Travelling Salesman Problem) using Exact Algorithms, Heuristics and Metaheuristics
Project description
pyCombinatorial
Introduction
A library to solve the TSP (Travelling Salesman Problem) using Exact Algorithms, Heuristics and Metaheuristics : 2-opt; 2.5-opt; 3-opt; 4-opt; 5-opt; 2-opt Stochastic; 2.5-opt Stochastic; 3-opt Stochastic; 4-opt Stochastic; 5-opt Stochastic; Ant Colony Optimization; Adaptive Large Neighborhood Search; Bellman-Held-Karp Exact Algorithm; Branch & Bound; BRKGA (Biased Random Key Genetic Algorithm); Brute Force; Cheapest Insertion; Christofides Algorithm; Clarke & Wright (Savings Heuristic); Concave Hull Algorithm; Convex Hull Algorithm; Elastic Net; Extremal Optimization; Farthest Insertion; Genetic Algorithm; GRASP (Greedy Randomized Adaptive Search Procedure); Greedy Karp-Steele Patching; Guided Search; Hopfield Network; Iterated Search; Karp-Steele Patching; Large Neighborhood Search; Multifragment Heuristic; Nearest Insertion; Nearest Neighbour; Random Insertion; Random Tour; Scatter Search; Simulated Annealing; SOM (Self Organizing Maps); Space Filling Curve (Hilbert); Space Filling Curve (Morton); Space Filling Curve (Sierpinski); Stochastic Hill Climbing; Sweep; Tabu Search; Truncated Branch & Bound; Twice-Around the Tree Algorithm (Double Tree Algorithm); Variable Neighborhood Search.
Usage
- Install
pip install pyCombinatorial
- Import
# Required Libraries
import pandas as pd
# GA
from pyCombinatorial.algorithm import genetic_algorithm
from pyCombinatorial.utils import graphs, util
# Loading Coordinates # Berlin 52 (Minimum Distance = 7544.3659)
coordinates = pd.read_csv('https://bit.ly/3Oyn3hN', sep = '\t')
coordinates = coordinates.values
# Obtaining the Distance Matrix
distance_matrix = util.build_distance_matrix(coordinates)
# GA - Parameters
parameters = {
'population_size': 15,
'elite': 1,
'mutation_rate': 0.1,
'mutation_search': 8,
'generations': 1000,
'verbose': True
}
# GA - Algorithm
route, distance = genetic_algorithm(distance_matrix, **parameters)
# Plot Locations and Tour
graphs.plot_tour(coordinates, city_tour = route, view = 'browser', size = 10)
print('Total Distance: ', round(distance, 2))
- Try it in Colab
- 2-opt ( Colab Demo ) ( Paper )
- 2.5-opt ( Colab Demo ) ( Paper )
- 3-opt ( Colab Demo ) ( Paper )
- 4-opt ( Colab Demo ) ( Paper )
- 5-opt ( Colab Demo ) ( Paper )
- 2-opt Stochastic ( Colab Demo ) ( Paper )
- 2.5-opt Stochastic ( Colab Demo ) ( Paper )
- 3-opt Stochastic ( Colab Demo ) ( Paper )
- 4-opt Stochastic ( Colab Demo ) ( Paper )
- 5-opt Stochastic ( Colab Demo ) ( Paper )
- Ant Colony Optimization ( Colab Demo ) ( Paper )
- Adaptive Large Neighborhood Search ( Colab Demo ) ( Paper )
- Bellman-Held-Karp Exact Algorithm ( Colab Demo ) ( Paper )
- Branch & Bound ( Colab Demo ) ( Paper )
- BRKGA (Biased Random Key Genetic Algorithm) ( Colab Demo ) ( Paper )
- Brute Force ( Colab Demo ) ( Paper )
- Cheapest Insertion ( Colab Demo ) ( Paper )
- Christofides Algorithm ( Colab Demo ) ( Paper )
- Clarke & Wright (Savings Heuristic) ( Colab Demo ) ( Paper )
- Concave Hull Algorithm ( Colab Demo ) ( Paper )
- Convex Hull Algorithm ( Colab Demo ) ( Paper )
- Elastic Net ( Colab Demo ) ( Paper )
- Extremal Optimization ( Colab Demo ) ( Paper )
- Farthest Insertion ( Colab Demo ) ( Paper )
- Genetic Algorithm ( Colab Demo ) ( Paper )
- GRASP (Greedy Randomized Adaptive Search Procedure) ( Colab Demo ) ( Paper )
- Greedy Karp-Steele Patching ( Colab Demo ) ( Paper )
- Guided Search ( Colab Demo ) ( Paper )
- Hopfield Network ( Colab Demo ) ( Paper )
- Iterated Search ( Colab Demo ) ( Paper )
- Karp-Steele Patching ( Colab Demo ) ( Paper )
- Large Neighborhood Search ( Colab Demo ) ( Paper )
- Multifragment Heuristic ( Colab Demo ) ( Paper )
- Nearest Insertion ( Colab Demo ) ( Paper )
- Nearest Neighbour ( Colab Demo ) ( Paper )
- Random Insertion ( Colab Demo ) ( Paper )
- Random Tour ( Colab Demo ) ( Paper )
- Scatter Search ( Colab Demo ) ( Paper )
- Simulated Annealing ( Colab Demo ) ( Paper )
- SOM (Self Organizing Maps) ( Colab Demo ) ( Paper )
- Space Filling Curve (Hilbert) ( Colab Demo ) ( Paper )
- Space Filling Curve (Morton) ( Colab Demo ) ( Paper )
- Space Filling Curve (Sierpinski) ( Colab Demo ) ( Paper )
- Stochastic Hill Climbing ( Colab Demo ) ( Paper )
- Sweep ( Colab Demo ) ( Paper )
- Tabu Search ( Colab Demo ) ( Paper )
- Truncated Branch & Bound ( Colab Demo ) ( Paper )
- Twice-Around the Tree Algorithm ( Colab Demo ) ( Paper )
- Variable Neighborhood Search ( Colab Demo ) ( Paper )
Single Objective Optimization
For Single Objective Optimization try pyMetaheuristic
Multiobjective Optimization or Many Objectives Optimization
For Multiobjective Optimization or Many Objectives Optimization try pyMultiobjective
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyCombinatorial-1.8.1.tar.gz
.
File metadata
- Download URL: pyCombinatorial-1.8.1.tar.gz
- Upload date:
- Size: 44.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bda9c0df2866e5960d7857a66ace82ce7f868a33ad78587dd0637f42114b9f56 |
|
MD5 | 0b73210c1d441ec9f413573e889eec5c |
|
BLAKE2b-256 | 637229c1ceac2fb4e2364bfb536f1bffe65ec6ba292d4406e9aae5b4633d65ed |
File details
Details for the file pyCombinatorial-1.8.1-py3-none-any.whl
.
File metadata
- Download URL: pyCombinatorial-1.8.1-py3-none-any.whl
- Upload date:
- Size: 86.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 755b8b0bd4bdd6a832f9a02d28b8ac73c68823ad8d6f0d870c3736691d6bee33 |
|
MD5 | c48c93151ef413cfdd6ccbe5e2904115 |
|
BLAKE2b-256 | d30f9aab73f84085303ee5b8b0656b1104c6ac961dc639d64256b4a71905574b |