-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathREADME
More file actions
46 lines (32 loc) · 1.47 KB
/
README
File metadata and controls
46 lines (32 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
* The Traveling Salesman Problem
This project uses a Genetic Algorithm to solve the Traveling Salesman
Problem. The positions of the cities are given as coordinates on a 2D
plane. The script returns the cities in the order of one of the
shortest routes and can also write the route to an SVG image.
#+BEGIN_QUOTE
The travelling salesman problem (TSP) is an NP-hard problem in
combinatorial optimization studied in operations research and
theoretical computer science. Given a list of cities and their
pairwise distances, the task is to find the shortest possible route
that visits each city exactly once and returns to the origin city. It
is a special case of the travelling purchaser problem.
@<div class="source">[[http://en.wikipedia.org/wiki/Traveling_salesman_problem][Wikipedia]]@</div>
#+END_QUOTE
A set of 10 cities has 10!(factorial) = 3,628,800 possible routes. A
genetic algorithm can find an acceptable path in a small amount of
time by creating a pool of random routes and selecting the shortest
to create a new generation. Each generation random mutations are
introduced and pairs of routes are combined to create a new route.
* Usage
This runs the algorithm with an octagon:
#+BEGIN_EXAMPLE
python TravelingSalesman.py 26,2 62,2 87,26 87,62 62,87 26,87 2,62 2,26
#+END_EXAMPLE
You can also let it use random input:
#+BEGIN_EXAMPLE
python TravelingSalesman.py -r
#+END_EXAMPLE
Output a map to an image:
#+BEGIN_EXAMPLE
python TravelingSalesman.py -r -i map.svg
#+END_EXAMPLE