Download presentation
Presentation is loading. Please wait.
1
ARTIFICIAL INTELLIGENCE
CS 512 ARTIFICIAL INTELLIGENCE LECTURE 03
2
Solving problems by searching
Problem solving We want: To automatically solve a problem We need: A representation of the problem Algorithms that use some strategy to solve the problem defined in that representation
3
Problem Representation
State-based Models State space : Model task as a graph of all possible states A state captures all the relevant information about the past in order to act (optimally) in the future Actions correspond to transitions from one state to another Solutions are defined as a sequence of steps/actions (i.e., a path in the graph) State-space graphs
4
Building Goal-Based Agents
What are the key questions needing to be addressed? What goal does the agent need to achieve? What knowledge does the agent need? What actions does the agent need to do?
5
Search Example: Route Finding
Actions: go straight, turn left, turn right Goal: shortest? fastest? most scenic?
6
Search Example: River Crossing Problem
Goal: All on right side of river Rules: Farmer must row the boat Only room for one other Without the farmer present: Dog bites sheep Sheep eats cabbage Actions: F>, F<, FC>, FC<, FD>, FD<, FS>, FS<
7
Search Example: 8-Puzzle
Actions: move tiles (e.g., Move2Down) Goal: reach a certain configuration
8
Search Example: Water Jugs Problem
Given 4-liter and 3-liter pitchers, how do you get exactly 2 liters into the 4-liter pitcher? 4 3
9
Search Example: 8-Queens
Place eight queens on a chess board such that no queen can attack another queen
10
Search Example: Remove 5 Sticks Problem
Remove exactly 5 of the 17 sticks so the resulting figure forms exactly 3 squares
11
Search Space Definitions
State A description of a possible state of the world Initial state the state in which the agent starts the search Goal test Conditions the agent is trying to meet Goal state Any state which meets the goal condition Action Function that maps (transitions) from one state to another
12
Water Jugs Problem Given 4-liter and 3-liter pitchers, how do you get exactly 2 liters into the 4-liter pitcher? State: (x, y) for # liters in 4-liter and 3-liter pitchers, respectively Actions: empty, fill, pour water between pitchers Initial state: (0, 0) Goal state: (2, *) 4 3
13
Actions / Successor Functions
1. (x, y | x < 4) (4, y) “Fill 4” 2. (x, y | y < 3) (x, 3) “Fill 3” 3. (x, y | x > 0) (0, y) “Empty 4” 4. (x, y | y > 0) (x, 0) “Empty 3” 5. (x, y | x+y ≥ 4 and y > 0) (4, y - (4 - x)) “Pour from 3 to 4 until 4 is full” 6. (x, y | x+y ≥ 3 and x > 0) (x - (3 - y), 3) “Pour from 4 to 3 until 3 is full” 7. (x, y | x+y ≤ 4 and y > 0) (x+y, 0) “Pour all water from 3 to 4”
14
State space
15
Example: Map Planning
16
Searching For Solutions
Initial State e.g. “At Arad” Successor Function A set of action state pairs S(Arad) = {(Arad->Zerind, Zerind), …} Goal Test e.g. x = “at Bucharest” Path Cost sum of the distances traveled
17
Searching For Solutions
Having formulated some problems…how do we solve them? Search through a state space Use a search tree that is generated with an initial state and successor functions that define the state space
18
Search Problem Example (as a tree)
19
Uninformed Search on Trees
Uninformed means we only know: The goal test The successors() function But not which non-goal states are better For now, also assume state space is a tree Search process constructs a "search tree" root is the start state leaf nodes are: unexpanded nodes (in the Frontier list) "dead ends" (nodes that aren't goals and have no successors because no operators were applicable) goal node is last leaf node found
20
Uninformed Search Strategies
Uninformed Search: strategies that order nodes without using any domain specific information, i.e., don’t use any information stored in a state BFS: breadth-first search Queue (FIFO) used for the Frontier remove from front, add to back DFS: depth-first search Stack (LIFO) used for the Frontier remove from front, add to front CLICK EACH SUB
21
Depth First Search ( DFS )
Expand deepest unexpanded node
22
Depth First Search ( DFS )
23
Depth First Search ( DFS )
24
Depth First Search ( DFS )
25
Depth First Search (DFS)
Put start state in the agenda Loop Get a state from the agenda If goal, then return Expand state (put children to the front of agenda) Avoiding loops Don’t add a node to the agenda if it’s already in the agenda Don’t expand a node (or add it to the agenda) if it has already been expanded.
26
Depth-First Search (DFS)
generalSearch(problem, stack) S start # of nodes tested: 0, expanded: 0 expnd. node Frontier {S} 5 2 4 A B C CLICK DESC: 1. interior nodes, 2. leaf nodes, 3. arcs 9 4 6 2 D E 6 G goal 1 F 7 H
27
Depth-First Search (DFS)
generalSearch(problem, stack) S start # of nodes tested: 1, expanded: 1 expnd. node Frontier {S} S not goal {A,B,C} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
28
Depth-First Search (DFS)
generalSearch(problem, stack) S start # of nodes tested: 2, expanded: 2 expnd. node Frontier {S} S {A,B,C} A not goal {D,E,B,C} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
29
Depth-First Search (DFS)
generalSearch(problem, stack) S start # of nodes tested: 3, expanded: 3 expnd. node Frontier {S} S {A,B,C} A {D,E,B,C} D not goal {H,E,B,C} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
30
Depth-First Search (DFS)
generalSearch(problem, stack) S start # of nodes tested: 4, expanded: 4 expnd. node Frontier {S} S {A,B,C} A {D,E,B,C} D {H,E,B,C} H not goal {E,B,C} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
31
Depth-First Search (DFS)
generalSearch(problem, stack) S start # of nodes tested: 5, expanded: 5 expnd. node Frontier {S} S {A,B,C} A {D,E,B,C} D {H,E,B,C} H {E,B,C} E not goal {G,B,C} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
32
Depth-First Search (DFS)
generalSearch(problem, stack) S start # of nodes tested: 6, expanded: 5 expnd. node Frontier {S} S {A,B,C} A {D,E,B,C} D {H,E,B,C} H {E,B,C} E {G,B,C} G goal {B,C} no expand 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
33
Depth-First Search (DFS)
generalSearch(problem, stack) S start # of nodes tested: 6, expanded: 5 expnd. node Frontier {S} S {A,B,C} A {D,E,B,C} D {H,E,B,C} H {E,B,C} E {G,B,C} G {B,C} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 path: S,A,E,G cost: 15 H
34
Depth First Search (DFS)
Try this Depth First Search (DFS) Find a path from node S to the goal nod I. Use DFS method.
35
Try this Find a path from node A to the goal nod B. Use DFS method. A
Z O S F C P R T L M D
36
Breadth First Search (BFS)
Expand shallowest unexpanded node
37
Breadth First Search (BFS)
38
Breadth First Search (BFS)
39
Breadth First Search (BFS)
Put start state in the agenda Loop Get a state from the agenda If goal, then return Expand state (put children to the back of agenda) Avoiding loops Don’t add a node to the agenda if it’s already in the agenda Don’t expand a node (or add it to the agenda) if it has already been expanded.
40
Breadth-First Search (BFS)
generalSearch(problem, queue) 5 2 9 6 4 1 7 S start A E D F B G goal C H # of nodes tested: 0, expanded: 0 expnd. node Frontier list {S} CLIKC ANIM: 1. generalSearch, 2. graph, 3. table, 4. # expanded
41
Breadth-First Search (BFS)
generalSearch(problem, queue) S start # of nodes tested: 1, expanded: 1 expnd. node Frontier list {S} S not goal {A,B,C} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
42
Breadth-First Search (BFS)
generalSearch(problem, queue) S start # of nodes tested: 2, expanded: 2 expnd. node Frontier list {S} S {A,B,C} A not goal {B,C,D,E} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
43
Breadth-First Search (BFS)
generalSearch(problem, queue) S start # of nodes tested: 3, expanded: 3 expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B not goal {C,D,E,G} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
44
Breadth-First Search (BFS)
generalSearch(problem, queue) S start # of nodes tested: 4, expanded: 4 expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C not goal {D,E,G,F} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
45
Breadth-First Search (BFS)
generalSearch(problem, queue) S start # of nodes tested: 5, expanded: 5 expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C {D,E,G,F} D not goal {E,G,F,H} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
46
Breadth-First Search (BFS)
generalSearch(problem, queue) S start # of nodes tested: 6, expanded: 6 expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C {D,E,G,F} D {E,G,F,H} E not goal {G,F,H,G} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
47
Breadth-First Search (BFS)
generalSearch(problem, queue) S start # of nodes tested: 7, expanded: 6 expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C {D,E,G,F} D {E,G,F,H} E {G,F,H,G} G goal {F,H,G} no expand 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 H
48
Breadth-First Search (BFS)
generalSearch(problem, queue) S start # of nodes tested: 7, expanded: 6 expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C {D,E,G,F} D {E,G,F,H} E {G,F,H,G} G {F,H,G} 5 2 4 A B C CLICK ONCE 9 4 6 2 D E 6 G goal 1 F 7 path: S,B,G cost: 8 H
49
Depth First Search (DFS)
Try this Depth First Search (DFS) Find a path from node S to the goal nod I. Use BFS method.
50
Try this Find a path from node A to the goal nod B. Use BFS method. A
Z O S F C P R T L M D
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.