# How To Calculate The Most Optimal Skills Route

For all the newer teams out there, I’ve spent the past couple of hours developing a little python script to find the most optimal route for your skills runs. This code works by finding all the possible routes and then comparing them.

``````import itertools

diskLocations = [[1, 1], [2, 2], [3, 3], [3, 3], [3, 3], [4, 4], [5, 5], [7, 7], [8, 8], [9, 9], [9, 9], [9, 9], [10, 10], [11, 11], [5, 3], [6, 4], [7, 5], [5, 7], [6, 8], [7, 9], [3, 5], [3, 5], [3, 5], [9, 7], [9, 7], [9, 7], [2, 8], [3, 8], [4, 8], [4, 8], [4, 9], [4, 10], [8, 2], [8, 3], [8, 4], [8, 4], [9, 4], [10, 4]]

# Find number of disk combinations
def findCombinations(diskLocations):
combinations = itertools.permutations(diskLocations, len(diskLocations))

return list(combinations).sorted()[0]

print(findCombinations(diskLocations))
``````

Feel free to run this and share your results!

Don’t actually do this. Although this code theoretically works, there is not enough computing power in the world to actually run this code. I did the math, and even in the most optimized circumstances, which this code is definitely not, it would take up more than 1.1 novemdecillion bytes of memory, or 1 followed by 60 zeros. For code that runs in a reasonable amount of time and generates a very short path, have a look at the program below:

``````import itertools
import turtle

diskLocations = [[1, 1], [2, 2], [3, 3], [3, 3], [3, 3], [4, 4], [5, 5], [7, 7], [8, 8], [9, 9], [9, 9], [9, 9], [10, 10], [11, 11], [5, 3], [6, 4], [7, 5], [5, 7], [6, 8], [7, 9], [3, 5], [3, 5], [3, 5], [9, 7], [9, 7], [9, 7], [2, 8], [3, 8], [4, 8], [4, 8], [4, 9], [4, 10], [8, 2], [8, 3], [8, 4], [8, 4], [9, 4], [10, 4]]
robotLocation = [1, 3]

robotPath = []

pathDistance = 0

# Find number of disk combinations
def findCombinations(diskLocations):
global pathDistance
combinations = []
for i in range(len(diskLocations)):
xDif = abs(diskLocations[i][0] - robotLocation[0])
yDif = abs(diskLocations[i][1] - robotLocation[1])
xSqr = xDif ** 2
ySqr = yDif ** 2
distance = (xSqr + ySqr) ** 0.5
combinations.append([distance, diskLocations[i]])
combinations.sort()
pathDistance = pathDistance + combinations[0][0]
return combinations[0][1]

for i in range(len(diskLocations)):
closestDisk = findCombinations(diskLocations)
robotPath.append(closestDisk)
robotLocation = closestDisk
diskLocations.remove(closestDisk)

print(robotPath)
print(pathDistance)
tur = turtle.Turtle()
tur.fillcolor("red")

for i in range(len(robotPath)):
tur.goto(robotPath[i][0] * 50, robotPath[i][1] * 50)
tur.stamp()

turtle.done()
``````

This will pop up with a window, that when overlaid over a spin up field will reveal what should be among the most efficient skills run paths.

8 Likes

theoretically, could you run the short one as many times as it takes to calculate a full skills run?

i realize now you cant edit posts anymore. where would i run this script? like what software

The short one should calculate a full skills run on the first go thanks to the following part:

``````for i in range(len(diskLocations)):
closestDisk = findCombinations(diskLocations)
robotPath.append(closestDisk)
robotLocation = closestDisk
diskLocations.remove(closestDisk)
``````

This iterates over the function, calculating the closest disk to the current one, and so on until all the disks on the field are gone.

5 Likes

This script runs using Python, which can be downloaded from the Python website. Then, once it’s installed, download main.zip (612 Bytes) and extract it. After that, open up a terminal in the folder you downloaded it to and run `python3 main.py`. A window should hopefully pop up with the path.

3 Likes

This is a neat tool and I can’t wait to explore its uses further as both for my team and other teams I help mentor.

2 Likes