0% found this document useful (0 votes)
1 views

03_Search

The document discusses problem-solving in artificial intelligence using search strategies for goal-oriented agents. It covers various problem classifications, search terminologies, and specific examples like the 8-puzzle and 8-queens problem, along with different search methods such as breadth-first, depth-first, and uniform cost search. Additionally, it highlights the importance of choosing the right state space and evaluates the effectiveness of uninformed versus informed search strategies.

Uploaded by

leimu.864
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

03_Search

The document discusses problem-solving in artificial intelligence using search strategies for goal-oriented agents. It covers various problem classifications, search terminologies, and specific examples like the 8-puzzle and 8-queens problem, along with different search methods such as breadth-first, depth-first, and uniform cost search. Additionally, it highlights the importance of choosing the right state space and evaluates the effectiveness of uninformed versus informed search strategies.

Uploaded by

leimu.864
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Problem Solving Using Search

Introduction to Artificial Intelligence


© G. Lakemeyer

G. Lakemeyer

Winter Term 2024/25


Problem Solving Using Search

Here we consider goal-oriented agents.


Given an initial (world) state, the agent wants to reach a certain goal using
appropriate actions, where actions transform one state into another.
A goal is a set of world states, which the agent finds desirable (wants to reach
one of them).
© G. Lakemeyer

Example: Driving from City A to City B.


Problem formulation
How to represent world states?
Which actions should be considered?

Search: Finding an action sequence which transforms an initial state into a


goal state.

AI/WS-2024/25 2 / 25
Problem Classification

Single-state problem
The vaccuum-world states:
complete world knowledge,
1 2 complete knowledge about the actions
Multiple-state problem
3 4 incomplete world knowledge,
© G. Lakemeyer

complete knowledge about the actions


Contingency problem
5 6
incomplete knowledge about actions,
needs to gather information at run-time
7 8
Exploration problem
World states and effect of actions are
both unkown. Very difficult!

AI/WS-2024/25 3 / 25
The vacuum world
© G. Lakemeyer

AI/WS-2024/25 4 / 25
Some Terminology (1)

Initial state: World state which the agent believes to be in initially.


State space: Set of all possible states.
Description of which state is reached by an action from
Operator:
© G. Lakemeyer

a given state.
Successor S (x ) returns the set of states reachable by any action
function S: from state x.
Goal test: Tests whether a state is a goal state.

AI/WS-2024/25 5 / 25
Some Terminology (2)

Path: Sequence of actions.


Cost function over paths, usually the sum of the costs
Path cost:
of the actions of the path, often denoted as g.
Path from the initial state to a state that satisfies the
Solution:
goal test.
© G. Lakemeyer

Search cost: Time and memory needed to find a solution.


Total cost: Sum of the path cost (of the solution) and search cost.

Note: For multiple-state problems, replace state by state set, operators apply
to all elements of the set, and paths connect sets of states.

AI/WS-2024/25 6 / 25
Choosing a State Space
It is an art to choose the right state space. Want to leave out unnecessary
detail (Abstraction)!

Example: Drive from A to B.


Only represent the most important places.

Oradea
Neamt
© G. Lakemeyer

Zerind
Iasi
Arad

Sibiu Fagaras

Vaslui

Rimnicu Vilcea
Timisoara

Pitesti
Lugoj

Hirsova
Mehadia Urziceni

Bucharest
Dobreta
Craiova Eforie
Giurgiu
AI/WS-2024/25 7 / 25
8-Puzzle

5 4 5
1 4
2 3

6 1 88 6
8 84

7 3 22 7 6 25
© G. Lakemeyer

Start State Goal State

States: Describe the location of each tile including the blank.


Operators: Blank moves left, right, up, or down.
Goal test: Does the state match picture on the right?
Path cost: Each step costs 1 unit.
Search cost: Problem is NP-complete in the size of the puzzle.

