Skip to content

Instantly share code, notes, and snippets.

@MrDMurray
Created January 10, 2019 15:02
Show Gist options
  • Save MrDMurray/c974f69be1698d311cfdb0ca8ef7ed49 to your computer and use it in GitHub Desktop.
Save MrDMurray/c974f69be1698d311cfdb0ca8ef7ed49 to your computer and use it in GitHub Desktop.
Traveling Salesman example for ALT3
import pandas
import tsp #traveling salesman
mat = [[ 0, 128, 75, 95],
[ 128, 0, 105, 160],
[ 75, 105, 0, 120],
[95, 160, 120, 0]] # Distance Matrix
r = range(len(mat))
# Dictionary of distance
dist = {(i, j): mat[i][j] for i in r for j in r}
print(tsp.tsp(r, dist))
print ("0 is Enniskillen, 1 is Belfast, 2 is Derry, 3 is Donegal")
print("and with BREXIT")
mat = [[ 0, 128, 75, 105],
[ 128, 0, 105, 160],
[ 75, 105, 0, 130],
[105, 160, 130, 0]] # Distance Matrix
r = range(len(mat))
# Dictionary of distance
dist = {(i, j): mat[i][j] for i in r for j in r}
print(tsp.tsp(r, dist))
print ("0 is Enniskillen, 1 is Belfast, 2 is Derry, 3 is Donegal")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment