AI3 - Solving Problems by Searching

Download as pdf or txt
Download as pdf or txt
You are on page 1of 72

Solving Problems by

Searching
Problem Solving Agents
• Goal based agents decides what to do by finding sequences of actions that lead
to desirable states
• Goal formulation based on the current situation and agent’s performance
measure is the first step in problem solving
• Problem formulation is the process of deciding what actions and states to
consider, given a goal
• An agent with several immediate options of unknown value can decide what to
do by first examining different possible sequences of actions that lead to states of
known value, and then choosing the best sequence – Search
• Search algorithm takes a problem as input and return a solution as action
sequence
• Execution phase: the action recommended in solution are carried out
Well defined problems and solutions
• Problem can be defined formally by 4 components:
1. Initial state: that the agent starts in
2. A description of possible actions available to the agent
• uses a successor function
• Given a state x, SUCCESSOR_FN(x) returns a set of <action, successor> ordered pairs, where each action is
one of the legal action on state x and each successor is a state that can be reached from x by applying the
action
• Initial state and SUCCESSOR_FN implicitly defines the state space of the problem
• Represented with graph where nodes are states and arcs between nodes are actions
• A path in the state space is a sequence of states connected by a sequence of actions
3. Goal test: which determines whether a given state is a goal state
• If there is a set of possible goal states, agent checks whether the given state is one among them
• Goal can be specified by abstract property also
Well defined problems and solutions
4. Path cost function: assigns a numeric cost to each path
• Problem solving agent chooses a cost function that reflects its own performance measure
• Path cost can be the sum of costs of the individual actions along the path
• Step cost [c(x,a,y)] of taking action a, to go from state x to state y
• A solution to a problem is a path from the initial state to a goal state.
• Solution quality is measured by path cost function
• An optimal solution has the lowest path cost among all other solutions
Problem formulation
• Abstract representation of problem
• Avoiding irrelevant details of a problem
• Abstract state description and actions
• Eg:
• Toy problems:
• intended to illustrate on various problem solving methods
• Can be given a concise and exact description
• Used for comparing the performance of the algorithms
• Real world problems
• Solutions people actually care about
• Don’t have a single agreed-upon description
Toy problems
8-puzzle

1 2 1 2 3
4 5 3 4 5 6
7 8 6 7 8
goal state
8-puzzle
1 2
4 5 3
7 8 6

1 2 1 2 1 5 2
4 5 3 4 5 3 4 3
7 8 6 7 8 6 7 8 6

.. ..
. .
8-queens problem (N-queens problem)
• Placing 8 queens in a chess such that no queens attacks any other
Real world problems
• Route finding
• Touring problem
• Travelling salesman problem
• Robot navigation
• Web searching
Airline travel problems
Searching Concepts
• A state can be expanded by generating all states that can be reached by applying
a legal operator to the state.
• State space can be defined by a successor function that returns all states
produced by applying a single legal operator.
• A search tree is generated by generating search nodes by successively expanding
states starting from the initial state as the root.
• A search node in the tree can contain
• Corresponding state
• Parent node
• Action/Operator applied to reach this node
• Path cost of path from initial state to node
• Number of steps along the path from root to node (depth)
Searching Concepts
• Fringe: collection of nodes that have been generated but not expanded (leaf
nodes with no successors)
• Search strategy selects node to be expanded from fringe/frontier
• Can be computationally expensive as search strategy has to look at every element and
choose the best one
• Collection of nodes is implemented with Queue data structure
• Partial search trees for
finding a route from
Arad to Bucharest.
General search algorithm
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
Handling repeated states
General search algorithm with Queue
function GENERAL-SEARCH( problem, QUEUING-FN) returns a solution, or failure
nodes ←MAKE-QUEUE(MAKE-NODE(INITIAL-STATE[problem]))
loop do
if nodes is empty then return failure
node ← REMOVE-FRONT(nodes)
if GOAL-TEST[problem] applied to STATE(node) succeeds then return node
nodes ← QUEUING-FN(nodes, EXPAND(node, OPERATORS[problem]))
end
Measuring problem solving performance
• 4 ways
• Completeness – is the algorithm guaranteed to find a solution when there is one?
• Time Complexity - how long does it take to find a solution?
• Space Complexity – how much memory is required to perform search?
• Optimality – does the strategy find the optimal solution?
• In AI, complexity is expressed in 3 quantities
• Branching factor, b or maximum number of successors for any node
• Depth, d of the shallowest goal node
• m, the maximum length of any path in the state space
Search Strategies
• Uninformed search strategies (blind, exhaustive, bruteforce) do not guide the
search with any additional information about the problem.
• Informed search strategies (heuristic, intelligent) use information about the
problem (estimated distance from a state to the goal) to guide the search.
Find Path from S to G
Optimal ?? No
Depth-limited search
• depth-first search with a predetermined depth limit ‘l’. That is, nodes
at depth l are treated as if they have no successors
• depth limit solves the infinite-path problem
• introduces incompleteness if we choose l < d, that is, the shallowest
goal is beyond the depth limit
• Can be nonoptimal if we choose l > d
• Time complexity is O(bl) and its space complexity is O(bl)
Bidirectional search
• Even better: search from both the start and the goal, in parallel!

• If the shallowest solution has depth d and branching factor is


b on both sides, requires only O(bd/2) nodes to be explored!
• Fringe(0)={4}; Fringe(14) = {10}
• Fringe(4)={6,1}; Fringe(10) = {8,13}
• Fringe(6)={1,7,5}; Fringe(8) = {13,7,9}
Making bidirectional search work
• Need to be able to figure out whether the fringes intersect
• Need to keep at least one fringe in memory…

• Can do various kinds of search on either tree


• Not possible (feasible) if backward search is not possible (feasible)
• Hard to compute predecessors
• High predecessor branching factor
• Too many goal states
Comparison of uninformed search strategies

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy