# Introduction¶

Given a list of cities and their pairwise distances, the task is to find the shortest possible tour that visits each city exactly once.

In the symmetric TSP, the distance between two cities is the same in each opposite direction, forming an undirected graph. This symmetry halves the number of possible solutions. In the asymmetric TSP, paths may not exist in both directions or the distances might be different, forming a directed graph.

Traveling salesman problems can be formulated (encoded) in PyGMO in three different ways.

## TSP as integer linear programs (FULL encoding)¶

In this encoding each edge is associated to a variable \(X_{i,j}\)

\(X_{i,j}\) is the square binary matrix, with

\(C_{i,j}\) is the square adjacency matrix containing the distances (weights) between city i and city j, with i and j \(\in = \{1, 2, .., n\}\). If the problem is symmetric, then the matrix is symmetric. For \(i = \{1, 2, .., n\} \quad u_i\) is an artificial variable which has to satisfy the inequality constraints. Then, the TSP can be written as follows:

For more information visit: http://en.wikipedia.org/wiki/Travelling_salesman_problem#Integer_linear_programming_formulation

The dimensions of the constraint and of the chromosome grow quadratically with the number of cities. This makes the FULL encoding particularly unefficient in PaGMO when large dimensions are involved.

## TSP encoded using Random Keys (RANDOMKEYS encoding)¶

In this encoding the sequence of the cities visited is obtained from a sequence of floats by considering their indices after sorting.

This maps the TSP into a box-bounded continuous problem getting rid of the constrains and of all the problems associated with the possibility of generating unfeasible offsprings.

For more information see: Bean, J. C. (1994). Genetic algorithms and random keys for sequencing and optimization. ORSA journal on computing, 6(2), 154-160.

## TSP encoded using the city sequence (CITIES encoding)¶

In this encoding the sequence of the cities visited is directly put in the chromosome, creating a problem with one constraint: the sequence must be a permutation of the city indexes.