You are on page 1of 47

ARTIFICIAL INTELLIGENCE

3
PROBLEM SOLVING I: CLASSICAL SEARCH

• Problem Solving Agents?


• Examples of Problems
• Searching for solutions
• Uninformed Search Strategies
• Informed Search Strategies
• Nonclassical Local Search
PROBLEM SOLVING AGENTS
Problem-solving agent
• Problem-solving agent is one kind of goal-based agent that
considers states of the world as wholes, with no internal
structure visible to the problem-solving algorithms.
• Goal-based agents that use more advanced factored or
structured representations are usually called planning agents.

problem-solving
• Problems are challenges which require set of actions an
agent need to take to achieve a goal which maximizes its
chance of success and existence.
• Problem solving agent must come up with solutions which
lead to achieving a goal.
PROBLEM SOLVING AGENTS
Problem-solving agent
• Problem formulation is the process of deciding what actions
and states to consider, given a goal.
• Search: The process of looking for a sequence of actions that
reaches the goal.
• A search algorithm: takes a problem as input and returns a
solution in the form of an action sequence.
• execution phase: Once a solution is found, the actions it
recommends can be carried out.
PROBLEM SOLVING AGENTS
Problem formulation
• A problem can be defined formally by five components:
1. Initial state: that the agent starts in. For example, the initial state
for our agent in Romania might be described as in (Arad).
2. Actions: A description of the possible actions available to the
agent.
3. Transition model: description of what each action does
4. Goal test, which determines whether a given state is a goal state
5. Path cost function that assigns a numeric cost to each path.
PROBLEM SOLVING AGENTS
Goal Formulation
• Imagine an agent in the city of Arad, Romania, enjoying a touring
holiday. The agent wants to do a lot of things but has nonrefundable
return ticket to Bucharest the next day.
• What's the agent’s goal?
EXAMPLE OF PROBLEMS
Examples of Problems
• 8-puzzle
EXAMPLE OF PROBLEMS
Examples of Problems
• 8-queen Problem
• The goal of the 8-queens problem is to place eight queens on
a chessboard such that no queen attacks any other.
• A queen attacks any piece in the same row, column or
diagonal.
EXAMPLE OF PROBLEMS
Examples of Problems
• Traveling salesperson problem (TSP) is a touring problem in
which each city must be visited exactly once. The aim is to
find the shortest tour.
• VLSI layout problem requires positioning millions of
components and connections on a chip to minimize area,
minimize circuit delays, minimize stray capacitances, and
maximize manufacturing yield.
• Robot navigation is a generalization of the route-finding
problem described earlier.
SEARCHING FOR A SOLUTION
Searching for a solution
• Having formulated some problems, the next stage is to solve
the problems (i.e. find solution).
• A solution is an action sequence, so search algorithms work
by considering various possible action sequences.
• Search plays a key role in many parts of AI. These algorithms
provide the conceptual backbone of almost every approach to
the systematic exploration of alternatives.
• Search problems are found everywhere in day-to-day real life
applications in robotics, planning, transportation, computer
networking etc.
SEARCHING FOR A SOLUTION
Searching for a solution
• Most of the search problems can be represented inform of a
Graph or Tree in AI.
• These graphs or trees provide a framework which an agent
can use to achieve certain goals.
• One general approach to problem solving in AI is to reduce
the problem to be solved to one of searching a graph.
• To use this approach, we must specify what are the states,
the actions and the goal test.
SEARCHING FOR A SOLUTION
Tree
• A tree is made up of nodes and links (circles and lines)
connected so that there are no loops (cycles).
• Nodes are sometimes referred to as vertices and links as
edges (especially when dealing with graphs).
• A tree has a root node (where the tree "starts"). Every node
except the root has a single parent (direct ancestor).
SEARCHING FOR A SOLUTION
Graph
• Graph: a graph is also a set of nodes connected by links but
where loops are allowed and a node can have multiple
parents.
• Directed Graph: all links have direction denoted by arrow
head (similar to one-way road). whereas
• Undirected Graph: links go in both directions (similar to two-
way streets) and simply denoted by non-arrowed lines

