Skip to main content

A toolset that simplifies the process of solving TSP (Traveling Salesman Problem) problems.

Project description

TSP Lifesaver

PRs Welcome PyPI - License

!!! This package is currently under development and may contain bugs. !!!

Introduction

This is a framework that simplifies the process of solving TSP (Traveling Salesman Problem) problems.

Installation

pip install TSPLifesaver

Quick Start

How to import:

from TSPLifesaver.structure import BasicRoute, PointWithEuclideanDistance
from TSPLifesaver.optimizer import SimulatedAnnealing
from TSPLifesaver.tools import route_from_sequence, simulated_annealing

Define a point:

point = PointWithEuclideanDistance([1,1,1], name="test_point")
print(point)
# test_point([1,1,1])

print(point.distance_to(point))
# 0

print(point.distance_to([1,1,2]))
# 1

Define a route:

points = [PointWithEuclideanDistance(i) for i in [[1,1,1],[2,2,2],[3,3,3]]]
route = BasicRoute(points, name="TestRoute")

#or you can
route = route_from_sequence([[1,1,1],[2,2,2],[3,3,3]])

print(route)

# TestRoute(
# None: [1, 1, 1]
# None: [2, 2, 2]
# None: [3, 3, 3]
# )

Calculate total distance:

print(route.distance())
# 6.928203230275509

Optimize the route:

optimizer = SimulatedAnnealing(route, temperature=10000, cooling_rate=0.003, min_temperature=1)
route = optimizer.optimize()

# or you can 
optimized_route = simulated_annealing(route,epoch=50)

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

TSPLifesaver-0.0.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

TSPLifesaver-0.0.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: TSPLifesaver-0.0.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for TSPLifesaver-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4bc65aae5c3017f6322cd6da45d5368f811cd4b4e4802d507ef00fde2c0c0681
MD5 c0e06c77896183ab26310374648dc4f6
BLAKE2b-256 a32d47187be67ee39eef7cce67f70bbf28fb9d26a131e86edd790db3f42728ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: TSPLifesaver-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for TSPLifesaver-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f9cfa3a15b2e36482e416a1a5589abd3d6d5dc0de83255f8e956db00652927b
MD5 3d25131f0b67ee2544e07de6800b4d70
BLAKE2b-256 ad32b76f97599bd6fab72f91f0991b4f93f71919515eb1682c9909d7a4e02348

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