AAI Intro Lec 5 6 (2)

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 45

Advanced Artificial Intelligence

Lecture 5-6: Problem Solving by


Searching

Instructor: Dr. Sakeena Javaid


Assistant Professor,
Computer Science Department,
KICSIT Kahuta
Agenda of the Lecture

 What is search?
 Problem-solving agents
 Problem types
 Problem formulation
 Example problems
 Uninformed search
 Basic search algorithms

2
What is Search?
 Suppose an agent can execute several actions immediately in a given state
 It doesn’t know the utility of these actions
 Then, for each action, it can execute a sequence of actions until it reaches
the goal
 The immediate action which has the best sequence (according to the
performance measure) is then the solution
 Finding this sequence of actions is called search, and the agent which does
this is called the problem-solver.
 Its possible that some sequence might fail, e.g., getting stuck in an infinite
loop, or unable to find the goal at all.

3
Linking Search to Trees
 You can begin to visualize the concept of a graph
 Searching along different paths of the graph until you reach the solution
 The nodes can be considered congruous to the states
 The whole graph can be the state space
 The links can be congruous to the actions

4
Example: Traveling in Romania
 On holiday in Romania; currently in Arad.
 Flight leaves tomorrow for Bucharest
 Formulate goal: Be in Bucharest
 Formulate problem:
 States: various cities
 Actions: drive between cities
 Find solution:
 Sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest.

5
Example: Traveling in Romania

6
Search Problem Types
 Static: The configuration of the graph (the city map) is unlikely to
change during search
 Observable: The agent knows the state (node) completely, e.g.,
which city I am in currently
 Discrete: Discrete number of cities and routes between them
 Deterministic: Transiting from one city (node) on one route, can
lead to only one possible city
 Single-Agent: We assume only one agent searches at one time, but
multiple agents can also be used.

7
Problem-Solver Formulation
 A problem is defined by five items:
1. An Initial state, e.g., “In Arad“
2. Possible actions available, ACTIONS(s) returns the set of actions that can be executed
in s.
3. A successor function S(x) = the set of all possible {Action–State} pairs from some
state, e.g., Succ(Arad) = {<Arad  Zerind, In Zerind>, …}
4. Goal test, can be
▪ explicit, e.g., x = "In Bucharest”
▪ implicit, e.g., specifying any city

5. Path cost (additive): e.g., sum of distances, number of actions executed, etc. and
c(x,a,y) is the step cost, assumed to be ≥ 0

 A solution is a sequence of actions leading from the initial state to a goal


state.
8
Vacuum World State Space Graph

 States? Actions?
 Goal test? Path cost?

9
Vacuum World State Space Graph

 States? dirt and robot location


 Actions? Left, Right, Pick
 Goal test? no dirt at all locations
 Path cost? 1 per action 10
Example: The 8-puzzle

Start state Goal state

 States?
 Actions?
 Goal test?
11
 Path cost?
Example: The 8-puzzle

Start state Goal state


 States: locations of tiles
 Actions: move blank left, right, up, down
 Goal test: goal state (given)
 Path cost: 1 per move
12
Tree Search Algorithms
 Basic idea:
 Offline (not dynamic), simulated exploration of state space by
generating successors of already-explored states (a.k.a. expanding
the states)
 The expansion strategy defines the different search algorithms

13
Tree search example

14
Tree search example

15
Tree search example

16
Fringe
 Fringe: The collection of nodes that have been generated but not yet
expanded
 Each element of the fringe is a leaf node, with (currently) no
successors in the tree
 The search strategy defines which element to choose from the fringe

17
Implementation: States vs. Nodes
 A state is a representation of a physical configuration
 A node is a data structure constituting part of a search tree
includes state, parent node, action, path cost g(x), depth
 The Expand function creates new nodes, filling in the
various fields and using the SuccessorFn of the problem to
create the corresponding states.

