|
@@ -64,7 +64,7 @@ def naive(start):
|
|
|
# took too long
|
|
|
if (count >= 10000):
|
|
|
print("took too long")
|
|
|
- return False
|
|
|
+ return 10000
|
|
|
|
|
|
# check if this part of the domain(solution) is valid
|
|
|
if (valid(working, index[0], index[1], i)):
|
|
@@ -92,9 +92,9 @@ def naive(start):
|
|
|
|
|
|
|
|
|
# if we exit without assigning everything, we should have failed
|
|
|
- if (unassigned): return False
|
|
|
+ if (unassigned): return 10000
|
|
|
|
|
|
- return (working, count)
|
|
|
+ return count
|
|
|
|
|
|
|
|
|
# returns a board (domains) where inferences are made for the cell at row, col
|
|
@@ -171,7 +171,9 @@ def forward(start):
|
|
|
if (working[i][j] != 0):
|
|
|
domains = infer(domains, working, i, j, working[i][j])
|
|
|
|
|
|
- return solve(working, domains, unassigned, 0)
|
|
|
+ result = solve(working, domains, unassigned, 0)
|
|
|
+ if (result): return result[1]
|
|
|
+ else: return 10000
|
|
|
|
|
|
|
|
|
# returns size of domain for a given index
|
|
@@ -321,20 +323,24 @@ def heuristic(start):
|
|
|
if (working[i][j] != 0):
|
|
|
domains = infer(domains, working, i, j, working[i][j])
|
|
|
|
|
|
- return solveh(working, domains, unassigned, 0)
|
|
|
+ result = solveh(working, domains, unassigned, 0)
|
|
|
+ if (result): return result[1]
|
|
|
+ else: return 10000
|
|
|
|
|
|
|
|
|
def main():
|
|
|
+ plt.ioff()
|
|
|
+ plt.switch_backend('agg')
|
|
|
averages = []
|
|
|
bverages = []
|
|
|
cverages = []
|
|
|
|
|
|
- for i in range(0, 72):
|
|
|
+ for i in range(1, 72):
|
|
|
avgA = 0
|
|
|
avgB = 0
|
|
|
avgC = 0
|
|
|
for j in range(1, 11):
|
|
|
- filepath = "sudoku_problems/" + i + "/" + j + ".sd"
|
|
|
+ filepath = "sudoku_problems/" + str(i) + "/" + str(j) + ".sd"
|
|
|
|
|
|
# import board
|
|
|
with open(filepath) as file:
|