Directed Graph undirected Graphs (two-


(one-way Street) way-streeets)
SEARCHING FOR A SOLUTION
Converting Graph to Tree
• Graph is bad for searching problems due to presence of
loops. You don’t want to go round and round getting nowhere
in the end.
• When asked to search a graph, we can construct an
equivalent problem of searching a tree by doing two things:
1. Turning undirected links into two directed links;
2. Making sure we never consider a path with a loop or, even
better, by never visiting the same node twice.
SEARCHING FOR A SOLUTION
• States are represented by nodes of the tree or graph.
• Visited state is the state which a search algorithm reached but
has not explored its child nodes.
• Expanded state is the one that has been visited and also its
child nodes are being explored.
SEARCHING FOR A SOLUTION
Measuring problem-solving performance
• Completeness: Is the algorithm guaranteed to find a solution
when there is one?

• Optimality: Does the strategy find the optimal solution.

• Time complexity: How long does it take to find a solution?

• Space complexity: How much memory is needed to perform


the search?
UNINFORMED (BLIND) SEARCH
• Uninformed Search means that the strategies have no
additional information about states beyond that provided in
the problem definition.
• All they can do is generate successors and distinguish a goal
state from a non-goal state.
• There are three types of uninformed search algorithms:

1. Depth-First search
2. Breath-First Search
3. Uniform-Cost Search
UNINFORMED (BLIND) SEARCH
Depth-First Search
• Depth-first search always expands the deepest node in the
current frontier of the search tree.
• The search proceeds immediately to the deepest level of the
search tree, where the nodes have no successors.
UNINFORMED (BLIND) SEARCH
Depth-First Search
• Depth-first search uses a LIFO queue where the most
recently generated node is chosen for expansion.
• In a search problem with infinite state, depth-first might never
find a solution.
• Depth-first search can use backtracking search and keep a
list (Q) of nodes ( partial paths), then to pick one such node
from Q, see if it reaches the goal and otherwise extend that
path to its neighbors and add them back to Q.
Depth-First Variant
• Depth-limited search: imposes depth limit on the Depth-first
search
• Iterative deepening depth-first search: search with increasing
depth limits until a goal is found.
UNINFORMED (BLIND) SEARCH
Iterative Depth-First Search
UNINFORMED (BLIND) SEARCH
Depth-First Example
• A problem solving agent searching for a path to reach city G
from its current location city S using Depth-first algorithm.

A B

C D D G

C G C G
Tree
UNINFORMED (BLIND) SEARCH
Depth-First Example
Expand S
S
Q Visited
A B
1 (S) S
2 (A S) (B S) S, A
C D D G
3
4
C G C 5
G
Expand AS
S
Q Visited

A B 1 (S) S
2 (A S) (B S) S, A, B
C D D G 3 (C A S) (D A S) (B S) S, A, B , C, D
4

C 5
G C G
UNINFORMED (BLIND) SEARCH
Depth-First Example
CAS reaches terminal node and is not a goal
S
Q Visited
A B
1 (S) S
2 (A S) (B S) S, A, B
C D D G
3 (C A S) (D A S) (B S) S, A, B , C, D
4 (D A S) (B S) S, A, B , C, D
C G C 5
G
Expand DAS
S
Q Visited

A B 1 (S) S
2 (A S) (B S) S, A, B
C D D G 3 (C A S) (D A S) (B S) S, A, B , C, D
4 (D A S) (B S) S, A, B , C, D

C 5 (G D A S) (B S)
G C G
Note CDAS not use because C was visited
UNINFORMED (BLIND) SEARCH
Depth-First Example
S

A B

C D D G

C G C G

