Browse Source

submission?

tarfeef101 6 years ago
parent
commit
dbc21ad5f4
6 changed files with 20 additions and 18 deletions
  1. BIN
      a1/graph.pdf
  2. 2 0
      a1/sudoku.py
  3. 2 2
      a1/tsp.py
  4. 16 16
      a1/tsp_dumb.py
  5. BIN
      a1/tspdumb.pdf
  6. BIN
      a1/tsph.pdf

BIN
a1/graph.pdf


+ 2 - 0
a1/sudoku.py

@@ -141,6 +141,7 @@ def solve(working, domains, unassigned, count):
     for i in domains[index[0]][index[1]]:
         working[index[0]][index[1]] = i
         newdomains = infer(domains, working, index[0], index[1], i)
+        domains[index[0]][index[1]].remove(i)
         count += 1
         # took too long
         if (count >= 10000):
@@ -161,6 +162,7 @@ def solve(working, domains, unassigned, count):
         if (result[0]):
             return result
         else:
+            #domains[index[0]][index[1]].remove(i)
             count = result[1]
     
     return (False, count)

+ 2 - 2
a1/tsp.py

@@ -114,7 +114,7 @@ def main():
     plt.switch_backend('agg')
     averages = []
     
-    for i in range(1, 17):
+    for i in range(1, 12):
         average = 0
         for j in range(1, 11):
             filepath = "tsp_problems/" + str(i) + "/instance_" + str(j) + ".txt"
@@ -123,7 +123,7 @@ def main():
         averages.append(average / 10.0)
     
     figure, axes = plt.subplots(1, 1, True)
-    axes.semilogy(range(1, 17), 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")

+ 16 - 16
a1/tsp_testing.py → a1/tsp_dumb.py

@@ -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()

BIN
a1/tspdumb.pdf


BIN
a1/tsph.pdf