-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSudokuSolver.py
29 lines (24 loc) · 1.05 KB
/
SudokuSolver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from time import time
from ConstraintPropagation import ConstraintPropagation
from RelaxationLabeling import RelaxationLabeling
"""
Set up and solve the Sudoku boards using 2 techniques: Constraint Propagation with Backtracking & Relaxation Labeling
"""
testFile = 'testFiles/game1.txt'
# The domain of legal values for each cell are the integers [1,9]
boardDimension = 9
print("Solving with Constraint Propagation\n-----------------------------------")
constrainPropagationSolver = ConstraintPropagation(boardDimension, testFile.format())
start = time()
isSolved1 = constrainPropagationSolver.solve()
end = time()
print(constrainPropagationSolver)
print("Time elapsed: {}".format(end - start))
print("Board was solved: {}\n".format(isSolved1))
print("Solving with Relaxation Labeling\n-----------------------------------")
relaxationLabelingSolver = RelaxationLabeling(boardDimension, testFile.format())
start = time()
isSolved2 = relaxationLabelingSolver.solve()
end = time()
print("Time elapsed: {}".format(end - start))
print("Board was solved: {}\n".format(isSolved2))