All Projects → afourmy → Pytsp

afourmy / Pytsp

A 2D/3D visualization of the Traveling Salesman Problem main heuristics

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pytsp

Car Simulator
Autonomous car simulator (based on JavaScript & WebGL) implemented by fuzzy control system, genetic algorithm and particle swarm optimization.
Stars: ✭ 335 (+174.59%)
Mutual labels:  webgl, genetic-algorithm
Mapsui
Mapsui is a .NET Map component for WPF, Xamarin.Forms, Xamarin.Android, Xamarin.iOS and UWP
Stars: ✭ 447 (+266.39%)
Mutual labels:  gis, openstreetmap
Fmm
Fast map matching, an open source framework in C++
Stars: ✭ 359 (+194.26%)
Mutual labels:  gis, openstreetmap
Geojs
High-performance visualization and interactive data exploration of scientific and geospatial location aware datasets
Stars: ✭ 323 (+164.75%)
Mutual labels:  webgl, gis
Urbansprawl
Open framework for calculating spatial urban sprawl indices and performing disaggregated population estimates using open data
Stars: ✭ 48 (-60.66%)
Mutual labels:  gis, openstreetmap
Tasking Manager
Tasking Manager - The tool to team up for mapping in OpenStreetMap
Stars: ✭ 328 (+168.85%)
Mutual labels:  flask, openstreetmap
Xbsjearthui
XbsjEarthUI是基于Cesium和EarthSDK的三维GIS/BIM的UI模板,可以基于此定制自己的三维App
Stars: ✭ 373 (+205.74%)
Mutual labels:  webgl, gis
accessibility-cloud
👩🏽‍🦯🦮👩🏻‍🦽👩🏿‍🦼 the platform to exchange physical accessibility data in a standardized, future-proof, easy-to-use way.
Stars: ✭ 37 (-69.67%)
Mutual labels:  openstreetmap, gis
Mapbox Gl Js
Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
Stars: ✭ 8,017 (+6471.31%)
Mutual labels:  webgl, openstreetmap
Cesium
An open-source JavaScript library for world-class 3D globes and maps 🌎
Stars: ✭ 8,095 (+6535.25%)
Mutual labels:  webgl, gis
Cga.js
CGA 3D 计算几何算法库 | 3D Compute Geometry Algorithm Library webgl three.js babylon.js等任何库都可以使用
Stars: ✭ 313 (+156.56%)
Mutual labels:  webgl, gis
Openrouteservice R
🌐 R package to query openrouteservice.org
Stars: ✭ 57 (-53.28%)
Mutual labels:  gis, openstreetmap
Osmnx
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.
Stars: ✭ 3,357 (+2651.64%)
Mutual labels:  gis, openstreetmap
Mars3d
Mars3D三维地球平台软件 主仓库,包含示例及引导
Stars: ✭ 332 (+172.13%)
Mutual labels:  webgl, gis
Offroad-routing-engine
Off-road Navigation System
Stars: ✭ 16 (-86.89%)
Mutual labels:  openstreetmap, gis
Blendergis
Blender addons to make the bridge between Blender and geographic data
Stars: ✭ 4,642 (+3704.92%)
Mutual labels:  gis, openstreetmap
a11yjson
A11yJSON: A standard to describe the accessibility of the physical world.
Stars: ✭ 58 (-52.46%)
Mutual labels:  openstreetmap, gis
osmcha
Python package to detect suspicious OSM changesets
Stars: ✭ 33 (-72.95%)
Mutual labels:  openstreetmap, gis
Itowns
A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
Stars: ✭ 517 (+323.77%)
Mutual labels:  webgl, gis
Shadoweditor
Cross-platform 3D scene editor based on three.js, golang and mongodb for desktop and web. https://tengge1.github.io/ShadowEditor-examples/
Stars: ✭ 1,060 (+768.85%)
Mutual labels:  webgl, gis

Introduction

The travelling salesman problem (TSP) asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city ?

pyTSP uses various approaches to solve the TSP (linear programming, construction heuristics, optimization heuristics, genetic algorithm). It provides a geographical step-by-step visualization of each of these algorithms.

pyTSP

You can find a demo of pyTSP here ! (U.S cities with a population larger than 900 000 inhabitants)

