150 likes | 288 Views
AI Algorithms. Tam Siu Lung, Alan HKOI 2005 (2005-03-05). Prerequisites. Graph Theory Depth First Search Breadth First Search Dijkstra’s Single Source Shortest Path Algorithm Recursion Exhaustion Stack Queue Priority Queue. Itinerary. State Space Search (SSS) Problems
E N D
AI Algorithms Tam Siu Lung, Alan HKOI 2005 (2005-03-05)
Prerequisites • Graph Theory • Depth First Search • Breadth First Search • Dijkstra’s Single Source Shortest Path Algorithm • Recursion • Exhaustion • Stack • Queue • Priority Queue
Itinerary • State Space Search (SSS) Problems • DFS/BFS/IDS/BDS • A* Search • Constraint Satisfaction Problems (CSP) • Exhaustion strategies • Local Search (Removed)
State Space Search • Graph is modeled by • V: Number of nodes • E: Number of edges • State Space is modeled by • b: Maximum Breadth • d: Maximum Depth • V=? • E=? • State Space Search • Find a path to a goal state (with minimum path cost)
DFS • Tries to simply visit all states • Not optimal • Very little memory • If we want to find the nearest goal, … add initial state while stack not empty get an element u if u is goal, then return u mark u closed for all neighbors v of u if v not closed, add v
BFS • Stores all states around a given depth • We always find the nearest goal • Promise: all states nearer than the solution are visited add initial state while queue not empty get an element u if u is goal, then return u mark u closed for all neighbors v of u if v not closed, add v
IDS • Trade-off space of BFS using time • Note the number of duplicated searches for depth = 0..infinity if DFS(initial, depth) return it
Revision • BFS • Complete and Optimal • Need much memory • DFS • Not Always Complete and Not Optimal • Use very little memory • IDS • Combines goodness of DFS and BFS • A bit more time consuming
Bidirectional BFS • If we really have to use BFS • We wasted a lot of memory anyway • We can do more with them if we only have a single goal state • Search from both sides • When we found a state marked in another side we found the solution
Improving BFS • In BFS, we need to visit all states nearer than optimal • This is to ensure … • Suppose we have spent cost g to reach state u • We know that it is at least cost h from a goal • And we know a goal state v withg < cost < g + h • Can we claim that this is nearest goal without expanding state u?
Really there • Suppose for all nodes not expanded • We know they are at least f away from nearest goal • And we found a goal with cost <= f • What we features of f we need? • f >= g • f < g + real cost to goal (no over-estimation) • What will happen if over-estimated?
A* Search • Use a heuristic to estimate the remaining path cost • h(x) >= 0 for all x • h(x) = 0 for all goal x • Choose the state with minimum total cost f(x) = g(x) + h(x) • Terminate if the selected (not those found) state x has h(x) = 0 • Optimal and Complete • Cost = number of states with f(x) < g(goal)
The Algorithm add initial state while priority queue not empty get an element u with minimum f if u is goal, then return u mark u closed for all neighbors v of u if v not closed, add v
Search Algorithm Hierarchy • Best first search: choose the node with minimum f(x) = g(x) + h(x) • A search: h(x) >= 0 and h(x) = 0 at goal • A* search: h(x) <= h(x) • Uniform cost search: h(x) ≡ 0, e.g. Dijkstra • Breadth first search: g(x) = d(x) • Depth first search: h(x) = –g(x)
Variants • RBFS • IDA* • MA* • SMA*