0% found this document useful (0 votes)
42 views67 pages

Slide Trí Tuệ Nhân Tạo - Lecture02 - SearchStrategies - Phạm Bảo Sơn - UET

This document provides an overview of artificial intelligence problem solving by searching. It discusses key concepts like agents and environments, rational agents that aim to maximize performance, and different types of problem-solving agents like reflex agents and planning agents. It also covers formulating search problems, examples like the vacuum world and 8-puzzle, and general tree search algorithms like breadth-first search.
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)
42 views67 pages

Slide Trí Tuệ Nhân Tạo - Lecture02 - SearchStrategies - Phạm Bảo Sơn - UET

This document provides an overview of artificial intelligence problem solving by searching. It discusses key concepts like agents and environments, rational agents that aim to maximize performance, and different types of problem-solving agents like reflex agents and planning agents. It also covers formulating search problems, examples like the vacuum world and 8-puzzle, and general tree search algorithms like breadth-first search.
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/ 67

Artificial Intelligence

"

Solving Problems by searching


Outline"
• Agent & Environment"
• Agent types"
• Problem-solving agents"
• Problem types"
• Problem formulation"
• Example problems"
• Uninformed search algorithms"
Son Bao Pham 2017 2
Agents"
• An agent is anything that can be viewed as
perceiving its environment through sensors
and acting upon that environment through
actuators"
• Human agent: eyes, ears, and other organs
for sensors; hands, legs, mouth, and other
body parts for actuators"
• Robotic agent: cameras and infrared range
finders for sensors; various motors for
actuators"
"

Son Bao Pham 2017 3


Agents and environments"

"
"
• The agent function maps from percept
histories to actions:"
[f: P* à A]"
• The agent program runs on the physical
architecture to produce f"
• agent = architecture + program"
" Son Bao Pham 2017 4
Vacuum-cleaner world"

"
• Percepts: location and contents, e.g.,
[A,Dirty]"
• Actions: Left, Right, Suck, NoOp"
"
Son Bao Pham 2017 5
A vacuum-cleaner agent"

Son Bao Pham 2017 6


Rational agents"
• An agent should strive to "do the right thing",
based on what it can perceive and the actions
it can perform. The right action is the one that
will cause the agent to be most successful"
• Performance measure: An objective criterion
for success of an agent's behavior"
• E.g., performance measure of a vacuum-
cleaner agent could be amount of dirt cleaned
up, amount of time taken, amount of
electricity consumed, amount of noise
generated, etc."
" Son Bao Pham 2017 7
Rational agents"
• Rational Agent: For each possible
percept sequence, a rational agent
should select an action that is expected
to maximize its performance measure,
given the evidence provided by the
percept sequence and whatever built-in
knowledge the agent has."
"
Son Bao Pham 2017 8
Reflex Agents"
• Choose action based on current percept
(and maybe memory)"
• May have memory or a model of the
world’s current state"
• Do not consider the future
consequences of their actions"
• Consider how the world currently is!"
• Can a reflex agent be rational?"
Son Bao Pham 2017 9
Planning Agents"
• Ask “what if”"
• Decisions based on (hypothesized)
consequences of actions"
• Must have a model of how the world
evolves in response to actions"
• Must formulate a goal"
• Consider how the world would be!"
• Planning agents search"
Son Bao Pham 2017 10
Problem-solving agents"

Son Bao Pham 2017 11


Search problem"
• A state space: an abstraction of the
world, it encodes how the world is at a
certain point"
• Successor function: models how the
world works"
• A start state and a goal test"

Son Bao Pham 2017 12


Example: Romania"

Son Bao Pham 2017 13


Example: Romania"
• On touring holiday in Romania; currently in Arad. "
• Flight leaves tomorrow from Bucharest; non-refundable
ticket. "
1. Formulate goal: be in Bucharest on time."
2. Specify task:"
1. States: various cities"
2. Operations or actions (= transitions between states): drive
between cities"
3. Find solution (= action sequences): sequence of cities:
e.g. Arad, Sibiu, Fagaras, Bucharest."
4. Execute: drive through all the cities given by the solution."
Son Bao Pham 2017 14
Single-State Task Specification"
A task is specified by states and actions:"
• Initial state e.g. “at Arad”"
• State space e.g. other cities"
• Actions or operators (or successor function) e.g. Arad -> Zerind
Arad-> Sibiu"
• Goal test, check if a state is goal state"
– Explicit x = “at Bucharest”"
– Implicit x = NoDirt(x)"
• Path cost e.g. sum of distances, number of actions"
• Total cost = search cost + path cost"
• A solution is a state-action sequence (initial to goal state)"

