Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion week7/tsp_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import math,random
from collections import defaultdict

# ALEXNOTE: I am curious about which areas changed from before. Hoping you'll walk us through it during our meeting time.
# Also, since C++ is so much faster, have you considered rewriting in C++?

def calSlope(a,b):
x1,y1 = a
x2,y2 = b
Expand Down Expand Up @@ -29,6 +32,7 @@ def findConvex(Route,end):
return Route

def distance(a, b):
# ALEXNOTE: have you considered caching results? If some number combinations are frequently used...
return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)

def totalDistance(result):
Expand Down Expand Up @@ -171,4 +175,4 @@ def optimize(result, mode, randomNum, looptime):

# name = 'output'
# with open(f'{name}_{k}.csv', 'w') as f:
# f.write(format_tour(result) + '\n')
# f.write(format_tour(result) + '\n')