Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status Coverage Dev Stable

This is a simple Julia package to solve the travelling salesman problem using an Dantzig-Fulkerson-Johnson algorithm. I learned about this kind of algorithm from the very nice blog post which also has a Julia implementation. In the symmetric case, the implementation in this package uses the symmetry of the problem to reduce the number of variables, and essentially is the most basic version of the algorithms described by (Pferschy and Staněk, 2017) (i.e. no warmstarts or clustering methods for subtour elimination as a presolve step).

See also TravelingSalesmanHeuristics.jl for a Julia implementation of heuristic solutions to the TSP (which will be much more performant, especially for large problems, although not exact). Additionally, see TravelingSalesmanBenchmarks for one use of this package: generating exact cost values for test-cases to help tune the heuristics of the aforementioned TravelingSalesmanHeuristics.jl.

Generating subtour elimination constraints for the TSP from pure integer solutions
Pferschy, U. & Staněk, R. Cent Eur J Oper Res (2017) 25: 231.

Solution of a Large-Scale Traveling-Salesman Problem
G. Dantzig, R. Fulkerson, and S. Johnson, J. Oper. Res. Soc. (1954) 2:4, 393-410


Requires Julia (

This package is registered, so you can add it via

] add TravelingSalesmanExact

You also need a mixed-integer solver compatible with JuMP 19+ to do the underlying optimization. For example, GLPK is a free, open-source solver (see for the compatible Julia wrapper) and can be installed by

] add GLPK

Gurobi is a commercial wrapper that offers free academic licenses. It has a compatible Julia wrapper Gurobi ( that can be installed via

] add Gurobi

Note you also need Gurobi itself installed and a license properly configured.



With GLPK:

using TravelingSalesmanExact, GLPK
n = 50
cities = [ 100*rand(2) for _ in 1:n];
tour, cost = get_optimal_tour(cities; verbose = true)

Note, if you are using an older version of JuMP (v0.19 or v0.20), you need to use set_default_optimizer!(with_optimizer(GLPK.Optimizer)) instead.

To use Gurobi, the first few lines can be changed to:

using TravelingSalesmanExact, Gurobi
const GurobiEnv = Gurobi.Env()
set_default_optimizer!(() -> Gurobi.Optimizer(GurobiEnv, OutputFlag = 0))

Note that without the OutputFlag = 0 argument, Gurobi will print a lot of information about each iteration of the solve.

Mosek is another commercial wrapper that offers free academic licenses. It has a compatible Julia wrapper MosekTools ( You also need a license properly configured; the older wrapper Mosek.jl offers instructions for this. Mosek can be used as e.g.

using TravelingSalesmanExact, MosekTools
set_default_optimizer!(() -> Mosek.Optimizer(QUIET = true))

One can also pass an optimizer to get_optimal_tour instead of setting the default for the session, e.g.

using TravelingSalesmanExact, GLPK
n = 50
cities = [ 100*rand(2) for _ in 1:n];
tour, cost = get_optimal_tour(cities, GLPK.Optimizer; verbose = true)

See for a benchmark comparing the computation time between these solvers on random problems as well as comparing to that of heuristics.


Solve the travelling salesman problem using a mixed integer optimization algorithm with JuMP







No packages published