Question

In: Electrical Engineering

construct A*star algorithm for solving the 8-puzzle problem . Use MATLAB or Python .Your code should...

construct A*star algorithm for solving the 8-puzzle problem . Use MATLAB or Python .Your code should include two heuristic functions -misplaced tiles and calculation of manhattan distance. The code should work for all cases of puzzle.

Solutions

Expert Solution

This program implements [A* search algorithm] to solve 8-puzzle problem (a type of slider puzzle). It uses the sum of moves to current step and Manhattan priority function as cost function. A priority queue of search node containing number of moves, current board and previous search node is created. For each move, the search node with minimum cost is dequeued and neighboring nodes of this search node are then inserted into the priority queue. The sequence of moves using fewest number of moves to solve the puzzle is obtained when the goal board is ultimately dequeued (total number of moves is always at least its priority).

Board data type represents a priority queue of search node. Its API is as follows:

  public class Board {
      public Board(int[][] blocks)           // construct a board from an N-by-N array of  
                                                blocks
                                             // (where blocks[i][j] = block in row i, column
                                                  j)
      public int dimension()                 // board dimension N
      public int hamming()                   // number of blocks out of place
      public int manhattan()                 // sum of Manhattan distances between blocks and  
                                                goal
      public boolean isGoal()                // is this board the goal board?
      public Board twin()                    // a board obtained by exchanging two adjacent 
                                                blocks in the same row
      public boolean equals(Object y)        // does this board equal y?
      public Iterable<Board> neighbors()     // all neighboring boards
      public String toString()               // string representation of the board 
  }

Solver

Check whether the board is solvable by simultaneously solving a twin board derived from initial board by exchanging two adjacent blocks. Test client solver is in the main function. API is shown below:

  public class Solver {
      public Solver(Board initial)            // find a solution to the initial board (using 
                                                 the A* algorithm)
      public boolean isSolvable()             // is the initial board solvable?
      public int moves()                      // min number of moves to solve initial board;  
                                                 -1 if no solution
      public Iterable<Board> solution()       // sequence of boards in a shortest solution; 
                                                  null if no solution
      public static void main(String[] args)  // solve a slider puzzle 
  }

Related Solutions

For this problem, you should: describe the algorithm using aflowchart and thenwrite Python code...
For this problem, you should: describe the algorithm using a flowchart and thenwrite Python code to implement the algorithm.You must include:a.) a picture of the flowchart you are asked to create,b.) a shot of the Python screen of your code, andc.) a shot of the Python screen of your output.Program Requirements: Your application will implement a stopwatch to beused during a 1500-meter race in a swimming match. The input to theapplication will be the number of seconds for two different...
Implement the recursive LU factorization algorithm in Python. Use plenty of comments to explain your code....
Implement the recursive LU factorization algorithm in Python. Use plenty of comments to explain your code. While you are coding, it is helpful to break up your code into sub-functions and test the sub-functions as you go along.
Write a Python program to solve the 8-puzzle problem (and its natural generalizations) using the A*...
Write a Python program to solve the 8-puzzle problem (and its natural generalizations) using the A* search algorithm. The problem. The 8-puzzle problem is a puzzle invented and popularized by Noyes Palmer Chapman in the 1870s. It is played on a 3-by-3 grid with 8 square blocks labeled 1 through 8 and a blank square. Your goal is to rearrange the blocks so that they are in order, using as few moves as possible. You are permitted to slide blocks...
Lab - Validate all of the row in the puzzle. // //   - Use this code...
Lab - Validate all of the row in the puzzle. // //   - Use this code as a start of the program. //   - Catch all duplicate entries in each row. //   - Catch any numbers that are not 1 - 9. //   - Display an error msg for each error found. //   - At end, display a msg stating how many errors were found. //===================================================================== import java.util.*; public class Lab_ValidateAllRows    {    public static void main (String[] args)...
Describe an efficient recursive algorithm for solving the element uniqueness problem
Describe an efficient recursive algorithm for solving the element uniqueness problem, which runs in time that is at most O(n2) in the worst case without using sorting.    
For a catapult project I must make a MATLAB code that should make use of the...
For a catapult project I must make a MATLAB code that should make use of the projectile motion equations so for a given input range R (horizontal distance from the catapult to the target), the code outputs the necessary velocity and firing angle of the catapult. What is the code for this? I am lost.
For a catapult project I must make a MATLAB code that should make use of the...
For a catapult project I must make a MATLAB code that should make use of the projectile motion equations so for a given input range R (horizontal distance from the catapult to the target), the code outputs the necessary velocity and firing angle of the catapult. I must be able to input ranges: 7ft, 8ft and 9ft and the output of the code should give me the possible velocities and theta of the catapult.
Problem 4 ..... you can use Matlab Using the same initial code fragment as in Problem...
Problem 4 ..... you can use Matlab Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandstop filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce the below is the Problem 1 initail code .. you can use it Matlab The following cilab code generates a 10-second “chirp”...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
MATLAB CODE: Making cubic spline iterpolation function. Then, To solve use Tridiagonal matrix algorithm(TDMA) xi -0.5...
MATLAB CODE: Making cubic spline iterpolation function. Then, To solve use Tridiagonal matrix algorithm(TDMA) xi -0.5 -0.4 -0.2 0 0.2 0.4 0.6 0.8 yi 0.04 0.1 0.4 1 0.35 0.2 0.3 0.04
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT