tsp_descent


tsp_descent, a MATLAB code which solves small versions of the traveling salesperson problem (TSP), using a descent method.

The user must prepare a file beforehand, containing the city-to-city distances. The program will request the name of this file, and then read it in as a matrix d. An example of such a file is:

        0  3  4  2  7
        3  0  4  6  3
        4  4  0  5  8
        2  6  5  0  6
        7  3  8  6  0
      
The distance file d should be square, symmetric, and have a zero diagonal.

A tour of n cities can be represented as a permutation p on the integers 1 through n. The cost of the tour, that is, the length, is the sum

        cost = sum ( 1 <= i <= n ) ( d(p(i),p(i+1)) )
      
where p(n+1) is understood to mean p(1).

Given a permutation p, we can consider a transposition variation p2 of p by selecting two indices i1 and i2, with i1 + 1 < i2, and constructing a tour in which the i2 item now follows i1 immediately.

        p = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
        i1 = 3, i2 = 7
        p2 = [ 1, 2, 3, 7, 4, 5, 6, 8, 9, 10 ]
      

Given a permutation p, we can consider a reversal variation p2 of p by selecting two indices i1 and i2, with i1 < i2, and constructing a tour in which the ordering of cities between steps i1 and i2 is reversed.

        p = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
        i1 = 3, i2 = 7
        p2 = [ 1, 2, 7, 6, 5, 4, 3, 8, 9, 10 ]
      

Starting with a random choice for p, we can generate random reversals and transpositions. The current value of p is replaced whenever a variation is seen to have a lower cost. By repeating this process, a sequence of tours is produced of successively lower cost. It is hoped that this process will find a good tour, if not the best.

This program is set to check only a limited number of variations, currently set to 1000. Thus, it will return an "answer" relatively quickly, even for problems of 50 or 100 cities, where the search space of possible tours is unimaginably complex.

However, even for small problems, there is no guarantee that the tour that is returned is optimal, or even close to optimal. Even if it can be shown that no reversal or transposition can improve the tour that is returned, this may merely mean that the tour is a local minimum.

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

tsp_descent is available in a MATLAB version and an Octave version and a Python version.

Related Data and Programs:

tsp_descent_test

cities, a MATLAB code which handles various problems associated with a set of "cities" on a map.

subset_sum_backtrack, a MATLAB code which uses backtracking to solve the subset sum problem, to find a subset of a set of integers which has a given sum.

tsp_brute, a MATLAB code which is given a city-to-city distance table, and solves a (small) traveling salesperson problem (TSP), using brute force.

tsp_greedy, a MATLAB code which is given a city-to-city distance table,, and solves a small traveling salesperson problem (TSP) using the greedy algorithm. It picks a starting city at random, and then successively visits the nearest unvisited city.

tsp_moler, a MATLAB code which tries to optimize the traveling salesperson problem (TSP), written by Cleve Moler.

tsp_random, a MATLAB code which is given a city-to-city distance table, seeks a solution of the Traveling Salesperson Problem (TSP), by randomly generating round trips that visit every city, returning the tour of shortest length.

Reference:

  1. Gerhard Reinelt,
    TSPLIB - A Traveling Salesman Problem Library,
    ORSA Journal on Computing,
    Volume 3, Number 4, Fall 1991, pages 376-384.

Source Code:


Last revised on 01 October 2022.