18
Search Strategies

 A search strategy is defined by picking the order of node expansion


 Strategies are evaluated along the following dimensions:
 Completeness: Does it always find a solution if one exists?
 Time complexity: Number of nodes generated
 Space complexity: Maximum number of nodes in memory
 Optimality: Does it always find a least-cost solution?

 Time and space complexity are measured in terms of:


 b: maximum no. of successors of any node.
 d: depth of the shallowest goal node.
 m: maximum length of any path in the state space.

19
Uninformed Search Strategies

 Uninformed search strategies use only the information available in


the problem definition
 Breadth-first search
 Uniform-cost search
 Depth-first search
 Depth-limited search
 Iterative deepening search

20
Breadth-first search

• Implementation:
– fringe is a FIFO queue, i.e., new successors go at end

21
Breadth-first search

 Expand shallowest unexpanded node


 Implementation:
– fringe is a FIFO queue, i.e., new successors go at end

22
Breadth-first search

23
Breadth-first search

• Algorithm

24
Properties of Breadth-first search

 Complete? Yes (if b is finite)


 Time? 1+b+b2+b3 +… +bd + b(bd -1) = O(bd+1)
 Space? O(bd+1) (keeps every node in memory)
 Optimal? Yes (if cost = 1 per step)
 Space is the bigger problem (more than time)

25
Preventing Loopy Paths

 We can have search graphs (instead of trees)


– Hence paths can go backwards, A  B  C  B
– Can get paths with loops A  B  C  D  B
 We can also have multiple paths to a node
 From them, we are interested in the min-cost path
 The Loop problem is that we “rediscover” nodes that the search has
already discovered
 Need to consider methods to suppress nodes that have already been
visited

26
Uniform-Cost Search
fringe  MAKE-EMPTY-QUEUE()
fringe  INSERT( root_node ) // with g=0
loop {
if fringe is empty then return false // finished without goal
node  REMOVE-SMALLEST-COST(fringe)
if node is a goal
1. print node and g
2. return true // that found a goal
Lg  EXPAND(node) // Lg is set of neighbors with their g costs
// NOTE: do not check Lg for goals here!!
fringe  INSERT-IF-NEW(Lg , fringe ) // ignore revisited nodes
// unless with a new and better g
}

27
Uniform-Cost Search

28
29
Uniform-Cost Search

30
Uniform-Cost Search
 Expand least-cost unexpanded node
 Implementation:
 fringe = queue ordered by path cost

 Equivalent to breadth-first if step costs all equal


 Complete? Yes, if step cost ≥ ε
 Time? O(bceiling(C*/epsilon)) where C * is the cost of the optimal solution
 Space? O(bceiling(C*/ epsilon))
 Optimal? Yes – given the condition of completeness – you always
expand the node with lowest cost
 O(bceiling(C*/ epsilon)) can be greater than Ob/d

31
Depth-first search
 Expand deepest unexpanded node
 Implementation:
 fringe is a LIFO queue, i.e., put successors in the front

32
Depth-first search

33
Depth-first search

34
Depth-limited search

 Depth-first search with depth limit l, i.e., nodes at depth l have no


successors
 Recursive implementation:

35
Depth-Limited Search

 Complete? NO. Why? (l < d OR l > d)


 Time? O(bl)
 Space? O(bl)
 Depth-first is a special case of depth-limited with l being infinite.

36
Iterative deepening search

37
Iterative deepening search l =0

38
Properties of Depth-first search

 Complete? No: fails in infinite-depth spaces,


spaces with loops
– Complete in finite spaces

 Time? O(bm): terrible if m is much larger than d


– But if solutions are dense, may be much faster than breadth-first

 Space? O(bm), i.e., linear space!


 Optimal? No

39
Iterative deepening search l =1

40
Iterative deepening search l =2

41
Iterative deepening search l =3

42
Properties of Iterative Deepening search

• Complete? Yes
• Time? (d+1)b0 + d b1 + (d-1) b2 + … + bd = O(bd)
• Space? O(bd)

• Optimal? Yes, if step cost = 1

43
Summary of Algorithms

44
Questions

45

You might also like