7. Problem solving agents, Search Algorithms
7. Problem solving agents, Search Algorithms
2. Problem Formulation
● The agent creates an abstract model of the relevant world. Key
considerations include:
• States: Cities in Romania (e.g., Arad, Sibiu, Bucharest)
• Actions: Traveling from one city to an adjacent city
• State Changes: Current city changes based on the travel action
Problem-Solving Process (cont…)
3. Search
● The agent simulates possible sequences of actions to find a
solution (path to Bucharest).
• Solution example: Arad → Sibiu → Fagaras → Bucharest
• If no solution exists, it concludes Bucharest is unreachable.
4. Execution
● The agent executes the actions in the solution. In a fully
deterministic environment, percepts during execution can be
ignored (open-loop system).
Search problems and solutions
● A search problem includes:
• State Space: All possible states of the environment
• Initial State: Starting point (e.g., Arad)
• Goal States: Desired endpoint (e.g., Bucharest)
• Actions: Possible transitions between states
• Example: ACTIONS(Arad) = {ToSibiu, ToTimisoara, ToZerind}
• Transition Model: Defines the result of actions
• Example: RESULT(Arad, ToZerind) = Zerind
• Action Cost Function: Numeric cost for applying an action
Useful Abstraction:
● The abstraction is useful if carrying out each of the actions in the
solution is easier than the original problem; in our case, the action
“drive from Arad to Sibiu” can be carried out without further search or
planning by a driver with average skill.
Search Algorithms
Introduction
● A search algorithm takes a search problem as input and returns a
solution, or an indication of failure.
● Each node in the search tree corresponds to a state in the state space
and the edges in the search tree correspond to actions. The root of
the tree corresponds to the initial state of the problem.
Introduction (cont…)
● The search tree may have multiple paths to (and thus multiple
nodes for) any given state, but each node in the tree has a
unique path back to the root (as in all trees).
Partial search trees for finding a route
from Arad to Bucharest
Nodes that have been expanded are lavender with
bold letters. Nodes on the frontier that have been
generated but not yet expanded are in green
The set of states corresponding to these two
types of nodes are said to have been reached
Partial search trees for finding a route
from Arad to Bucharest
• The set of unexpanded nodes are called the frontier of the search tree.
• We say that any state that has had a node generated for it has been reached
(whether or not that node has been expanded).
• Note that the frontier separates two regions of the state-space graph: an
interior region where every state has been expanded, and an exterior region
of states that have not yet been reached.
• Nodes that could be generated next are shown in faint dashed lines. Notice in
the bottom tree there is a cycle from Arad to Sibiu to Arad; that can’t be an
optimal path, so search should not continue from there.
Best-First search
● How do we decide which node from the frontier to expand next? A
very general approach is called best-first search, in which we choose a
node, n, with minimum value of some evaluation function, f (n).
● On each iteration we choose a node on the frontier with minimum f
(n) value, return it if its state is a goal state, and otherwise apply
EXPAND to generate child nodes.
● The algorithm returns either an indication of failure, or a node that
represents a path to a goal.
● By employing different f (n) functions, we get different specific
algorithms,
Search data structures
• Completeness:
• Ensures all reachable states are explored in finite spaces.
• Requires systematic exploration in infinite spaces.
Understanding Complexity