Upload
honey
View
44
Download
3
Tags:
Embed Size (px)
DESCRIPTION
Princess Nora University Artificial Intelligence. Chapter (3) Solving problems by searching. Out Line :. Problem-solving agents Problem types Problem formulation Example problems Basic search algorithms. Solving problems by searching. - PowerPoint PPT Presentation
Citation preview
1
Princess Nora University
Artificial Intelligence
Chapter (3)Solving problems
by searching
2
Out Line :
• Problem-solving agents• Problem types• Problem formulation• Example problems• Basic search algorithms
•
Solving problems by searching
• In which we look at how an agent can decide what to do by systematically considering the outcomes of various sequences of actions that it might take.
• Basic Search Algorithm Many AI problems can be posed as search If goal found=>success; else, failure
3
4
Why Search? Not just city route search
– Many AI problems can be posed as search Planning :
– Vertices : World states; Edges: Actions Game-playing:
– Vertices: Board configurations; Edges: Moves
Speech Recognition:– Vertices: Phonemes; Edges: Phone
transitions
Problem-solving agents
5
Example:
• On holiday in Riyadh.• Flight leaves tomorrow from Riyadh• Formulate goal :
– be after two days in Paris• Formulate problem:
– States : various cities– Actions : drive between cities
• Find solution :– sequence of cities, e.g., Riyadh, Jeddah,
London, Paris6
7
Example: Romania
Problem types• Deterministic, fully observable single-
state problem– Agent knows exactly which state it will be in; solution
is a sequence• Non-observable sensorless problem
(conformant problem)– Agent may have no idea where it is; solution is a
sequence• Nondeterministic and/or partially
observable contingency problem– percepts provide new information about current state– Solution is tree, branch chosen based on percepts– Must use sensors during execution
• Unknown state space exploration problem 8
Single-state problem formulation
A problem is defined by 4 items:
1. initial state e.g., "at Arad“
2. actions or successor function S(x) = set of action–state pairs
e.g., S(Arad) = {<Arad Zerind, Zerind>, … }
9
Single-state problem formulation
3. goal test, can beexplicit, e.g., x = "at Bucharest"implicit, e.g., Checkmate(x)
4. path cost (additive) sequence of actions leading from one state to another
e.g., sum of distances, number of actions executed, etc.C (x, a, y) is the step cost, assumed to be ≥ 0
State space: all states reachable from the initial state by any sequence action
A solution is a sequence of actions leading from the initial state to a goal state
10
Selecting a state space
• Real world is absurdly complex • state space must be abstracted for problem
solving(Abstract) state = set of real states
• (Abstract) action = complex combination of real actions– e.g., "Arad Zerind" represents a complex set
of possible routes, detours, rest stops, etc. • For guaranteed reliability, any real state "in Arad“
must get to some real state "in Zerind"• (Abstract) solution =
– set of real paths that are solutions in the real world
• Each abstract action should be "easier" than the original problem
11
Vacuum world state space graph
• States ? dirt and robot location • actions? Left, Right, Suck• goal test ? no dirt at all locations• path cost? 1 per action 12
Example: The 8-puzzle
• states? locations of tiles • actions? move blank left, right, up, down • goal test? = goal state (given)• path cost? 1 per move•
[Note: optimal solution of n-Puzzle family is NP-hard] 13
Tree search algorithms
• Basic idea:– offline, simulated exploration of state space
by generating successors of already-explored states (expanding states)
14
Tree search example
15
16
Implementation: general tree search
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 branching factor of the search tree– d: depth of the least-cost solution– m: maximum depth of the state space (may be ∞)
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
19
Breadth-first search
• Expand shallowest unexpanded node• Implementation:
– fringe is a FIFO queue, i.e., new successors go at end
Application1: Given the following state space (tree search), give the sequence of visited nodes when using BFS (assume that the node O is the goal state)
20
21
Breadth First Search :
A
B C ED
F G H I J
K L
O
M N
22
Breadth First Search A,
B,C,D,E, F,G,H,I,J,
K,L, M,N, Goal state: OA
B C EDF G H I J
K L
O
M N
23
Breadth First Search The returned solution is the sequence of operators in
the path:A, B, G, L, OA
B C EDF G H I J
K L
O
M N
24
Basic Search Algorithms Uninformed Search
Uniform Cost Search (UCS)
Properties of breadth-first search
• Complete? Yes ( if b is finite)• Time? b+b2+b3+… +bd + b(bd-1) =
O(bd+1)• Space? 1+b+b2+b3+… +bd + b(bd-1) =
O(bd+1) O(bd+1) (keeps every node in memory)
• Optimal? Yes (if cost = 1 per step)
• Space is the bigger problem (more than time)
25
26
Uniform Cost Search (UCS)
Expand the cheapest node. Where the cost is the path cost g(n).
Implémentations: Enqueue nodes in order of cost g(n). QUEUING-FN:- insert in order of increasing path cost.Enqueue new node at the appropriate position in the queue so that we dequeue the cheapest node.
27
Uniform Cost Search (UCS)
25
1 7
4 5
[5] [2]
[9][3]
[7] [8]
1 4
[9][6]
[x] = g(n)
path cost of node n
Goal state
28
Uniform Cost Search (UCS)
25
[5] [2]
29
Uniform Cost Search (UCS)
25
1 7
[5] [2]
[9][3]
30
Uniform Cost Search (UCS)
25
1 7
4 5
[5] [2]
[9][3]
[7] [8]
31
Uniform Cost Search (UCS)
25
1 7
4 5
[5] [2]
[9][3]
[7] [8]
1 4
[9][6]
32
Uniform Cost Search (UCS)
25
1 7
4 5
[5] [2]
[9][3]
[7] [8]
1 4
[9]
Goal state path cost g(n)=[6]
33
Uniform Cost Search (UCS)
25
1 7
4 5
[5] [2]
[9][3]
[7] [8]
1 4
[9][6]
34
Uniform Cost Search (UCS)
Complete? Yes
Time? O(bd)
Space? : O(bd), note that every node in the fringe keep in the queue.
Optimal? Yes
Depth-first search
• Expand deepest unexpanded node• Implementation:
– fringe = LIFO queue, i.e., put successors at front
35
36
Depth First Search (DFS)Given the following state space (tree search), give the sequence of visited nodes when using DFS (assume that the nodeO is the goal state):
AB C ED
F G H I J
K L
O
M N
37
Depth First Search A,
AB C ED
38
Depth First Search A,B,
AB C ED
F G
39
Depth First Search A,B,F,
AB C ED
F G
40
Depth First Search A,B,F,
G,
AB C ED
F G
K L
41
Depth First Search A,B,F,
G,K,
AB C ED
F G
K L
42
Depth First Search A,B,F,
G,K, L,
AB C ED
F G
K L
O
43
Depth First Search A,B,F,
G,K, L, O: Goal State
AB C ED
F G
K L
O
44
Depth First SearchThe returned solution is the sequence of operators in the path:
A, B, G, L, O
AB C ED
F G
K L
O
Properties of depth-first search
• Complete? No: fails in infinite-depth spaces, spaces with loops– Modify to avoid repeated states along path– 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 45
Depth-limited search
= depth-first search with depth limit l,
i.e., nodes at depth l have no successors
46
47
Depth-Limited Search (DLS)
Given the following state space (tree search), give the sequence of visited nodes when using DLS (Limit = 2):
AB C ED
F G H I J
K L
O
M N
Limit = 0
Limit = 1
Limit = 2
48
Depth-Limited Search (DLS)
A,
AB C ED
Limit = 2
49
Depth-Limited Search (DLS)
A,B,
AB C ED
F G
Limit = 2
50
Depth-Limited Search (DLS)
A,B,F,
AB C ED
F G
Limit = 2
51
Depth-Limited Search (DLS)
A,B,F, G,
AB C ED
F G
Limit = 2
52
Depth-Limited Search (DLS)
A,B,F, G, C,
AB C ED
F G H
Limit = 2
53
Depth-Limited Search (DLS)
A,B,F, G,
C,H,
AB C ED
F G H
Limit = 2
54
Depth-Limited Search (DLS)
A,B,F, G,
C,H, D,A
B C EDF G H I J
Limit = 2
55
Depth-Limited Search (DLS)
A,B,F, G,
C,H, D,IA
B C EDF G H I J
Limit = 2
56
Depth-Limited Search (DLS)
A,B,F, G,
C,H, D,I
J,AB C ED
F G H I JLimit = 2
57
Depth-Limited Search (DLS) A,B,F,
G, C,H,
D,I J, E
AB C ED
F G H I J
Limit = 2
58
Depth-Limited Search (DLS)
A,B,F, G,
C,H, D,I
J, E, Failure
AB C ED
F G H I J
Limit = 2
59
Depth-Limited Search (DLS)
DLS algorithm returns Failure (no solution) The reason is that the goal is beyond the limit (Limit
=2): the goal depth is (d=4)
AB C ED
F G H I J
K L
O
M NLimit = 2
60
Depth-Limited Search (DLS)
Complete? Yes if there is a goal state at a depth less than L
Time? O(bL), where L is the cutoff.
Space? : O(bL), where L is the cutoff
Optimal? NO
61
Iterative Deepening Search (IDS)
Iterative deepening search (IDS) applies DLS repeatedly with increasing depth. It terminates when a solution is found or no solutions exists.
62
Iterative deepening search• Number of nodes generated in a depth-limited search to
depth d with branching factor b: NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd
• Number of nodes generated in an iterative deepening search to depth d with branching factor b:
NIDS = d b0 + (d-1)b1 + … + 3bd-2 +2bd-1 + 1bd
For b = 10, d = 6,•• NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
–– NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456–
• Overhead = (123,456 - 111,111)/111,111 = 11%
63
Properties of iterative deepening search• Complete? Yes• Time? d b1 + (d-1)b2 + … + bd =
O(bd)• Space? O(bd)• Optimal? Yes, if step cost = 1
64
Bi-directional Search (BDS) Start searching from both the
initial state and the goal state, meet in the middle.
• Complete? Yes• Optimal? Yes• Time Complexity: O(bd/2),
where d is the depth of the solution.
• Space Complexity: O(bd/2), where d is the depth of the solution.
65
Comparison of search algorithms
b: Branching factord: Depth of solutionm: Maximum depth
l : Depth Limit
Summary
• Problem formulation usually requires abstracting away real-world details to define a state space that can feasibly be explored
• Variety of uninformed search strategies
• Iterative deepening search needs only linear space and not much more time than other uninformed algorithms
66