AI/WS-2024/25 8 / 25
8-Queens Problem

Goal test: 8 queens on the board, all safe.


Path cost: 0 (only the solution counts).

Representation 1
States: any placement of 0–8 queens.
Operators: place a queen on the board.
© G. Lakemeyer

Problem: Too many states (648 )!

AI/WS-2024/25 9 / 25
8-Queens Problem

Goal test: 8 queens on the board, all safe.


Path cost: 0 (only the solution counts).

Representation 1
States: any placement of 0–8 queens.
Operators: place a queen on the board.
© G. Lakemeyer

Problem: Too many states (648 )!

Representation 2
States: 0–8 on board, all safe.
Operators: place a queen starting from left.
Problem: few state (2057), but sometimes deadend (see figure).

AI/WS-2024/25 9 / 25
8-Queens Problem

Goal test: 8 queens on the board, all safe.


Path cost: 0 (only the solution counts).

Representation 1
States: any placement of 0–8 queens.
Operators: place a queen on the board.
© G. Lakemeyer

Problem: Too many states (648 )!

Representation 2
States: 0–8 on board, all safe.
Operators: place a queen starting from left.
Problem: few state (2057), but sometimes deadend (see figure).

Representation 3
States: 8 queens on board, one per column.
Operators: move a queen under attack in the same column.
AI/WS-2024/25 9 / 25
Vacuum World 1

Complete World Knowledge (single-state problem):


R
L R

S S

R R
L R L R

L L
© G. Lakemeyer

S S
S S

R
L R

S S

States: All combinations of robot location and presence of dust (8).


Operators: left (L), right (R), suck (S).
Goal test: no dust in any room.
Path cost: 1 unit per action.

AI/WS-2024/25 10 / 25
Vacuum World 2
Incomplete Knowledge (multiple-state problem).
L

L R

S
© G. Lakemeyer

S S
L R
R

S S

R L

L R

S S
R

State set: All subsets of the 8 states.


Goal test: No dust anywhere in the elements of the state set.
AI/WS-2024/25 11 / 25
Search in General
Starting from the initial state we (a) The initial state Arad

always expand one state, i.e.


we create all successor states (b) After expanding Arad Arad

of that state.
Sibiu Timisoara Zerind
Search tree = the tree induced
by expansion. (c) After expanding Sibiu Arad

Nodes contain world states;


© G. Lakemeyer

edges = actions. Sibiu Timisoara Zerind

Arad Fagaras Oradea Rimnicu Vilcea

function GENERAL-SEARCH( problem, strategy) returns a solution, or failure


initialize the search tree using the initial state of problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting nodes to the search tree
end

AI/WS-2024/25 12 / 25
Search Nodes

PARENT-NODE

ACTION = right
© G. Lakemeyer

5 4 Node
DEPTH = 6
PATH-COST = 6
6 1 88
STATE
7 3 22

AI/WS-2024/25 13 / 25
Evaluating Search Strategies

Completeness: Does it always find a solution if one exists?


Time Complexity: How long does it take to find a solution in the worst
© G. Lakemeyer

case?
Space Complexity: How much memory is used in the worst case?
Optimality: Does it always find the best solution?

AI/WS-2024/25 14 / 25
Uninformed vs. Informed Search

Uninformed (blind) search:


No information available about the length or the cost of a solution.
The main methods are:
breadth-first search, uniform cost search, depth-first search,
depth-limited search, iterative deepening, bidirectional search.
© G. Lakemeyer

Informed (heuristic) search:


Here the user has information about the length or the cost of a solution,
which often helps in speeding up the search.
We will look at:
Greedy search, A∗ and some variants, hill-climbing, and
simulated annealing.

AI/WS-2024/25 15 / 25
Breadth-First Search

Expand the nodes in the same order in which they are generated.
© G. Lakemeyer

Always finds the shallowest solution (completeness).


Solutions are optimal, provided all actions have identical non-negative
cost.

