Finding optimal solution of 15 puzzle
This presentation is the property of its rightful owner.
Sponsored Links
1 / 15

Finding Optimal Solution of 15 puzzle PowerPoint PPT Presentation


  • 99 Views
  • Uploaded on
  • Presentation posted in: General

Finding Optimal Solution of 15 puzzle. B94902062 NTUCSIE Kai-Yung Chiang. 15 puzzle introduction. Initial states : a solvable puzzle, including numbered 1~15 tiles and a blank tile 0 Goal state : puzzle in which tiles 0 ~ 15 are in well permutation from row to column

Download Presentation

Finding Optimal Solution of 15 puzzle

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Finding optimal solution of 15 puzzle

Finding Optimal Solution of 15 puzzle

B94902062 NTUCSIE

Kai-Yung Chiang


15 puzzle introduction

15 puzzle introduction

Initial states: a solvable puzzle, including numbered 1~15 tiles and a blank tile 0

Goal state: puzzle in which tiles 0 ~ 15 are in well permutation from row to column

A (valid) move: swap blank tile with its neighboring tile

The optimal solution: given a initial state, find the move sequence such that it is a solution taking the fewest moves to reach the goal state


Searching algorithm

Searching Algorithm

A* search

Each node has heuristic (the estimating distance from current state to goal state)

Each node’s evaluation function = heuristic + total moves from initial state

A* always expands the fringe node whose evaluation function is minimum


Example

: fringe nodes

: expanded nodes h: heuristic f: evaluation function

Example

h=45, f=45


Example1

: fringe nodes

: expanded nodes h: heuristic f: evaluation function

Example

h=45, f=45

h=41, f=42

h=45,f=46

h=42, f=43


Example2

: fringe nodes

: expanded nodes h: heuristic f: evaluation function

Example

h=45, f=45

h=41, f=42

h=45,f=46

h=42, f=43

h=45, f=47

h=42, f=44

h=43, f=45


Example3

: fringe nodes

: expanded nodes h: heuristic f: evaluation function

Example

h=45, f=45

h=41, f=42

h=45,f=46

h=42, f=43

h=45, f=47

h=42, f=44

h=43, f=45

h=40,f=42

h=39, f=41

h=45,f=47


Finding optimal solution of 15 puzzle

Pros and cons for A* search

  • Pros:

    • Can find the optimal solution (or admissible) if heuristic function will never overestimate

    • Eliminate number of expanded nodes

  • Cons:

    • Taking more time on expanding each nodes (compared with DFS or BFS):

      • Find minimum nodes (in fringe) to expand

      • Compute heuristic and evaluation function

      • Check, eliminate and update repetitive states

      • Maintain data structure


Speed up by good data structure

Speed up by good data structure

Priority queue: Fibonacci heap

Extract minimum and decrease key in (amortized) O(logn)

Insert in O(1)

Hash function:

Used in checking repetitive states, eliminate number of searching nodes

A* search with above data structure and Manhattan distance as heuristic function could solve 8 puzzle in (averaged) 0.002 seconds

However, still too slow to solve 15 puzzle


More speed up technique

More speed up technique

  • Still too many nodes need to be expanded (though eliminate repetitive states)

  • If f(n) = 2h(n) + moves(n)…

    • Could speed up much, but not admissible.

  • Ideas: try to improve h(n) to be more close to truly needed optimal moves, while still maintaining admissible

  • Disjoint pattern database heuristic instead of Manhattan distance

  • New heuristic = ∑i number of needed moves to well order tiles in pattern i


Pattern database

Pattern database

  • Divide puzzle into 3 disjoint patterns

  • Each pattern has 16!/10!≒5.7 * 106 different combination orders of tiles, and each of them corresponds to a database entry

  • Each entry records moves for aligning these pattern tiles to correct position


Building pattern database

Building pattern database

  • Constructed by bottom up approach

    • Start with well ordered tiles

    • BFS moving blank tile to new states, move is added only when tile in this pattern is swapped with blank tile

    • Add new entry to pattern database if current state has not been traversed (using a bits of array to record this information)


Benchmark and outcome

Benchmark and outcome

  • Randomly generate 100 solvable puzzles:


Benchmark and outcome1

Benchmark and outcome

  • Pattern database heuristic improves nearly 10 moves than Manhattan distance in averaged

  • In most problem instances…

    • Expanded nodes are less than 100,000

    • Could be solved in 30 seconds, and more than half could be solved in 10 seconds

    • CPU% are less than 20%. It might suggest that lots of time are took in communication with database

  • Pattern database heuristic improves a lot


Finding optimal solution of 15 puzzle

Demo

  • http://140.112.249.168/phpAdmin


  • Login