-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (31 loc) · 1.16 KB
/
main.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
30
31
32
33
34
35
36
import Backtracking
import Hillclimb
import Beam
import SimulatedAnnealing
import MinConflicts
from Utils import printBoard, numAttacks
import time
def testMethod(method, name, n):
start = time.time()
s = method.findOneSolution(n)
end = time.time()
print("\n")
print(name + " result: " + str(numAttacks(s)))
print("Time taken: " + str(end-start) + "s")
printBoard(s)
def successRate(method, n, tests):
count = 0
for i in range(tests):
score = numAttacks(method.findOneSolution(n))
if score == 0:
count += 1
return count / tests
#testMethod(Backtracking, "Backtracking", 20)
testMethod(Hillclimb, "Steepest ascent hill climb", 50)
testMethod(Beam, "Local beam search", 50)
testMethod(SimulatedAnnealing, "Simulated Annealing hill climb", 50)
testMethod(MinConflicts, "Minimum conflicts heuristic", 50)
#print("Min Conflicts accuracy: " + str(successRate(MinConflicts, 50, 100)))
#print("Hillclimb accuracy: " + str(successRate(Hillclimb, 10, 100)))
#print("Local beam search accuracy: " + str(successRate(Beam, 10, 100)))
#print("Simulated Annealing accuracy: " + str(successRate(SimulatedAnnealing, 10, 100)))