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.

Files for tsp, version 0.0.9
Filename, size File type Python version Upload date Hashes
Filename, size tsp-0.0.9-py3-none-any.whl (4.0 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

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