Skip to content

Instantly share code, notes, and snippets.

@gkhayes
Created January 17, 2019 19:32
Show Gist options
  • Select an option

  • Save gkhayes/14a94ed4d27f6df9a1d967bdca9bb2ef to your computer and use it in GitHub Desktop.

Select an option

Save gkhayes/14a94ed4d27f6df9a1d967bdca9bb2ef to your computer and use it in GitHub Desktop.
Initialize TSP fitness function using distance method
# Create list of distances between pairs of cities
dist_list = [(0, 1, 3.1623), (0, 2, 4.1231), (0, 3, 5.8310), (0, 4, 4.2426), \
(0, 5, 5.3852), (0, 6, 4.0000), (0, 7, 2.2361), (1, 2, 1.0000), \
(1, 3, 2.8284), (1, 4, 2.0000), (1, 5, 4.1231), (1, 6, 4.2426), \
(1, 7, 2.2361), (2, 3, 2.2361), (2, 4, 2.2361), (2, 5, 4.4721), \
(2, 6, 5.0000), (2, 7, 3.1623), (3, 4, 2.0000), (3, 5, 3.6056), \
(3, 6, 5.0990), (3, 7, 4.1231), (4, 5, 2.2361), (4, 6, 3.1623), \
(4, 7, 2.2361), (5, 6, 2.2361), (5, 7, 3.1623), (6, 7, 2.2361)]
# Initialize fitness function object using dist_list
fitness_dists = mlrose.TravellingSales(distances = dist_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment