Sie sind auf Seite 1von 14

Department of Computer

Science, Gujarat University

TRAVEL MAZE Using A*


M.Sc.(AI & ML)2019-2020
Semester-1
Project Guide: Presented By:
Dr. Suchit Purohit 07.Palak Doshi
27.Suraj Singh
Maze Solving

• A simple maze consists of a rectangular grid of cells (usually


square), a starting position, and a “Goal" Position.
Maze Solving

To keep it as simple as possible:


• We will use small 7x7, 8x8, 20x20 and 10x10 mazes as examples.
• We have two types of cells: free cells and occupied cells.
• In occupied cells agent doesn’t allowed to move.
• The agent can start from Initial state and is allowed to travel on
the free cells only.
• each cell is represented by a pair of integers (row,
col) where row is the row number (counted from the top!)
and col is the column number (counted left to right).
Environment Description
• For Solving this problem we want an environment and an agent
which acts in this environment:
• In our case the environment is a classical square maze with below
types of cells:(1) Occupied cells
(2) Free cells
(3) Start Position cell (Taking Value from the User)
(4) Goal Position cell (Taking Value from the User)
• Our agent has allowed to move only on free cells, and whose sole
purpose in maze is to get to the goal only.
• We define free cells using 0’s , block cells using 1’s , start position
using yellow star and Goal position with red star .
Environment Description
• In our model, the agent will be "encouraged" to find the shortest
path to the target cell by a simple rewarding scheme:
• We can perform 8 actions that is :
• This is a list of all 8 directional movements from any location; up,
up/right, right, down/right, down, down/left, left, up/left
Finding Path Using A*
• A* achieve optimality and completeness , two important property
of search algorithms.

• When a search algorithm has the property of optimality, it means


it is guaranteed to find the best possible solution. When a search
algorithm has the property of completeness, it means that if a
solution to a given problem exists, the algorithm is guaranteed to
find it.
Finding Path Using A*
To find the Path using A* first we have to understand following:
• Staring node – where to start searching from.
•Goal node – The target to stop searching.
•F’ – Total cost of node
•g – g is the cost to reach starting node to current node.
•h’ – The estimated cost of getting distance from the current state
to goal state.
The A* algorithm Use formula for finding path is F’ = g + h’.
Implementation
• We used data structure to implement open list and closed list.
• Open list : Open list contains nodes that have been generated and
have had heuristic function applied to them but which have not
yet been examined.
• Close list : Close list contains nodes that have been already
examined.
Algorithm
• We create two lists – Open List and Closed List.
(1) Initialize the open list.
(2) Initialize the Closed list.
put the starting node on the open list(you can leave its f’ at zero).
(3) While the open list is not empty,
-(a)find the node with value F’ and put it in a Open list.
-(b)generate F’s successors , Now put it successors in open list and
its parent in closed list.
Algorithm
-(c)For each successor
• If successor is the goal, stop search and make it goal state.
• If a node with same position as successor is in the open list which
has a lower F’ than successor, skip this successor.
• If a node with the same position as successor is in the closed list
which has a lower F’ than successor skip it, otherwise add the
node to the open list.
-(d)Push F’ value in the closed list.
Calculate Heuristic Value
• Here is two ways to calculate heuristics value.
(1) Calculate Exact value(which is time consuming).
(2) Approximate value of h’ using some heuristic(less time
consuming).
So, we are using here Approximate value for calculate heuristic
value.
Approximation Heuristic(Distance Formula)

• It is the distance between the current cell and the goal cell using
the distance formula.
• To do this, we just apply Pythagoras’ theorem to find the distance
between two points, based on us knowing the difference of the
two along the x and y axis.
h = sqrt((current_cell.x – goal.x)2 + abs(current_cell.y – goal.y)2)
We can use distance formula to find the heuristic value when we
have to allowed move in any directions.
References

• https://www.geeksforgeeks.org/a-search-algorithm/

• https://brilliant.org/wiki/a-star-search/

• https://www.samyzaf.com/ML/rl/qmaze.html
Thank You

Das könnte Ihnen auch gefallen