瀏覽代碼

progress! tsp is crap once you go past like n=12 or smth but otherwise works. sudoku for forward checking is pure trash

tarfeef101 6 年之前
父節點
當前提交
47899ccd0c
共有 4 個文件被更改,包括 6 次插入6 次删除
  1. 二進制
      a1/graph.pdf
  2. 5 5
      a1/sudoku.py
  3. 1 1
      a1/tsp.py
  4. 二進制
      a1/tsph.pdf

二進制
a1/graph.pdf


+ 5 - 5
a1/sudoku.py

@@ -157,14 +157,14 @@ def solve(working, domains, unassigned, count):
 # forward checking solver
 def forward(start):
     working = copy.deepcopy(start) # this is only "filled in values" and 0s
-    domains = gen2Domains(start)
+    domains = gen2Domains(working)
     # unassigned will be a list of positions we have to fill
     unassigned = []
     for i in range(0, 9):
         for j in range(0, 9):
             if (len(domains[i][j]) == 9):
                 unassigned.append((i, j))
-    
+   
     # forward-checking on pre-assigned values
     for i in range(0, 9):
         for j in range(0, 9):
@@ -351,9 +351,9 @@ def main():
             for l in board:
                 board[board.index(l)] = list(map(lambda x: int(x), l.split()))
             
-            avgA += naive(board)
-            avgB += forward(board)
-            avgC += heuristic(board)
+            avgA += naive(copy.deepcopy(board));print(i, j)
+            avgB += forward(copy.deepcopy(board));print(i, j)
+            avgC += heuristic(copy.deepcopy(board));print(i, j)
             
         averages.append(avgA / 10.0)
         bverages.append(avgB / 10.0)

+ 1 - 1
a1/tsp.py

@@ -123,7 +123,7 @@ def main():
         averages.append(average / 10.0)
     
     figure, axes = plt.subplots(1, 1, True)
-    axes.plot(range(1, 12), averages, label='TSP Solver (Heuristic)')
+    axes.plot(range(1, 14), averages, label='TSP Solver (Heuristic)')
     axes.legend()
     plt.xlabel("Number of Cities")
     plt.ylabel("Average Number of Nodes Generated in 10 Runs")

二進制
a1/tsph.pdf