lab 5

docx

School

Arizona State University *

*We aren’t endorsed by this school

Course

360

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

9

Uploaded by ProfStraw17234

Report
Jordan Whitecar IFT360 Lab 5 Class explanations: EightQueenGame: this class defines the game being run, it sets the rules for how the pieces can move, and how the game is run. EightQueenGameSolver: this class is the AI that attempts to solve the game, it contains several different “methods” of doing this, including two different brute force methods, a hill-climbing method, and when complete, a simulated annealing method.
1)
2)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
3) Hill climbing method starts with a solution:
4) Second hill-climb finds a local minimum in 6 moves:
5) Restarting hill-climb restarts 6 times and finds a solution different than the two brute force methods:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
After running for 30 minutes, new code does nothing: Suspect I made a mistake, so started from scratch: results in same issue, suspect something wrong with lab instructions. simulated annealing code:
def simulated_annealing(initial_position): #check if initial position is a solution! old_p = initial_position[:] old_n_attacks = EightQueenGame.get_num_attacks(initial_position) if old_n_attacks == 0: print("Initial State is a solution!", initial_position) return True T = 0.70 while True: #extend current position by checking all neighboring positions new_positions = EightQueenGame.extend_position(old_p) new_n_attacks = [] #get number of attacks for each neighboring position for i in range(len(new_positions)): n = EightQueenGame.get_num_attacks(new_positions[i]) new_n_attacks.append(n) #get index of the neighboring position min # attacks new_p_indx = random.randrange(len(new_n_attacks)) n_attacks = new_n_attacks[new_p_indx] #check if that is a solution if n_attacks == 0: print("Solution found:", new_positions[new_p_indx])
return True #if no neighboring position has a lower number of attacks, hill climbing gets stuck! if old_n_attacks <= n_attacks: print("Hill Climbing Reached a Local Minimum at Position:", new_positions[new_p_indx]) return False #only accept worse positions with some probability T, then reduce T if old_n_attacks<= n_attacks: d=random.random() if d<T: old_p = (new_positions[new_p_indx])[:] old_n_attacks = EightQueenGame.get_num_attacks(old_p) if T > 0.1: T -= 0.01
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help