Skip to content

Instantly share code, notes, and snippets.

@mhornbacher
Created June 9, 2017 14:26
Show Gist options
  • Save mhornbacher/7c32b644ef188717896d28d1d302ef7b to your computer and use it in GitHub Desktop.
Save mhornbacher/7c32b644ef188717896d28d1d302ef7b to your computer and use it in GitHub Desktop.
Takes a list of X, and Y coordinates and calculates the edge cost between all of them. X^2 runtime
def build_edges(x, y):
edges = []
for i in range(len(x)):
for k in range(len(x)):
dist = math.sqrt(((x[i] - x[k]) ** 2) + ((y[i] - y[k]) **2))
edges.append([i, k, dist])
return edges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment