Skip to main content

Randomized algorithms for Travelling Salesman Problem

Project description

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.

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

randomized_tsp-0.0.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

randomized_tsp-0.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file randomized_tsp-0.0.2.tar.gz.

File metadata

  • Download URL: randomized_tsp-0.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for randomized_tsp-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b71986a6ece08f8e723e7e821363c2f0fa6a735b9fda6b8d6de8a193f3e5c7d3
MD5 6128b25d989763c1432a9385cb4f6db1
BLAKE2b-256 11cf27e262e38716b78cb8e917f7ae32e32a43a4d60a3cf8eaa315ccd861c8ae

See more details on using hashes here.

File details

Details for the file randomized_tsp-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: randomized_tsp-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for randomized_tsp-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b3d2e493083119efccfce386667ccb3a79c725380a2e6378ecbca2b29c382437
MD5 6655af785d2bab8c8b511c13b4e35b06
BLAKE2b-256 2ad353df2c07028068ecdb85d2fcf6a5c44e8050ac714dc569f7e342f710f68a

See more details on using hashes here.

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