Son Bao Pham 2017 15


Choosing States and Actions"
• 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 realizability, 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. "
Son Bao Pham 2017 16
Example Problem"
• Toy problems: concise exact description"
• Real world problems: don’t have a
single agreed description."

Son Bao Pham 2017 17


Vacuum world state space
graph"

• states?"
• actions?"
• goal test?"
• path cost?"
Son Bao Pham 2017 18
"
Vacuum world state space
graph"

• states? integer dirt and robot location "


• actions? Left, Right, Suck"
• goal test? no dirt at all locations"
• path cost? 1 per action"
Son Bao Pham 2017 19
The 8-Puzzle"

• States:?"
• Operators: ?"
• Goal test: ?"
• Path cost: ?"

Son Bao Pham 2017 20


The 8-Puzzle"

• States: integer locations of tiles"


• Operators: move blank left, right, up, down."
• Goal test: goal state (given)"
• Path cost: 1 per move"

Son Bao Pham 2017 21


Rubik’s Cube"

• States: ?"
• Operators: ?"
• Goal test: ?"
• Path cost: ?"
Son Bao Pham 2017 22
Path Search Algorithm"
• Search: Finding state-action sequences that
lead to desirable states. Search is a function "
! ! !solution search(task) !
• Basic idea: "
Simulated explorations of state space by
generating successors of already-explored
states (i.e. “expanding” them). "

Son Bao Pham 2017 23


Path search vs. Constraint Satisfaction"

Important difference between Path Search Problems


and CSP: "
• Constraint Satisfaction Problems (e.g. n-Queens)"
– Difficult part is knowing the final state"
– How to get there is easy "
• Path search problem (e.g. Rubikʼs cube): "
– Knowing the final state is easy"
– Difficult part is how to get there. "

Son Bao Pham 2017 24


Generating action sequences"
• Start with the initial state. "
• Test if it is a goal state "
• Expand one of the states"
• If there are multiple possibilities, you must make a
choice. "
• Procedure: choosing, testing and expanding until a
solution is found or there are no more states to
expand. "
• Think of it as building up a search tree. "

Son Bao Pham 2017 25


Search tree"
• Search tree: superimposed over a state space "
• Root: search node corresponding to the initial state "
• Leaf node: correspond to states that have no
successors in the tree because they were not
expanded or generated no new nodes"
• State space is not the same as search tree: "
– There are 20 states = 20 cities in the route finding example "
– But there are infinitely many paths. "

Son Bao Pham 2017 26


Data structures for a node"
One possibility is to have a node structure with five
component:"
• Corresponding state"
• Parent node: the node which generated the current
node "
• Operator: that was applied to generate the current
node "
• Depth: number of nodes from the root to the current
node "
• Path cost "
Son Bao Pham 2017 27
States vs. Nodes"
• A state is a representation of a physical configuration"
• A node is a data structure constituting part of a search tree
including parent, children, depth, path cost "
• States do not have parents, children, depth or path cost g(x)"

• Note: Two different nodes can contain the same state. "

Son Bao Pham 2017 28


Implementation: general tree search"

Son Bao Pham 2017 29


General Tree Search"
• Important ideas:"
– Fringe: partial plans under consideration"
– Expansion"
– Exploration strategy"
• Main questions: which fringe nodes to
explore?"

Son Bao Pham 2017 30


Search Tree"

Son Bao Pham 2017 31


Search Tree"

Son Bao Pham 2017 32


Search Tree"

Son Bao Pham 2017 33


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 ∞)"
"
Son Bao Pham 2017 34
Uninformed search
strategies"
• Uninformed search strategies use only the
information available in the problem definition"
• Breadth-first search"
• Depth-first search"
• Depth-limited search"
• Iterative deepening search"
"

Son Bao Pham 2017 35


Breadth-first search"
• All nodes are expanded at a given depth in the tree
before any nodes at the next level are expanded."
• Expand root first, then all nodes generated by root,
then all nodes generated by those nodes etc. "
• Expand shallowest unexpanded node "
• Implementation: put newly generated successors at
the end of the queue"
• Very systematic "
• Finds the shallowest goal first "