Q Visited
1 (S) S
2 (A S) (B S) S, A, B
3 (C A S) (D A S) (B S) S, A, B , C, D
4 (D A S) (B S) S, A, B , C, D
5 (G D A S) (B S) S, A, B , C, D, G
6 GDAS
UNINFORMED (BLIND) SEARCH
Breath-First Search
• Breath-first search is a simple strategy in which the root node
is expanded first, then all the successors of the root node are
expanded next, then their successors, and so on.
• Breadth-first search is an instance of the general graph-
search algorithm which the shallowest unexpanded node is
chosen for expansion.
• This is achieved very simply by using a FIFO queue for the
frontier
UNINFORMED (BLIND) SEARCH
Breath-First Example
• A problem solving agent searching for a path to reach city G
from its current location city S using Breath-first algorithm.

A B

C D D G

C G C G
Tree
UNINFORMED (BLIND) SEARCH
Breath-First Example
Expand node S
S
Q Visited
A B
1 (S) S
2 (A S) (B S) S, A
C D D G
3
4
C G C 5
G

S
Q Visited

A B 1 (S) S
2 (A S) (B S) S, A, B
C D D G 3 (B S) (C A S) (D A S) S, A, B , C, D
4

C 5
G C G
UNINFORMED (BLIND) SEARCH
Breath-First Example
Expand node BS
S
Q Visited
A B
1 (S) S
2 (A S) (B S) S, A, B
C D D G
3 (B S) (C A S) (D A S) S, A, B , C, D
4 (C A S) (D A S) (G B S) S, A, B , C, D, G
C G C 5
G
Note DBS not use because D was visited
S
Q Visited

A B 1 (S) S
2 (A S) (B S) S, A, B
C D D G 3 (B S) (C A S) (D A S) S, A, B , C, D
4 (C A S) (D A S) (G B S) S, A, B , C, D, G

C 5 ( G B S)
G C G
UNINFORMED (BLIND) SEARCH
Uniform-cost search
• uniform-cost search expands the node n with the lowest path
cost g(n).
• This is done by storing the frontier as a priority queue ordered
by g.
• Its use when information (path-cost) about the descendent
nodes are available but not the goal.
• Unlike Breath-First, in Uniform-cost a test is added in case a
better path is found to a node currently on the frontier

Path-cost g(n)

(Bucharest-Fagaras-Sibiu) g(n)=99+211=310
UNINFORMED (BLIND) SEARCH
Uniform-cost Example
• A problem solving agent searching for a path to reach city G
from its current location city S using Uniform-Cost search.
Cost-path between adjacent cities are provided.

C
2
A 3 G
2 2
4
S D
5
1
6
B

(C A S) g(n)=2+2=4
(D A S) g(n)=2+4=6
UNINFORMED (BLIND) SEARCH
Uniform-cost Example
.
INFORMED SEARCH
. Informed Search
• Informed search strategy—one that uses problem-specific
knowledge beyond the definition of the problem itself
• It can find solutions more efficiently than can an uninformed
strategy.
• The search strategy always has some knowledge about the
goal.
• In these search strategies, a node is selected for expansion
based on an evaluation function, f(n)
• There are two types;

1. Best-First Search
2. A* Search
INFORMED SEARCH
. Best-First Search
• Greedy best-first search tries to expand the node that is
closest to the goal, on the grounds that this is likely to lead to
a solution quickly.
• It evaluates nodes by using just the heuristic function h(n) as
its evaluation function f(n); i.e. f(n) = h(n).
• h(n) = estimated cost of the cheapest path from the state at
node n to a goal state.
• For example the heuristic information may be the straight-line
distance to the goal from each node n,
• Therefore at the goal h(n)=0.
INFORMED SEARCH
. Best-First Search
Example of Greedy Best-fisrt in Arad-Bucharest Problem
INFORMED SEARCH
. Best-First Search
A problem solving agent searching for a path to reach city G
from its current location city S using Greedy Best-first search.
Heuristic information about the goal are provided.
INFORMED SEARCH
A* Search
• The most widely known form of informed search is called A*
search (pronounced “A-star A* search”).
• It evaluates nodes by combining g(n), the cost to reach the
node, and h(n), the cost to get from the node to the goal:

