|
@@ -72,7 +72,6 @@ def tsp(filename):
|
|
|
with open(prob) as file:
|
|
|
prob = file.read().splitlines()
|
|
|
|
|
|
- global n
|
|
|
n = int(prob[0])
|
|
|
cities = prob[1:]
|
|
|
counter = 0
|
|
@@ -85,7 +84,6 @@ def tsp(filename):
|
|
|
counter += 1
|
|
|
cities[cities.index(l)] = temp
|
|
|
|
|
|
- global distances
|
|
|
distances = []
|
|
|
|
|
|
for i in range(0, len(cities) - 1):
|
|
@@ -104,15 +102,19 @@ def tsp(filename):
|
|
|
# add start state, list of visited, and distancesofar to frontier
|
|
|
heappush(frontier, [0, cities[0], [0]])
|
|
|
|
|
|
- print(solve(frontier, cities))
|
|
|
+ result = solve(frontier, cities)
|
|
|
+ print(result)
|
|
|
+ return result
|
|
|
|
|
|
|
|
|
def main():
|
|
|
+ global distances
|
|
|
+ global n
|
|
|
plt.ioff()
|
|
|
plt.switch_backend('agg')
|
|
|
averages = []
|
|
|
|
|
|
- for i in range(1, 13):
|
|
|
+ for i in range(1, 14):
|
|
|
average = 0
|
|
|
for j in range(1, 11):
|
|
|
filepath = "tsp_problems/" + str(i) + "/instance_" + str(j) + ".txt"
|
|
@@ -121,10 +123,10 @@ def main():
|
|
|
averages.append(average / 10.0)
|
|
|
|
|
|
figure, axes = plt.subplots(1, 1, True)
|
|
|
- axes.plot(range(1, 13), averages, label='TSP Solver (Heuristic)')
|
|
|
+ axes.plot(range(1, 12), averages, label='TSP Solver (Heuristic)')
|
|
|
axes.legend()
|
|
|
plt.xlabel("Number of Cities")
|
|
|
plt.ylabel("Average Number of Nodes Generated in 10 Runs")
|
|
|
- plt.savefig("graph.pdf")
|
|
|
+ plt.savefig("tsph.pdf")
|
|
|
|
|
|
-main()
|
|
|
+main()
|