Skip to main content

`tsp` is a package for Traveling Salesman Problem for Python.

Project description

tsp is a package for Traveling Salesman Problem for Python.

import tsp
t = tsp.tsp([(0,0), (0,1), (1,0), (1,1)])
print(t)  # distance, node index list
>>>
(4, [0, 1, 3, 2])

mat = [[  0,   1, 1, 1.5],
       [  1,   0, 1.5, 1],
       [  1, 1.5,   0, 1],
       [1.5,   1,   1, 0]]  # Distance Matrix
r = range(len(mat))
# Dictionary of distance
dist = {(i, j): mat[i][j] for i in r for j in r}
print(tsp.tsp(r, dist))
>>>
(4, [0, 1, 3, 2])

Note: When large size, ortoolpy.ortools_vrp may be efficient.

See also https://pypi.org/project/ortoolpy/

Requirements

  • Python 3
  • PuLP
  • more-itertools

Features

  • nothing

Setup

$ pip install tsp

History

0.0.1 (2015-10-2)

  • first release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Built Distribution

tsp-0.0.9-py3-none-any.whl (4.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page