Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do not edit the main.py file. I only need to work on the hill_climbing.py file. Modify so that it does hill climbing with random restarts

Do not edit the main.py file. I only need to work on the hill_climbing.py file. Modify so that it does hill climbing with random restarts and simulated annealing. Modify it to the below-mentioned requirements.

Alternative sliding tiles puzzle -

Square grid of NxN. Each square in the grid has a distinct number [1, N^2-1] or a blank. There can be multiple blanks. The cost of moving a tile is equal to the number on the tile. Goal states are to have all the blanks next to each other at the top left corner or the bottom right of the corner. The numbers need to be in ascending order.

Ex: 3 5 7 1 2 3

B 2 1 -------> 5 6 7

5 6 7 8 B B

8 B B

The program needs to accept the following command-line arguments - the file name of the board to read in and the number of seconds to run the algorithm.

It needs to give the following outputs - sequence of moves in written form. Example, "3 left" or "3 up" to indicate how the 3 tile moves, the number of moves the solution required, the cost of the solution, the branching factor, the heuristic value, and number of heuristics explores.

I have the following code.

hill_climbing.py image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedmain.py

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

heuristic_value[i] = calc_for_heuristic(move_value) heuristic_value = heuristic_value.astype(int) \# find the index of the move with the minimum heuristic value min_index = np.where(heuristic_value == min(heuristic_value)) \# if there is more than one move with the minimum heuristic value, choose one randomly if len(min_index[0]) 1 : min_index = random.choice(min_index[0]) else: \#in_index = int(np.asarray(min_index)) updated_board = move_values[min_index] updated_board = updated_board.astype(int) \# if the updated board is the same as the original board, return the original board if np.array_equal(updated_board, board) return board legalMoves. append ([ row, col +1, row, col ], str( board [ row ][col+1])+ Left" ]) \#print (str (board [ row ][ col +1])+ "Left") return legalMoves def move(board, moveTuple): new_board = board . copy ( ) new_board[moveTuple[2] [moveTuple[3]] = new_board[moveTuple [0]][moveTuple [1]] new_board [moveTuple [0] [ moveTuple [1] ]=0 return new_board \# Press the green button in the gutter to run the script. if if len(sys.argv) >4 or len(sys.argv)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions