Class3 PDF
Class3 PDF
Lecture 3
Milos Hauskrecht
[email protected]
5329 Sennott Square
A search problem
Many interesting problems in science and engineering are solved
using search
A search problem is defined by:
• A search space:
– The set of objects among which we search for the solution
Examples: routes between cities, or n-queens configuration
• A goal condition
– Characteristics of the object we want to find in the search
space?
– Examples:
• Path between cities A and B
• Non-attacking n-queen configuration
1
Graph representation of a search problem
• Search problems can be often represented using graphs
• Typical example: Route finding
– Map corresponds to the graph, nodes to cities, links valid
moves via available connections
– Goal: find a route (sequence of moves) in the graph from S
to T
G H J
B
S C
K
start I
A D
L
E T target
F
CS 1571 Intro to AI M. Hauskrecht
Graph search
• Less obvious conversion:
Puzzle 8. Find a sequence of moves from the initial
configuration to the goal configuration.
– nodes corresponds to states of the game,
– links to valid moves made by the player
start
target
2
Graph Search Problems
Search problems can be often represented as graph search
problems:
• Initial state
– State (configuration) we start to search from (e.g. start city,
initial game position)
• Operators:
– Transform one state to another (e.g. valid connections
between cities, valid moves in Puzzle 8)
• Goal condition:
– Defines the target state (destination, winning position)
N-queens
Some problems are easy to convert to the graph search problems
• But some problems are harder and less intuitive
– Take e.g. N-queens problem.
Goal configuration
• Problem:
– We look for a configuration, not a sequence of moves
– No distinguished initial state, no operators (moves)
CS 1571 Intro to AI M. Hauskrecht
3
N-queens
How to choose the search space for N-queens?
• Ideas? Search space:
– all configurations of N queens on the board
…..
• Can we convert it to a graph search problem?
• We need states, operators, initial state and goal condition.
initial goal
…
CS 1571 Intro to AI M. Hauskrecht
N-queens
Search space:
– all configurations of N queens on the board
goals
initial
…
4
N-queens
An alternative way to formulate the N-queens problem as a
search problem:
• Search space: configurations of 0,1,2, … N queens
• Graph search:
– States configurations of 0,1,2,…N queens
– Operators: additions of a queen to the board
– Initial state: no queens on the board
start
Graph search
N-queens problems
• This is a different graph search problem when compared to
Puzzle 8 or Route planning:
We want to find only the target configuration, not a path
5
Two types of graph search problems
• Path search
– Find a path between states S and T
– Example: traveler problem, Puzzle 8
– Additional goal criterion: minimum length (cost) path
Search
• Search (process)
– The process of exploration of the search space
• The efficiency of the search depends on:
– The search space and its size
– Method used to explore (traverse) the search space
– Condition to test the satisfaction of the search objective
(what it takes to determine I found the desired goal object
6
Comparison of two problem formulations
Solution 1:
Solution 2:
1 4 4 * 3 4 * 3 * 2 4 * 3 * 2 * 1 65
- configurations altogether
7
Search
• Search (process)
– The process of exploration of the search space
• The efficiency of the search depends on:
– The search space and its size
– Method used to explore (traverse) the search space
– Condition to test the satisfaction of the search objective
(what it takes to determine I found the desired goal object
Search
• Search (process)
– The process of exploration of the search space
• The efficiency of the search depends on:
– The search space and its size
– Method used to explore (traverse) the search space
– Condition to test the satisfaction of the search objective
(what it takes to determine I found the desired goal object
8
Search process
Exploration of the state space through successive application of
operators from the initial state
• Search tree = structure representing the exploration trace
– Is built on-line during the search process
– Branches correspond to explored paths, and leaf nodes to
the exploration fringe
Arad
Search tree
• A search tree = (search) exploration trace
– different from the graph representation of the problem
– states can repeat in the search tree
Graph
9
Search tree
Search tree
10
General search algorithm
Arad
11
General search algorithm
12
General search algorithm
Arad
Newly selected node
13
General search algorithm
Arad
Check if it is the goal
Arad
Expanded nodes
14
General search algorithm
Arad
Arad
15
General search algorithm
Implementation of search
• Search methods can be implemented using the queue structure
16
Implementation of search
• A search tree node is a data-structure that is a part of the
search tree
parent
ST
State Other attributes:
Node - state value (cost)
- depth
state - path cost
children
Search
• Search (process)
– The process of exploration of the search space
• The efficiency of the search depends on:
– The search space and its size
– Method used to explore (traverse) the search space
– Condition to test the satisfaction of the search objective
(what it takes to determine I found the desired goal object
17
Uninformed search methods
• Search techniques that rely only on the information available
in the problem definition
– Breadth first search
– Depth first search
– Iterative deepening
– Bi-directional search
Search methods
Properties of search methods :
• Completeness.
– Does the method find the solution if it exists?
• Optimality.
– Is the solution returned by the algorithm optimal? Does it
give a minimum length path?
18
Parameters to measure complexities.
• Space and time complexity.
– Complexity is measured in terms of the following tree
parameters:
• b – maximum branching factor
• d – depth of the optimal solution
• m – maximum depth of the state space
Branching factor
The number of
applicable operators
19
Breadth-first search
• Expand the shallowest node first
• Implementation: put successors to the end of the queue (FIFO)
queue Arad
Arad
Breadth-first search
queue Zerind
Sibiu
Timisoara
Arad
20
Breadth-first search
queue Sibiu
Timisoara
Arad
Oradea
Arad
Breadth-first search
queue Timisoara
Arad
Oradea
Arad
Arad
Oradea
Fagaras
Romnicu Vilcea
Zerind Sibiu Timisoara
21
Breadth-first search
queue Arad
Oradea
Arad
Oradea
Arad Fagaras
Romnicu Vilcea
Arad
Zerind Sibiu Timisoara
Lugoj
• Time complexity: ?
22
BFS – time complexity
depth number of nodes
b 0 1
1 21=2
d
2 22=4
3 23=8
d 2d (bd )
• Time complexity:
1 b b 2 b d O (b d )
exponential in the depth of the solution d
23