|
@@ -5,16 +5,16 @@ from heapq import heappush, heappop
|
|
|
from random import randint
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
-distances = []
|
|
|
+#distances = []
|
|
|
n = 0
|
|
|
|
|
|
# returns hueristic value
|
|
|
def heuristic(source, target, dist):
|
|
|
- #return 0
|
|
|
- for i in range(0, min(n * 2, n ** 2)):
|
|
|
- if (dist <= distances[i]):
|
|
|
- return 0
|
|
|
- return dist
|
|
|
+ return 0
|
|
|
+ #for i in range(0, min(n * 2, n ** 2)):
|
|
|
+ # if (dist <= distances[i]):
|
|
|
+ # return 0
|
|
|
+ #return dist
|
|
|
|
|
|
|
|
|
# returns weight(distance) between 2 vertices
|
|
@@ -84,14 +84,14 @@ def tsp(filename):
|
|
|
counter += 1
|
|
|
cities[cities.index(l)] = temp
|
|
|
|
|
|
- distances = []
|
|
|
+ #distances = []
|
|
|
|
|
|
- for i in range(0, len(cities) - 1):
|
|
|
- for j in range(i, len(cities)):
|
|
|
- dist = weight(cities[i], cities[j])
|
|
|
- distances.append(dist)
|
|
|
+ #for i in range(0, len(cities) - 1):
|
|
|
+ # for j in range(i, len(cities)):
|
|
|
+ # dist = weight(cities[i], cities[j])
|
|
|
+ # distances.append(dist)
|
|
|
|
|
|
- distances.sort()
|
|
|
+ #distances.sort()
|
|
|
|
|
|
# add in goal state
|
|
|
cities.append(copy.deepcopy(cities[0]))
|
|
@@ -108,13 +108,13 @@ def tsp(filename):
|
|
|
|
|
|
|
|
|
def main():
|
|
|
- global distances
|
|
|
+ #global distances
|
|
|
global n
|
|
|
plt.ioff()
|
|
|
plt.switch_backend('agg')
|
|
|
averages = []
|
|
|
|
|
|
- for i in range(1, 10):
|
|
|
+ for i in range(1, 12):
|
|
|
average = 0
|
|
|
for j in range(1, 11):
|
|
|
filepath = "tsp_problems/" + str(i) + "/instance_" + str(j) + ".txt"
|
|
@@ -123,10 +123,10 @@ def main():
|
|
|
averages.append(average / 10.0)
|
|
|
|
|
|
figure, axes = plt.subplots(1, 1, True)
|
|
|
- axes.semilogy(range(1, 10), averages, label='TSP Solver (Heuristic)')
|
|
|
+ axes.semilogy(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("tsph.pdf")
|
|
|
+ plt.savefig("tspdumb.pdf")
|
|
|
|
|
|
main()
|