CH 3 - Solving Problem by Search-1
CH 3 - Solving Problem by Search-1
INTELLIGENCE- CS411
Prof. Alaa Sagheer
Artificial Intelligence “CS 411”
• Textbook:
S. Russell and P. Norvig
Artificial Intelligence: A Modern Approach
Prentice Hall, 2020, Fourth Edition
Introduction
“Graph and Tree”
Lecture I S
4
A Problem?
A Problem?
A Problem?
Example: 8 - Puzzles
Solving Problem by
Searching
Lecture I S
Course Learning Outcomes
Chapter 3
Problem Solving
At the end of the course students will be able to
1. Compare different types of learning paradigms.
2. Apply suitable learning algorithm to a classification task.
3. Compare and contrast common models used for knowledge representation.
10
• Simplest agents (reflex agents, which base their actions on a direct mapping from
states to actions) cannot operate well in environments for which this mapping
would be too large to store and would take too long to learn.
• Goal-based agents can succeed by considering future actions and the desirability
of their outcomes.
Problem-Solving Agents
• Simplest agents (reflex agents, which base their actions on a direct mapping from
states to actions) cannot operate well in environments for which this mapping
would be too large to store and would take too long to learn.
• Goal-based agents can succeed by considering future actions and the desirability
of their outcomes.
Problem-Solving Agents
Are Deciding what to do by finding sequences of actions that lead to desirable states
•Intelligent agents are supposed to maximize their performance measure.
Achieving this is sometimes simplified if the agent can adopt a goal, (e.g. Taxi)
•Goals help to organize Agent’s behavior by limiting the objectives that the agent
is trying to achieve.
•Goal formulation, based on the current situation and the agent's performance
measure, is the first step in problem solving.
•A goal is a set of world states- exactly those states in which the goal is satisfied.
The agent's task is to find out which sequence of actions will get it to a goal state
*.
Artificial Intelligence Ch3: Problem Solving by Search Prof. Alaa Sagheer
13
Problem-Solving by Search
An agent with several immediate options of unknown value can decide
what to do by just examining different possible sequences of actions that
lead to states of known value, and then choosing the best sequence.
Problem-Solving by Search
After formulating a goal, the agent calls a search procedure to solve it. It then uses the
solution to guide its actions, doing whatever the solution recommends as the next thing
to do- typically, the first action of the sequence- and then removing that step from the
sequence. Once the solution has been executed, the agent will formulate a new goal.
Artificial Intelligence Ch3: Problem Solving by Search Prof. Alaa Sagheer
15
4- A path cost function that assigns a numeric cost to each path. This cost
function reflects the performance measure. (Example: Time to Bucharest
so the cost of a path might be its length). So the cost of a path might be
its length in kilometers.
Example of Problems
A toy problem is intended to illustrate (or exercise) various
problem-solving methods. It can be given a concise, exact
description. This means that it can be used easily by different
researchers to compare the performance of algorithms.
A real-world problem is one whose solutions people actually care
about. They tend not to have a single agreed-upon description
Toy Problems
❖ The Vacuum World
❖ The Puzzle World
Uninformed
Search
Lecture II S
34
Tree Search
• A tree search starts at the root
and explores nodes from there,
A
looking for a goal node (a node
that satisfies certain conditions,
B C depending on the problem)
Goal nodes
Breadth-First Search
• The root node is expanded first, then all the successors of the
root node are expanded next, then their successor, and so on.
• Implementation:
• Fringe is a FIFO queue, i.e., new successors go at end. i.e. Nodes that
are visited first will be expanded first. FIFO = First-In-First-Out
•
Breadth-First Search
• The root node is expanded first, then all the successors of the
root node are expanded next, then their successor, and so on.
• Implementation:
• Fringe is a FIFO queue, i.e., new successors go at end. i.e. Nodes that
are visited first will be expanded first.
•
Breadth-First Search
• The root node is expanded first, then all the successors of the
root node are expanded next, then their successor, and so on.
• Implementation:
• Fringe is a FIFO queue, i.e., new successors go at end. i.e. Nodes that
are visited first will be expanded first.
•
Breadth-First Search
• The root node is expanded first, then all the successors of the
root node are expanded next, then their successor, and so on.
• Implementation:
• Fringe is a FIFO queue, i.e., new successors go at end. i.e. Nodes that
are visited first will be expanded first.
•
Cost-Sensitive Search
a GOAL
2 2
b c
3
2
1 8
2 e
3 d
f
9 8 2
START h
1 4 2
p 4 r
15
q
Uniform-cost search
Breadth-first search is optimal when all step costs are equal,
because it always expands the shallowest unexpanded node.
• Implementation:
• fringe = queue ordered by path cost
•
• Equivalent to breadth-first if step costs
• all equal
•
Uniform-cost search
2 a G
b c
Strategy: expand a cheapest node first: 1 8 2
2 e
Fringe is a priority queue (priority: cumulative cost) 3 d f
9 2
S h 8 1
1 p q r
15
S 0
d 3 e 9 p 1
b 4 c e 5 h 17 r 11 q 16
11
Cost a 6 a h 13 r 7 p q f
contours
p q f 8 q c G
q 11 c G 10 a
a
46
• Is it complete?
• Assuming best solution has a finite cost and
minimum arc cost is positive, yes!
• Is it optimal?
Yes
Artificial Intelligence Ch3: Problem Solving by Search Prof. Alaa Sagheer
47
• The bad:
• Explores options in every “direction” Start Goal
• No information about goal location
Example
Solution
Excercise
Depth-first search
❖ The search proceeds immediately to the deepest level of the
search tree, where the nodes have no successors. As those
nodes are expanded, they are dropped from the fringe, so then
the search "backs up" to the next shallowest node that still has
unexplored successors.
Depth-first search
❑ Implementation:
• This strategy can be implemented by TREE-SEARCH with a
last-in-first-out (LIFO) strategy, also known as a stack.
• As an alternative to the TREE-SEARCH implementation, it is
common to implement depth-first search with a recursive
function that calls itself on each of its children in turn.
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
• This strategy can be implemented by TREE-SEARCH with a
last-in-first-out (LIFO) queue, also known as a stack.
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-first search
• Expand the deepest unexpanded node in the current
fringe.
•
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
•
Depth-limited search
• The problem of unbounded trees can be alleviated by supplying
depth-first search with a predetermined depth limit l . That is,
nodes at depth l are treated as if they have no successors.
• Sometimes, depth limits can be based on knowledge of the
problem.
For example, on the map of Romania there are 20 cities.
Therefore, we know that if there is a solution, it must be of
length 19 at the longest, so l = 19 is a possible choice.
But in fact if we studied the map carefully, we would discover
that any city can be reached from any other city at most 10
steps (the diameter of the state space), which leads to a more
efficient depth-limited search.
• For most problems, however, we will not know a good depth
limit until we have solved the problem.
Artificial Intelligence Ch3: Problem Solving by Search Prof. Alaa Sagheer
73
Depth-limited search
Solution
The higher the branching factor, the lower the relative cost
of iterative deepening depth first search
Artificial Intelligence Ch3: Problem Solving by Search Prof. Alaa Sagheer
100
• If an algorithm remembers every state that it has visited, then it can be viewed
as exploring the state-space graph directly.
being expanded.
SUMMARY
• This chapter has introduced methods that an agent can use to select actions in environments
that are deterministic, observable, static, and completely known. In such cases, the: agent can
construct sequences of actions that achieve its goals; this process is called search.
• Before an agent can start searching for solutions, it must formulate a goal and then use the
goal to formulate a problem.
• A problem consists of four parts: the initial state, a set of actions, a goal test function, and
a path cost function. The environment of the problem is represented by a state space. A
path through the state space from the initial state to a goal state is a solution.
• Search algorithms are judged on the basis of completeness, optimality, time complexity,
and space complexity. Complexity depends on b, the branching factor in the state space,
and d, the depth of the shallowest solution.
• Breadth-first search selects the shallowest unexpanded node in the search tree for
expansion. It is complete, optimal for unit step costs, and has time and space complexity of
O(bd+1). The space complexity makes it impractical in most cases.
SUMMARY
• Uniform-cost search is similar to breadth-first search but expands the node with lowest
path cost, g (n) . It is complete and optimal if the cost of each step exceeds some positive
bound.
• Depth-first search selects the deepest unexpanded node in the search tree for expansion. It
is neither complete nor optimal, and has time complexity of O(bm) and space complexity of
O(bm ), where m is the maximum depth of any path in the state space.
• Depth-limited search imposes a fixed depth limit on a depth-first search.
• Iterative deepening search calls depth-limited search with increasing limits until a goal is
found. It is complete, optimal for unit step costs, and has time complexity of O(bd) and
space complexity of O(bd).
Exercises
Q1: What are the properties of a search problem?
Exercises
Q1: What is the solution of the Vacuum problem?