Son Bao Pham 2017 36


Breadth-first search"
• Expand shallowest unexpanded node"
• Implementation:"
– fringe is a FIFO queue, i.e., new
successors go at end"
"

Son Bao Pham 2017 37


Breadth-first search"
• Expand shallowest unexpanded node"
• Implementation:"
– fringe is a FIFO queue, i.e., new successors
go at end"
"

Son Bao Pham 2017 38


Breadth-first search"
• Expand shallowest unexpanded node"
• Implementation:"
– fringe is a FIFO queue, i.e., new
successors go at end"
"

Son Bao Pham 2017 39


Breadth-first search"
• Expand shallowest unexpanded node"
• Implementation:"
– fringe is a FIFO queue, i.e., new
successors go at end"
"

Son Bao Pham 2017 40


Properties of BFS"
• Complete? Yes (if b is finite, the shallowest goal is at a fixed
depth d and expanded) "
• Time? b + b2 + b3 + … + bd + b(bd -1)= O(bd+1)"
• Space? b + b2 + b3 + … + bd + (bd+1 –b) = O(bd+1)!
(keeps every node in memory; expand all but the last node (goal)
at level d -> (bd+1 –b) nodes at level d+1) "
• Optimal? Yes (if all actions have same cost)"
"
• Space is the bigger problem (more than time) ; it grows
exponentially with depth. "
"
Son Bao Pham 2017 41
Properties of BFS"
• Giả sử b=10, kiểm tra 1000 trạng thái cần 1 giây, lưu một trạng
thái cần 100 byte"

Độ sâu d Thời gian Không gian


4 11 giây 1 megabyte
6 18 giây 111 megabyte
8 31 giờ 11 gigabyte
10 128 ngày 1terabyte
12 35 năm 111 terabyte

14 3500 năm 11 111 terabyte

Son Bao Pham 2017 42


Depth-first search"
• Expands one of the nodes at the deepest
level of the tree"
• Implementation:"
– Insert newly generated states at the front of the
queue"
– Can alternatively be implemented by recursive
function calls. "

Son Bao Pham 2017 43


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 44


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 45


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 46


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 47


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 48


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 49


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 50


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 51


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 52


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 53


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 54


Depth-first search"
• Expand deepest unexpanded node"
• Implementation:"
– fringe = LIFO queue, i.e., put successors at front"
"

Son Bao Pham 2017 55


Properties of DFS"
• 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"
"

Son Bao Pham 2017 56


Depth-limited search"
= depth-first search with depth limit l,"
i.e., nodes at depth l have no successors"

• Recursive implementation:"

Son Bao Pham 2017 57


Properties Depth-limited search
"
• Complete? (Yes if solution is within the depth limit. No infinite
loop)"
• Time? O(bl): l is the depth limit"
• Space? O(bl), i.e., linear space similar to depth first search."
• Optimal? No, can find suboptimal solution first"

• Problem: How to pick a good limit? "

Son Bao Pham 2017 58


Iterative deepening search"

• Tries to combines the benefits of depth first (low


memory) and bread-first (optimal and complete) by
doing a series of depth limited searches to depth 1, 2,
3, etc."
• Early states will be expanded multiple times, but that
might not matter too much as most of the nodes are
near the leaves "

Son Bao Pham 2017 59


Iterative deepening search"

Son Bao Pham 2017 60


IDS l =0"

Son Bao Pham 2017 61


IDS l =1"

Son Bao Pham 2017 62


IDS l =2"

Son Bao Pham 2017 63


IDS l =3"

Son Bao Pham 2017 64


IDS"
• 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+1)b0 + d b1 + (d-1)b2 + … + 3bd-2 +2bd-1 + 1bd "
• For b = 10, d = 5,"
– 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%"

Son Bao Pham 2017 65


IDS"
• Complete? Yes"
• Time? (d+1)b0 + d b1 + (d-1)b2 + … + bd
= O(bd)"
• Space? O(bd)"
• Optimal? Yes, if step cost = 1"

Son Bao Pham 2017 66


References"
• Artificial Intelligence: A Modern
Approach. Chapter 3."
• Artificial Intelligence Illuminated.
Chapter 4. "

Son Bao Pham 2017 67

You might also like