Skip to main content

randomized_tsp

A python3 package implementing randomized algorithms for Travelling Salesman Problem. The implementations are based off of A first course in Artificial Intelligence: Deepak Khemani.

The algorithms implemented include:

Installation

You can install this using pip. Just run

pip install randomized_tsp

Usage

See example here.

If you have n cities in your problem then you need to define the distances between cities using a two dimensional n X n list. distances[i][j] should give the distance between city i and city j.

from randomized_tsp.tsp import tsp

# If you have 3 cities then you need to define this list 
# which gives the distances between two cities
distances = [[0, 4, 2], [4, 0, 3], [2, 3, 0]]

tsp_obj = tsp(distances)

# To run genetic algorithm
tour, cost = tsp_obj.genetic_algorithm()

# To run simulated annealing
tour, cost = tsp_obj.simulated_annealing()

# To run ant colony optimization
tour, cost = tsp_obj.ant_colony()

All the three algorithms return that best tour found and the cost of that tour. Tour is represented using path representation.

Some optional parameters are also available for the above algorithms.

def genetic_algorithm(self,
                      population_size=50,
                      mutation_prob=0.1,
                      crossover='order'):
        """
        :param population_size: Defines the size of the population used in the algorithm
        :param mutation_prob:   Probability that a offspring will mutate
        :param crossover:       Defines the crossover operator, currently two options are available
                                `order` and `cycle`.
        :return:                Returns the best tour found and the cost of that tour
                                A tour is represented using path representation
        """

def simulated_annealing(self):
        """
        :return: Returns the best tour found and the cost of that tour
                 A tour is represented using path representation
        """

def ant_colony(self,
               num_of_ants=20,
               pheromone_evapouration=0.2):
        """
        :param num_of_ants:            Number of ants in the colony
        :param pheromone_evapouration: Evapouration rate of the pheromone deposited by ants
        :return:                       Returns the best tour found and the cost of that tour
                                       A tour is represented using path representation
        """

Contributing

Many of these algorithms need improvements and optimizations. If you want to improve this project or fix a bug then all contributions are welcome.

Contact

If you find any bugs then open a issue on this repository. You can also contact me on gitter.

Metadata

Release files for randomized-tsp 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for randomized-tsp 0.0.2
File Size Uploaded
randomized_tsp-0.0.2.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for randomized-tsp 0.0.2
File Interpreter ABI Platform
randomized_tsp-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / randomized_tsp-0.0.2.tar.gz

Download URL randomized_tsp-0.0.2.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b71986a6ece08f8e723e7e821363c2f0fa6a735b9fda6b8d6de8a193f3e5c7d3
BLAKE2b-256 checksum
How to use checksums
11cf27e262e38716b78cb8e917f7ae32e32a43a4d60a3cf8eaa315ccd861c8ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

Release files / randomized_tsp-0.0.2-py3-none-any.whl

Download URL randomized_tsp-0.0.2-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3d2e493083119efccfce386667ccb3a79c725380a2e6378ecbca2b29c382437
BLAKE2b-256 checksum
How to use checksums
2ad353df2c07028068ecdb85d2fcf6a5c44e8050ac714dc569f7e342f710f68a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page