0% found this document useful (0 votes)
13 views46 pages

Pathfinding Algorithms: Fiona French

Uploaded by

naajiahamed74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views46 pages

Pathfinding Algorithms: Fiona French

Uploaded by

naajiahamed74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Pathfinding algorithms

Fiona French
Recap
State space
Search tree
Search tree
Branch = action, node = state
Arad

Timisoara Sibiu Zerind

Fagaras Riminicu
Search tree
Search tree
Branch = action, node = state
Is current state a goal?
If not EXPAND state

Essence of search is to select 1 option and


save others for later
The Frontier
Parent node
Child node
Leaf node
Set of leaf nodes = frontier

(also known as open list)


Warnings
Algorithms that forget their history are
doomed to repeat it!

Loopy paths = infinite searches


Maintain an explored set (closed list)
Frontier separates explored and unexplored
regions
Infrastructure of search algorithm
Require data structure to keep track of search
tree = queue = lookup table

For each node:


Node State (where am I)
Node Parent (where did I come from)
Node Action (where can I go)
Node Path Cost (total to get here)
Measuring performance
How can we measure the performance of an
algorithm?
Measuring performance
Completeness - guarantee find solution
Optimality - lowest path cost
Time complexity - how long it takes
Space complexity - how much memory
required
Graph search
A grid is also a useful way to handle the data.

http://www.redblobgames.com/pathfinding/grids/graphs.html
Uninformed search (blind)
Breadth first
Uniform cost
Depth first
Depth limited
Iterative deepening depth first
Bidirectional
Uninformed search (blind)
Breadth first
FIFO - first in first out of the queue
Memory bigger problem than execution time
Uniform cost
Expands node with lowest path cost
Changes order of QUEUE
Depth first
LIFO
Backtracking search uses less memory
Uninformed search (blind)
Depth limited
Has a predetermined limit (no infinity)
What is the diameter of the problem?
Iterative deepening depth first
This limit gradually
increases
Bidirectional
Informed search (uses heuristic)
Best first search
Greedy best first search
A*
Best First Search
Node expanded based on evaluation function
f(n)
This function determines the search strategy
Includes heuristic h(n)
Heuristic = estimated cost of cheapest path
from state at node n to goal
Dijkstra’s Algorithm
"The question of whether computers can think is like the
question of whether submarines can swim."

Shortest path in weighted graphs


Builds on BFS by adding edge weights and adjusting
BPSF (Best Path So Far)
Edge relaxation (elastic)
Dijkstra’s Algorithm - 1
Find shortest path from A to F
Create list of nodes to examine: { A(0) }
Take node with lowest cost and
visit all its neighbours.
Dijkstra’s Algorithm - 2
Cost of node = cost of edge + cost of previous node
Note the parent (A)
New list: { B(2), D(3), C(4) }
Dijkstra’s Algorithm - 3
Checking path B
Path to D is redundant
New list: { E(4), D(3), C(4) }
Dijkstra’s Algorithm - 4
Checking path D
Finds better route to E
New list: { E(3), C(4) }
Dijkstra’s Algorithm - 5
Checking path E
Finds F at cost 10
List: { C(4), F(10) }
Finally check path C
And backtrack the shortest route (9)
by using the parents
Greedy Best First Search
Expands the node closest to goal
Using only the heuristic
f(n) = h(n)
Doesn’t go back to explore the others, so it’s
quick, but...
A*
A* is an improvement.
Cost of each node = cost of edge
+ cost of
previous nodes
+ estimated cost to reach target
A*
f(n) = g(n) + h(n)

Where g(n) is path cost from start to n


And h(n) is estimated cost from n to goal

It’s optimal and complete!


Just like Uniform Cost but g+h, not just g
node value

path weight

heuristic
A*
Take into account an estimate of cost to target
Heuristic: eg. distance as the crow flies
Underestimate guarantees optimal path
Stops you heading in wrong direction
Heuristics
Example - 8 puzzle
h1
= number of misplaced tiles

h2 Manhattan
= sum of distances from goals

H2 dominates h1
Genetic algorithms
Measure fitness of each possibility
Use this to determine probability of selection
Randomly match 2 parents
Swap match (like DNA) for offspring
Random mutation

Does it work? How? Chunks of usable code


Pathfinding in games?
http://www.yaldex.com/games-programming/0672323699_ch12lev1sec7.html
http://www.redblobgames.com/pathfinding/tower-defense/
Pathfinding in games?
Slime mould
a simple organism that consists of an acellular mass of
creeping jelly-like protoplasm containing nuclei, or a mass
of amoeboid cells. When it reaches a certain size it forms a
large number of spore cases.

https://www.scientificamerican.com/article/brainless-slime-
molds/
Slime mould
Slime mould
http://www.youtube.com/watch?v=2UxGrde1NDA TED
Slime mould
http://www.wired.com/2013/06/slime-mold-computers/

http://phys.org/news/2014-01-slime-molds.html

https://gigaom.com/2014/04/04/how-slime-mold-can-design-transportation-netw
orks-and-maybe-even-transform-computing/

EFFICIENT AND OPTIMAL NETWORKS

http://slimoco.ning.com/
A* tutorial links
More A* Tutorials
http://www.redblobgames.com/pathfinding/a-star/introduction.html
http://theory.stanford.edu/~amitp/GameProgramming/
http://www.policyalmanac.org/games/aStarTutorial.htm
Cat and bone tutorial:
www.raywenderlich.com/4946/introduction-to-apathfinding
http://wiki.gamegardens.com/Path_Finding_Tutorial
http://en.wikipedia.org/wiki/A%2a_search_algorithm
Vacuum cleaner world - C++ code
http://web.ntnu.edu.tw/~tcchiang/ai/Vacuum%20Cleaner%20World.htm
A* algorithm - C++ code
http://code.activestate.com/recipes/577457-a-star-shortest-path-algorithm/
Other examples / links
http://letsmakerobots.com/node/40756
http://qiao.github.io/PathFinding.js/visual/
http://www.yaldex.com/gamesprogramming/0672323699_ch12lev1sec7.html
http://www.redblobgames.com/pathfinding/tower-defense/
Pseudocode, very clear:
http://www.kirupa.com/forum/showthread.php?72863-Tutorial-PathFinding-
Algorithms-AI

Shows comparisons between A*, Dijkstra and concurrent D:


http://www.youtube.com/watch?v=cSxnOm5aceA
More links to code examples & tutorials
http://www.dauntless.be/Projects/AstarAS3/Demo/#app=d71a&6defselectedInd
ex=2
- AS3 demo
http://www.dauntless.be/astar/ - AS3 tutorial
http://www.heyes-jones.com/astar.html - C++ tutorial
http://briangrinstead.com/files/astar/ javascript demo + tutorial
http://active.tutsplus.com/tutorials/games/artificial-intelligence-series-part-1-pat
h-finding/
Flash demo + tutorial
http://code.google.com/p/romania-pathfind/ C++ source code
http://blogs.msdn.com/b/ericlippert/archive/tags/astar/ C# tutorial
Heuristics tutorial links
Heuristics eg. Manhattan, Diagonal, Euclidian
http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html
http://heuristicswiki.wikispaces.com/IDA*

You might also like