Bidirectional Graph Search
Techniques for Finding Shortest
Path in Image Based Maze Problem
Dissertation
Department of Computer Science and Engineering
Sri Sai College of Engineering &Technology, Manawala, Amritsar
17th July, 2019 Navin Kumar
M.Tech (CSE)
SEM IV
Roll No. 1710965
Contents
▪ Introduction to Maze Problem
▪ Uninformed Search Algorithms
• Breadth First SearchAlgorithm
• Death First Search Algorithm
▪ Informed Search Algorithms
• A* Algorithm
 Bidirectional SearchTechnique
▪ Calculations for Image Processing
▪ Implementation
▪ Result Analysis & Discussions
▪ Conclusion and Future Scope
INTRODUCTION
Introduction to Maze Problem
▪ Each Block is of size 100x100 , Image
contains total of 64 blocks in 8X8 matrix.
▪ AWhite block represent a path, which will
correspond to a node in the graph.
▪ A Black block represent a dead end or no
path in the image.
▪ First row will have only one block white and
rest all black representing the starting point.
▪ Last row will have only once block white and
rest all black representing the ending point.
Maze Problem Image
Introduction to Maze Problem (cont.)
Micro mouse Maze Problem Simulated Maze Image Solution Image
GRAPH
SEARCH
ALGORITHMS
Uninformed Search Algorithms
In Uninformed algorithms, there isn’t any additional
information given and used while solving other than the
indication to the start node and the required goal node.
These are also called as blind search algorithms.
The search space is explored according to the predefined
procedure and it doesn’t do anything special for specific
problems.
Breadth First Search Algorithm(Uninformed)
The breadth first search algorithm starts from one state and
consider all the states that are reachable from there i.e the
adjacent to it.Thereby dividing the nodes into different
levels eventually finding the goal state at the corresponding
level.
Its works best for the problems which are of moderate in
terms of search space and the time complexity is O(bd).
Where b is branching level and d is depth at which solution
resides.
Breadth First Search Algorithm Example
2
3
1
4 5
6
QUEUE : 1
2
3
1
4 5
6
QUEUE : 2,4
=>
QUEUE : 4,3,5
=>
2
3
1
4 5
6
2
3
1
4 5
6
QUEUE : 3,5,6
=>
2
3
1
4 5
6 QUEUE : 3,5,6
=>
2
3
1
4 5
6
QUEUE : 5,6
1 2 3
4 5 6
Breadth First Search Algorithm Example(Cont.)
2
3
1
4 5
6
7
QUEUE : EMPTY
=>
2
3
1
4 5
6
8
QUEUE : 6
The Algorithm will terminate
here as queue is empty
indicating that all nodes are
explored.
As the branching factor b is 2 and the maximum depth is d is
2 raising the time complexity to 22 = 4.
The white edges in the graph are the one which are not used
in BFS, although they might lead us to the goal state as well.
Breadth first Level Tree After the Algorithm
2
3
1
4 5
6
1
2 4 Level :1
Level :0
Level :2
=>
3 5 6
Initial Graph BFS level tree resulting
after the Algorithm
Depth First Search Algorithm(Uninformed)
Depth-first search always expands the deepest node in the
current frontier of the search tree.The search proceeds
immediately to the deepest level of the search tree, where
the nodes have no successors.
The algorithm is efficient in terms of space when compared
to breadth first search as it drops the nodes when backtracks
from a node.The time complexity is same as of BFS.
Its applicable when search space is large and goal node is
very far from initial node or state.
Depth First Search Algorithm Example
2
3
8
1
4 5 9
6
7 2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
7
1
2
3
Expanded by going
in one direction only
i.e node 2
Expanded by going
in one direction only
i.e node 5
Expanded by going
in one direction only
i.e node 5
Depth First Search Algorithm Example(Cont.)
2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
7
4 5 2
3
8
1
4 5 9
6
7
6
Backtrack
2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
77 8 9Backtrack
Depth First Search Algorithm Example(Cont.)
2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
7
2
3
8
1
4 5 9
6
7
10 11 12
13 14 15
Backtrack
Backtrack
Backtrack
Backtrack
Depth First Search Algorithm Example(Cont.)
2
3
8
1
4 5 9
6
7
16
Backtrack
2
3
8
1
4 5 9
6
7
17
Backtrack
The 17th is where we get the resultant DFS result.The white
edges are not part of it.
As the algorithm goes into one direction to extreme detpth and
then backtracks so its good for problem which are having large
search space and where goal resides far from initial state.
Informed Search Algorithms
▪ The key idea behind informed search algorithms is that of heuristics. So far,
our search algorithms only required a goal test. Given a node, they could
only find out whether it is a goal or not. A heuristic provides more
information; given a node, it provides an estimate of its distance from a
goal. Unlike a search algorithm which works for any search problem, a
heuristic is designed for a particular search problem. For the routing
problem (finding a path from one city to another), we could use Euclidean
distance as heuristic. For the Pacman problem discussed in the previous
post, Manhattan distance could be used as a heuristic.We’ll return to this
idea of heuristics to inject domain specific knowledge in search algorithms
and how to design them for a problem at hand but let’s first see some
algorithms which can use these heuristics.
Heuristics – Straight Line Heuristics
HeuristicValues For Informed
Searches
Hstart= (𝑥 𝐸 − 𝑥1)2+(𝑦 𝐸 − 𝑦1)2
A* Algorithm
A* search is the most commonly known form of best-first search.
It uses heuristic function h(n), and cost to reach the node n from
the start state g(n). It has combined features of UCS and greedy
best-first search, by which it solve the problem efficiently. A*
search algorithm finds the shortest path through the search space
using the heuristic function. This search algorithm expands less
search tree and provides optimal result faster. A* algorithm is
similar to UCS except that it uses g(n)+h(n) instead of g(n).
IMAGE
PROCESSING
PART
Calculations For Image Processing
In order to analyze the maze one need to get the pixel intensity of each pixel.
The size of image is approx. 856X856 which counts to 7,32,736 pixels.
There is no possible way to get intensities of these many pixels and then
processing them to make a abstract data type from it is not even conceivable.
As our image is consistent in structure, we can exploit this information in order
to drop the pixels required to be studied for the analysis to just 64 per image
Its based on the fact that our image is made up of blocks each of which is of
100x100 px.The proceeding slide shows how this is implemented in code.
Calculations For Image Processing (Cont.)
▪ Each Pixel is of 100x100 px, instead of going
through each pixel we take the pixel value at the
center of the square.
▪ A value greater than zero is considered as white
and is manipulated as a node in graph
▪ A value equal to zero is considered as no path.
▪ The step is repeated across each row thereby
getting pixel intensities of 64 pixels only.
Color Intensity Manipulation
255 to 100 Node
0 to 20 No PathOr End
Placing Edges on the nodes Obtained
▪ To place an edge for a node there are
only 4 adjacent blocks to check pixel
intensities.
1. One to left of it i.e (x-100,y)
2. One to the right of it i.e (x+100,y)
3. One to the top of it i.e (x,y-100)
4. One to the bottom of it i.e (x,y+100)
If the intensity value is greater than zero then an
edge is inserted between the pair of corresponding
nodes.
Image to graph conversion Demonstration
Start
End
IMPLEMENTATION
Implementation-
Creating a Maze (HTML to Image)
Implementation–
Generating Nodes from Image
Implementation–
Creating Solution Image using BFS & BiBFS
Implementation–
Creating Solution Image using A* & Bi A*
RESULT ANALYSIS
Result Analysis-
For Different MAZE Images
BFS
26X26 to 828.5X828.5 in 30 hops
Time BFS took in seconds: 0.00035715
Total Number of nodes are 174
Bidirectional BFS
Time Bi-BFS took in seconds: 0.00031304
Total Number of nodes are 174
Total Number of Hops are 30
Result Analysis-
For “8X8 MAZE” – BFS VS BiBFS
Result Analysis-
For “8X8 MAZE” – A* VS Bi A*
Result Analysis-
For “16X16 MAZE” – BFS VS BiBFS
Result Analysis-
For “16X16 MAZE” – A* VS Bi A*
BFSVS BiBFSBFSVS BiBFS
Result Analysis-
For “8X8 MAZE” – Comparison for All the Algorithms
Result Analysis-
For “16X16 MAZE” – Comparison for All the Algorithms
Result Analysis For Different MAZE Images
Image Time Hops Nodes
0.00007892 7 41
0.00007296 11 35
0.00007081 10 32
Image Time Hops Nodes
0.00010180 9 35
0.00008297 12 38
0.00013185 14 50
CONCLUSIONS
Conclusion from Maze Problem
• The time taken to run a BFS depends upon how far the initial node and the
goal node i.e. the how number of hops.
• Its also observed that as the number of nodes in maze image i.e. the white
blocks also increases the time, i.e. as search space is expanded the time to
explore it will definitely increase.
• If a path from initial to goal node doesn’t exist then the BFS will explore the
whole search space and eventually terminates with no solution
• At last the image operations like putting and getting pixels on the images
are also overheads which are included while analysisng the performance.
FUTURE SCOPE
Future Scope
It remains a challenging problem when it comes to
extremely large image maze say 1024X1024.
In such case, our approach should rely on informed search
techniques where the heuristic used should not only be
admissible but needs to be consistent as well as our
problem is a graph search.
TheA* search can be a good alternative with heuristic like
the straight line distance of every node from goal node.
Thanks 
Implementation
Url:http://navin.live/maze

