from board import singleboard
#Generates a single board
def generateBoard():
board=[]
for i in range(8):
board.append(randint(0,7))
return board
#Generates multiple boards
def generateBoards(size):
boards=[]
for i in range(size):
boards.append(singleboard(generateBoard()))
return boards
#Uses the Hill Climb to solve the n Queen problem I have not figured out how to implement
#random restarts quite yet
def hillClimb(problem):
while(optimizationCheck == False and problem.calculate() != 0):
current = problem
for Neighbor in problem.generateNeighbors():
if Neighbor.calculate() < current.calculate():
current = Neighbor
#Uses optimizationCheck
if problem.optimizationCheck(current) == True:
#restart goes here. I dont know how to add in the random restart. i'm not sure how to do it without #creating an entirely new def for the restart
else:
problem = current
return problem
I am doing the hill climb approach to solve the n-queen problem. I have been able to get the hill climbing portion down, but i still need to implement random restarts with the hill climbing. This is my driver class for my the program. How can i have it implement random restarts with out creating a new def for the restarts. It needs to go inside the hill climb def
Aucun commentaire:
Enregistrer un commentaire