f(n) = g(n) + h(n) .

• f(n) = estimated cost of the cheapest solution through n .


• A* search is both complete and optimal
INFORMED SEARCH
A* Search
A problem solving agent searching for a path to reach city G from
its current location city S using Greedy Best-first search. Heuristic
information and path-cost about the goal are provided.
INFORMED SEARCH
A* Search
INFORMED SEARCH
A* Search

A* Variants
• Recursive best-first search (RBFS)
• Simplified Memory-bound A* (SMA)
NONCLASSICAL LOCAL SEARCH
Local Search
• Local search algorithms search in the state space, evaluate
and modify one state at a time rather than systematically
exploring path from an initial stage.
• These algorithms are suitable for problems in which all that
matter is the solution state, not the path cost to reach it.
• The family of local search algorithm includes methods inspired
by statistical physics (e.g. Simulated Annealing) and
evolutionary biology (e.g. Genetic Algorithm).
• Local Search algorithm operates using the current node and
generally only moves to the neighbors of that node.
• Example of problems that do not care about the path to solution
are 8-queen, integrated circuit design etc.
NONCLASSICAL LOCAL SEARCH
Advantages of Local Search
1. The use very little memory since they don’t have to retain
paths history
2. They can find reasonable solution even in a large or infinite
state space for which systemic search algorithms are not
suitable
3. They are use to solve optimization problems where the goal if
to be found according to an objective function.
Example of Local Search algorithms
• Hill climbing Search
• Simulated annealing
• Local Beam Search
• Genetic Algorithm
NONCLASSICAL LOCAL SEARCH
Local Search landscape
• Search landscape or state space has both “location” and
“elevation”
• Locations depends on the states whereby elevation is defined
by the value of heuristic or objective function.
• Example finding a goal state where the objective function is
maximum.
NONCLASSICAL LOCAL SEARCH
Hill Climbing (Steepest-ascent)
• Hill climbing algorithm continuously moves in the direction of
increasing value of the objective function- that is uphill.
• It stops when it reaches a peak (maximum point) where no
neighbor has a higher value.
• Hill climbing does not look ahead beyond the immediate
neighbors of the current stage.
• Example in the 8-queen problem where queens are to be
placed in a state where to have non-attacking queen
• The objective function will be the the total number of non-
attacking queen.
• At each state, Hill climbing algorithm will move in the direction
with higher value of objective
NONCLASSICAL LOCAL SEARCH
Hill Climbing (Steepest-ascent)
• 8-queen examples with objective function
NONCLASSICAL LOCAL SEARCH
Hill Climbing (Steepest-ascent) Variants
• Hill climbing is often called a Greedy local search because it
grabs a good neighbor without thinking ahead about where to
go next.
• Hill climbing is get stuck by: Local Maxima, Ridges or Plateau

Hill Climbing Variants


There are number of variants of Hill Climbing Search Variants

• Stochastic Hill climbing


• First choice Hill climbing
• Random-restart Hill climbing
NONCLASSICAL LOCAL SEARCH
Genetic Algorithm
• Genetic Algorithm is a variant of stochastic beam algorithm
• In GA Successor states are generated by combining two parent
states rather than modifying a single state.
Genetic Algorithm Stages
• Randomly Generate initial population of states or individuals
• Evaluate each state or individual by a fitness function: the
higher the fitness score the more likely to be chosen.
• select pairs for reproduction from the population accordance
with the fitness function score
• Performed a crossover to produce offspring from the chosen
pairs.
• Mutate the offspring with random probability.
NONCLASSICAL LOCAL SEARCH
Genetic Algorithm

You might also like