Algorithms

The following algorithms are implemented in pyTSP:

  • Construction heuristics
    • Nearest neighbor
    • Nearest insertion
    • Farthest insertion
    • Cheapest insertion
  • Linear programming
  • Optimization heuristics
    • Pairwise exchange (2-opt)
    • Node insertion
    • Edge insertion
  • Genetic algorithm

Construction heuristics

Nearest neighbor

- Start from a random city.
- Travel to the nearest unvisited city.
- Repeat until every city has been visited.

Nearest neighbor

Nearest insertion

- Start from a random city.
- Find the city closest to the partial tour, i.e the city i which minimizes d(i, j)
with j a city already in the tour.
- Insert i before or after j, depending on which option is shorter.
- Repeat until every city has been visited.

Nearest insertion

Cheapest insertion

- Start from a random city.
- Find the city which insertion in the tour causes the smallest increase in length,  
i.e the city k which minimizes d(i, k)  + d(k, j) - d(i, j) with (i, j) an edge in the partial tour.
- Insert k between i and j.
- Repeat until every city has been visited.

Cheapest insertion

Farthest insertion

- Start from a random city.
- Find the city k farthest from any node in the tour (i.e the city k which maximizes d(c, k) with c
a city in the partial tour), and insert k where it causes the smallest increase in length 
(by minimizing d(i, k)  + d(k, j) - d(i, j), with (i, j) an edge in the partial tour).  
- Repeat until every city has been visited.

Farthest insertion

Linear programming

First constraints

Example of disjoint subtours

Subtour constraint

Final solution

Note: there is an exponentially growing number of subtour constraints, which makes this algorithm inefficient for larger instances of the TSP. One way to improve it is to use lazy constraints, i.e ignore the subtour constraints and eliminate them one by one when looking for a feasible solution.

Optimization heuristics

Pairwise exchange (2-opt)

Pairwise exchange

- Given a pair of edges, there is only one way of deleting and reconnecting the edges to obtain
a valid tour. If this new tour is shorter, make the change.
- Repeat for any pair of edges until no further improvement can be made.

Pairwise exchange

Node insertion

Node insertion

- Given a node, remove it from the tour and insert it at the best possible position.
- Repeat for any node until no further improvement can be made.

Node insertion

Edge insertion

Edge insertion

- Given an edge, remove it from the tour and insert it at the best possible position.
- Repeat for any edge until no further improvement can be made.

Edge insertion

Genetic algorithm

pyTSP implements a genetic algorithm with the following properties:

  • 3 mutation methods: random swap, insertion or displacement.
  • 3 crossover methods: order, maximally preservative, or partially mapped.
  • Selection: at each generation, 30 individuals are chosen randomly, and the 10 best are kept for the next generation.
  • Mutation and crossover rates default to 50%. They can be modified with sliders.

Genetic algorithm

Note: the genetic algorithm is processed by the server, and websockets (or long-polling if the server does not support websockets) are used to update the display client-side every new generation.

Getting started

The following modules are used in pyTSP:

flask
flask_socketio (sockets)
flask_sqlalchemy (database)
numpy (linear programming)
cvxopt (linear programming)
xlrd (graph import)

In order to use pyTSP, you need to:

  • (optional) set up a virtual environment .

  • clone pyTSP (or download as a zip archive from github)

git clone https://github.com/afourmy/pyTSP.git
  • install the requirements
cd pyTSP
pip install -r requirements.txt
  • run /flask_app.py.
python flask_app.py

Credits

Bootstrap: Front-end HTML/CSS framework.

Bootstrap slider: A slider component for Bootstrap.

CVXOPT: A library for convex optimization.

Flask: A microframework based on the Werkzeug toolkit and Jinja2 template engine.

Flask SQLAlchemy: Adds support for SQLAlchemy to Flask.

Jquery: JavaScript library designed to simplify the client-side scripting of HTML.

Leaflet: JavaScript library for mobile-friendly interactive maps.

OpenStreetMap: Collaborative project to create a free editable map of the world.

WebGL Earth: 3D digital globe for web and mobile devices.

xlrd: Library to extract data from Microsoft Excel (tm) spreadsheet files.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].