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.

5 Likes

Haven’t tried it myself, but maybe Dr. Djikstra can help?

Dijkstra's algorithm - Wikipedia

2 Likes

True. It would be quite interesting to create a couple of variations of this program using various algorithms and compare the results. If I find time to do this, I’ll make sure to post the results here!

1 Like