tsp_greedy


tsp_greedy, a Python code which solves the traveling salesperson problem (TSP) using the greedy algorithm.

The greedy algorithm progressively chooses the shortest unused link that does not complete a circuit, until the last step. This is a simple algorithm, but it is not guaranteed to be optimal, or even to do well. There are simple examples in which the greedy algorithm seems to choose one of the worst possible tours.

Licensing:

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

Languages:

tsp_greedy is available in a Python version.

Related Data and Programs:

concorde, examples which call concorde(), which solves the traveling salesman problem (TSP), mixed integer programming, and related network optimization problems.

tsp, a dataset directory which contains test data for the traveling salesperson problem (TSP) including the AT&T 48 state capital test, and Dantzig's 42 city test;

tsp_anneal, a Python code which is given a table of city locations, and solves a traveling salesperson problem (TSP), using simulated annealing.

tsp_att48, a Python code which returns the (x,y) coordinates of the cities that constitute the AT&T 48 state challenge for the Traveling Salesman Problem (TSP).

tsp_brute, a Python code which is given a table of city locations, and solves a (small) traveling salesperson problem (TSP), using brute force.

tsp_display, a Python code which displays the solution of a Traveling Salesman Problem (TSP).

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

tsp_nearest, a Python code which is given a table of city locations, and solves a small traveling salesperson problem (TSP) using the nearest neighbor algorithm. It picks a starting city at random, and then successively visits the nearest unvisited city.

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

Author:

This version by John Burkardt.

Reference:

  1. William Cook,
    In Pursuit of the Traveling Salesman,
    Princeton University Press, 2012,
    ISBN13 978-0-691-16352-9.
  2. James Howard,
    Computational Methods for Numerical Analysis with R,
    CRC Press, 2017,
    ISBN13: 978-1-4987-2363-3.

Source Code:


Last revised on 15 June 2026.