Bidirectional graph search techniques for finding shortest path in image based maze problem

  • 1.
    Bidirectional Graph Search Techniquesfor Finding Shortest Path in Image Based Maze Problem Dissertation Department of Computer Science and Engineering Sri Sai College of Engineering &Technology, Manawala, Amritsar 17th July, 2019 Navin Kumar M.Tech (CSE) SEM IV Roll No. 1710965
  • 2.
    Contents ▪ Introduction toMaze Problem ▪ Uninformed Search Algorithms • Breadth First SearchAlgorithm • Death First Search Algorithm ▪ Informed Search Algorithms • A* Algorithm  Bidirectional SearchTechnique ▪ Calculations for Image Processing ▪ Implementation ▪ Result Analysis & Discussions ▪ Conclusion and Future Scope
  • 3.
  • 4.
    Introduction to MazeProblem ▪ Each Block is of size 100x100 , Image contains total of 64 blocks in 8X8 matrix. ▪ AWhite block represent a path, which will correspond to a node in the graph. ▪ A Black block represent a dead end or no path in the image. ▪ First row will have only one block white and rest all black representing the starting point. ▪ Last row will have only once block white and rest all black representing the ending point. Maze Problem Image
  • 5.
    Introduction to MazeProblem (cont.) Micro mouse Maze Problem Simulated Maze Image Solution Image
  • 6.
  • 7.
    Uninformed Search Algorithms InUninformed algorithms, there isn’t any additional information given and used while solving other than the indication to the start node and the required goal node. These are also called as blind search algorithms. The search space is explored according to the predefined procedure and it doesn’t do anything special for specific problems.
  • 8.
    Breadth First SearchAlgorithm(Uninformed) The breadth first search algorithm starts from one state and consider all the states that are reachable from there i.e the adjacent to it.Thereby dividing the nodes into different levels eventually finding the goal state at the corresponding level. Its works best for the problems which are of moderate in terms of search space and the time complexity is O(bd). Where b is branching level and d is depth at which solution resides.
  • 9.
    Breadth First SearchAlgorithm Example 2 3 1 4 5 6 QUEUE : 1 2 3 1 4 5 6 QUEUE : 2,4 => QUEUE : 4,3,5 => 2 3 1 4 5 6 2 3 1 4 5 6 QUEUE : 3,5,6 => 2 3 1 4 5 6 QUEUE : 3,5,6 => 2 3 1 4 5 6 QUEUE : 5,6 1 2 3 4 5 6
  • 10.
    Breadth First SearchAlgorithm Example(Cont.) 2 3 1 4 5 6 7 QUEUE : EMPTY => 2 3 1 4 5 6 8 QUEUE : 6 The Algorithm will terminate here as queue is empty indicating that all nodes are explored. As the branching factor b is 2 and the maximum depth is d is 2 raising the time complexity to 22 = 4. The white edges in the graph are the one which are not used in BFS, although they might lead us to the goal state as well.
  • 11.
    Breadth first LevelTree After the Algorithm 2 3 1 4 5 6 1 2 4 Level :1 Level :0 Level :2 => 3 5 6 Initial Graph BFS level tree resulting after the Algorithm
  • 12.
    Depth First SearchAlgorithm(Uninformed) Depth-first search always expands the deepest node in the current frontier of the search tree.The search proceeds immediately to the deepest level of the search tree, where the nodes have no successors. The algorithm is efficient in terms of space when compared to breadth first search as it drops the nodes when backtracks from a node.The time complexity is same as of BFS. Its applicable when search space is large and goal node is very far from initial node or state.
  • 13.
    Depth First SearchAlgorithm Example 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 1 2 3 Expanded by going in one direction only i.e node 2 Expanded by going in one direction only i.e node 5 Expanded by going in one direction only i.e node 5
  • 14.
    Depth First SearchAlgorithm Example(Cont.) 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 4 5 2 3 8 1 4 5 9 6 7 6 Backtrack 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 77 8 9Backtrack
  • 15.
    Depth First SearchAlgorithm Example(Cont.) 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 2 3 8 1 4 5 9 6 7 10 11 12 13 14 15 Backtrack Backtrack Backtrack Backtrack
  • 16.
    Depth First SearchAlgorithm Example(Cont.) 2 3 8 1 4 5 9 6 7 16 Backtrack 2 3 8 1 4 5 9 6 7 17 Backtrack The 17th is where we get the resultant DFS result.The white edges are not part of it. As the algorithm goes into one direction to extreme detpth and then backtracks so its good for problem which are having large search space and where goal resides far from initial state.
  • 17.
    Informed Search Algorithms ▪The key idea behind informed search algorithms is that of heuristics. So far, our search algorithms only required a goal test. Given a node, they could only find out whether it is a goal or not. A heuristic provides more information; given a node, it provides an estimate of its distance from a goal. Unlike a search algorithm which works for any search problem, a heuristic is designed for a particular search problem. For the routing problem (finding a path from one city to another), we could use Euclidean distance as heuristic. For the Pacman problem discussed in the previous post, Manhattan distance could be used as a heuristic.We’ll return to this idea of heuristics to inject domain specific knowledge in search algorithms and how to design them for a problem at hand but let’s first see some algorithms which can use these heuristics.
  • 18.
    Heuristics – StraightLine Heuristics HeuristicValues For Informed Searches Hstart= (𝑥 𝐸 − 𝑥1)2+(𝑦 𝐸 − 𝑦1)2
  • 19.
    A* Algorithm A* searchis the most commonly known form of best-first search. It uses heuristic function h(n), and cost to reach the node n from the start state g(n). It has combined features of UCS and greedy best-first search, by which it solve the problem efficiently. A* search algorithm finds the shortest path through the search space using the heuristic function. This search algorithm expands less search tree and provides optimal result faster. A* algorithm is similar to UCS except that it uses g(n)+h(n) instead of g(n).
  • 20.
  • 21.
    Calculations For ImageProcessing In order to analyze the maze one need to get the pixel intensity of each pixel. The size of image is approx. 856X856 which counts to 7,32,736 pixels. There is no possible way to get intensities of these many pixels and then processing them to make a abstract data type from it is not even conceivable. As our image is consistent in structure, we can exploit this information in order to drop the pixels required to be studied for the analysis to just 64 per image Its based on the fact that our image is made up of blocks each of which is of 100x100 px.The proceeding slide shows how this is implemented in code.
  • 22.
    Calculations For ImageProcessing (Cont.) ▪ Each Pixel is of 100x100 px, instead of going through each pixel we take the pixel value at the center of the square. ▪ A value greater than zero is considered as white and is manipulated as a node in graph ▪ A value equal to zero is considered as no path. ▪ The step is repeated across each row thereby getting pixel intensities of 64 pixels only. Color Intensity Manipulation 255 to 100 Node 0 to 20 No PathOr End
  • 23.
    Placing Edges onthe nodes Obtained ▪ To place an edge for a node there are only 4 adjacent blocks to check pixel intensities. 1. One to left of it i.e (x-100,y) 2. One to the right of it i.e (x+100,y) 3. One to the top of it i.e (x,y-100) 4. One to the bottom of it i.e (x,y+100) If the intensity value is greater than zero then an edge is inserted between the pair of corresponding nodes.
  • 24.
    Image to graphconversion Demonstration Start End
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
    Result Analysis- For DifferentMAZE Images BFS 26X26 to 828.5X828.5 in 30 hops Time BFS took in seconds: 0.00035715 Total Number of nodes are 174 Bidirectional BFS Time Bi-BFS took in seconds: 0.00031304 Total Number of nodes are 174 Total Number of Hops are 30
  • 32.
    Result Analysis- For “8X8MAZE” – BFS VS BiBFS
  • 33.
    Result Analysis- For “8X8MAZE” – A* VS Bi A*
  • 34.
    Result Analysis- For “16X16MAZE” – BFS VS BiBFS
  • 35.
    Result Analysis- For “16X16MAZE” – A* VS Bi A* BFSVS BiBFSBFSVS BiBFS
  • 36.
    Result Analysis- For “8X8MAZE” – Comparison for All the Algorithms
  • 37.
    Result Analysis- For “16X16MAZE” – Comparison for All the Algorithms
  • 38.
    Result Analysis ForDifferent MAZE Images Image Time Hops Nodes 0.00007892 7 41 0.00007296 11 35 0.00007081 10 32 Image Time Hops Nodes 0.00010180 9 35 0.00008297 12 38 0.00013185 14 50
  • 39.
  • 40.
    Conclusion from MazeProblem • The time taken to run a BFS depends upon how far the initial node and the goal node i.e. the how number of hops. • Its also observed that as the number of nodes in maze image i.e. the white blocks also increases the time, i.e. as search space is expanded the time to explore it will definitely increase. • If a path from initial to goal node doesn’t exist then the BFS will explore the whole search space and eventually terminates with no solution • At last the image operations like putting and getting pixels on the images are also overheads which are included while analysisng the performance.
  • 41.
  • 42.
    Future Scope It remainsa challenging problem when it comes to extremely large image maze say 1024X1024. In such case, our approach should rely on informed search techniques where the heuristic used should not only be admissible but needs to be consistent as well as our problem is a graph search. TheA* search can be a good alternative with heuristic like the straight line distance of every node from goal node.
  • 43.