AI/WS-2024/25 16 / 25
Cost of Breadth-First Search

The Cost is very high!. Let b be the max. branching factor, d the depth of a
solution. Then at most

b + b 2 + b 3 + . . . + b d + b d +1 − b

nodes need to be generated, i.e. O (bd +1 ).


© G. Lakemeyer

Example: b = 10, 10000 nodes/s; 1000bytes/node:

AI/WS-2024/25 17 / 25
Uniform cost search

A modified breadth-first search, which always expands node n with the least
path cost g (n).
S
0
S

A B C
1 5 15
S
© G. Lakemeyer

A
A B C
1 10 5 15
B G
5 5 S
S G 11

15 5
A B C
C 15
G G
11 10
(a) (b)

Note: Always finds the cheapest solution, provided

g (successor (n)) ≥ g (n) for all n.

AI/WS-2024/25 18 / 25
Depth-First Search

Always expand the node at the deepest level.


© G. Lakemeyer

AI/WS-2024/25 19 / 25
Depth-limited Search
Perform depth-first search, but only up to a pre-specified depth.
Route planning: For n cities the maximal depth is n − 1.
Oradea
Neamt

Zerind
Iasi
Arad
© G. Lakemeyer

Sibiu Fagaras

Vaslui

Rimnicu Vilcea
Timisoara

Pitesti
Lugoj

Hirsova
Mehadia Urziceni

Bucharest
Dobreta
Craiova Eforie
Giurgiu

Actually, a maximal depth of 9 suffices (called the diameter of the problem).


AI/WS-2024/25 20 / 25
Iterative Deepening 1
Combines depth- and breadth-first search.
Optimal and complete like breadth-first search, but requires less space.

function ITERATIVE-DEEPENING-SEARCH( problem) returns a solution sequence


inputs: problem, a problem

for depth 0 to do 1
if DEPTH-LIMITED-SEARCH( problem, depth) succeeds then return its result
end
return failure
© G. Lakemeyer

Limit = 0

Limit = 1

Limit = 2

Limit = 3
.....

AI/WS-2024/25 21 / 25
Iterative Deepening 2

Number of expansions:

(d )b + (d − 1)b2 + . . . + 3bd −2 + 2bd −1 + 1bd

Compared to breadth-first search: b + b2 + b3 + . . . + bd −1 + bd + bd +1 − b.


Note: iterative deepening is better!

Example: b = 10, d = 5
© G. Lakemeyer

Breadth-first search:
10 + 100 + 1000 + 10000 + 100000 + 999990 = 1111110
Iterative deepening:
50 + 400 + 3000 + 20000 + 100000 = 123450

Time complexity: O (bd )


Space complexity: O (b × d )
Note: Preferred method if search depth unknown!

AI/WS-2024/25 22 / 25
Bidirectional Search

Start Goal
© G. Lakemeyer

Assuming that forward and backward search are symmetric, we can ideally
obtain search times of O (2 × bd /2 ) = O (bd /2 ).

Example: For b = 10, d = 6 we have 2222 nodes instead of 1111111!

AI/WS-2024/25 23 / 25
Problems with Bidirectional Search

Operators not always reversible. (Need to compute the predecessor


node.)
Sometimes there are very many goal states, which are described only
incompletely. E.g., what are the predecessors of “checkmate” in chess?
© G. Lakemeyer

We need efficient methods to decide when the two search methods have
met.
Which kind of search method should one use for each direction? (In the
figure it is breadth-first search for both, but that is not always optimal.)

AI/WS-2024/25 24 / 25
Comparison
© G. Lakemeyer

b = maximal branching factor


d = depth of a solution path
m = maximal search depth
l = depth restriction
a
: complete if b is finite; b : complete if step costs ≥ ϵ > 0;
c
: optimal if step costs identical; d : if both directions use BFS.

AI/WS-2024/25 25 / 25

You might also like