A* Search

advertisement
ARTIFICIAL INTELLIGENCE
[INTELLIGENT AGENTS PARADIGM]
PROBLEM SOLVING BY SEARCHING
Professor Janis Grundspenkis
Riga Technical University
Faculty of Computer Science and Information Technology
Institute of Applied Computer Systems
Department of Systems Theory and Design
E-mail: Janis.Grundspenkis@rtu.lv
Problem Solving by
Searching (1)
• Problem Solving Agent
(one kind of a Goal-Based Agent)
–Relevant feature:
Decision making what to do by
finding sequence of actions that
leads to desired states
Problem Solving by
Searching (2)
• How problem is solved?
Step 1. Goal formulation
Step 2. Problem formulation – a process of
deciding what actions and states to consider
Step 3. Search – systematic exploration of the
sequence of alternative states that appear in
a problem solving process
Step 4. Solution – an action sequence
Step 5. Execution – recommended actions can
be accomplished
Simple-Problem-Solving
Agent
> Percept
Update-State(state, percept)
> Goal
Formulate-Goal(state)
> Problems
Formulate-Problem(state, goal)
> Current state
Search(problem)
> Action
Recommendation(state, action)
Return: action
Problem Types (1)
• Single-state problem
– Percepts give enough information to tell
exactly which state is it
– Agent knows exactly what each of its
actions does
– Agent can calculate exactly which
state it will be in after any sequence of
actions
Problem Types (2)
• Multiple-state problem
– Percepts give not enough information to
tell which state is it
– Agent knows all the effects of its
actions
– Agent must reason about sets of
states that it might get to
Basic Elements of a Problem
Definition
• A problem is a collection of
information that the agent can use to
decide what to do
• Information specification for singlestate problem definition
Basic elements:
– States
– Actions
State Space of the Problem
• State space is the set of all states
reachable from the initial state by any
sequence of actions
– The initial state is the state that the agent
knows itself to be in
– The goal state corresponds to the solution of
the problem
– The operator describes an action in terms of
which state will be reached by carrying out the
action in a particular state
State Space Representation of
the Problem Using Graph
• The nodes of a graph corresponds to
particular problem solution states
• The arcs correspond to steps in a
problem-solving process
• Initial states form root of the graph and
correspond to the given information in a
problem instance
• Goal states of the problem corresponds to
the solutions to a problem instance
Formal State Space Representation
of the Problem (1)
• A state space is represented by a fourtuple
[N, A, IS, GS], where
N is the set of nodes or states of the graph
A is the set of arcs between nodes
Formal State Space Representation
of the Problem (2)
• A state space is represented by a fourtuple
[N, A, IS, GS], where
IS is the non-empty set that contains the
initial states of the problem
(IS  N)
GS is the non-empty set that contains the
goal states of the problem
(GS  N)
Testing the Goal States
• Agent can apply the goal test to a singlestate description to determine if it is a goal
state
• Description of the goal states:
– Explicit set of possible goal states
– A measurable property of the states
encountered in the search
– A property of the path developed in the
search
Paths in the State Space
• Each path that does reach the goal is called a
complete path
• Each path that does no reach the goal is called a
partial path
• A solution path is a complete path through the
graph from a node in IS to a node in GS
• A path cost function g is a function that assigns
a cost to a path
• The cost of a path is the sum of the costs of the
individual actions along the path
Measuring Problem-Solving
Performance
• Three ways to measure the effectiveness
of a search:
– Does a search find a solution at all?
– Is a solution good (one with a low path cost)?
– What is the search cost associated with the
time and memory required to find a solution?
• The total cost of the search:
Total cost = Path cost + Search cost
Searching for Solutions (1)
• Search process builds up a search
tree (subgraph of the state space)
• Search starts from the search node
that corresponds to the initial state
(the root of the search tree)
• Determining the children of a state is
called expanding the state
Searching for Solutions (2)
• At each step, the search algorithm
chooses one leaf node to expand
– Leaf nodes have not successors
(children)
Two cases:
• They have not been expanded
• They were expanded, but generated the
empty set
• Nodes that are waiting to be
expanded are called a frontier
Search Algorithms for Agents
• INPUT: instances of data type
PROBLEM
• OUTPUT: solution path
• Data type PROBLEM has four
components:
– Initial state
– Operators
– Goal test
– Path cost function
Distinction Between Nodes and
States
• A node is a data structure used to
represent the search tree for a
particular problem instance as
generated by a particular problem
• A state represents a configuration of
the world and is characterized by a
set of features
Data Structure for Search
Trees
• Node v is data structure with five
components:
– The corresponding state in the state space
– The node that generates node v (the parent
node)
– The operator that was applied to generate v
– The depth of the node v (the number of
nodes on the path from the search node to v)
– The path cost of the path from the search
node to v
Classification of Search
Strategies (1)
If available information is specified:
• Uninformed Search (Blind Search)
No information is available about:
• the number of steps
• the path cost
from the current state to the goal
• Informed Search (Heuristic Search)
Problem-specific knowledge is used
Classification of Search
Strategies (2)
If the search direction is specified:
• Data-Driven Search (Forward
Chaining)
– Search starts from the node(s)
representing the given facts of the
problem, applies operators to produce
new nodes that lead to a goal
– Searching forwards means generating
successors successively starting from
the initial (root) node
Classification of Search
Strategies (3)
If the search direction is specified:
• Goal-Driven Search (Backward
Chaining)
– Search starts from the goal, applies operators
that could produce the goal, and chains
backward to the given facts of the problem
– Searching backwards means generating
predecessors successively starting from the
goal node
Classification of Search
Strategies (4)
If the order in which nodes are expanded is
specified:
• Breadth-First Search
• Uniform Cost Search
• Depth-First Search
Uninformed
• Depth-Limited Search
Search
• Iterative Deepening
Search
• Bidirectional Search
Classification of Search
Strategies (5)
If the order in which nodes are expanded is
specified:
• Best-First Search
– Greedy Search (minimizing the
Informed
estimate cost to reach the goal)
Search
– A* Search (minimizing the total
path cost)
Classification of Search
Strategies (6)
If the order in which nodes are expanded is
specified:
• Memory Bounded Search
– IDA* Search (Iterative
Informed
Deepening A* search)
Search
– SMA* Search (Simplified
Memory-Bounded A*)
Classification of Search
Strategies (7)
If the order in which nodes are expanded is
specified:
• Iterative Improvement
Algorithms
– Hill-Climbing Search
Informed
– Random-Restart Hill-Climbing
Search
– Simulated Annealing
– Beam Search
Uninformed
Search Strategies (1)
• Breadth-First Search
–This search expands the shallowest
node in the search tree first
–This search explores the space in a
level-by-level fashion
Breadth-first search
Data driven search
A
B
D
B- the initial node
E
H
H – the goal
F
I
G
J
OPEN
CLOSED
0
B

1
DFG
B
2
FGIJ
BD
3
GIJH
BDF
4
IJH
BDFG
5
JH
BDFGI
6
H
BDFGIJ
Iteration
Goal
C
Uninformed
Search Strategies (2)
• Uniform-Cost Search
–This search expands the lowestcost node on the frontier first
–The path cost must never
decrease
g(successor(n))  g(n)
for every node n
Uninformed
Search Strategies (3)
• Depth-First Search
– This search expands the deepest node
in the search tree first
– This search goes deeper into the search
space whenever this is possible
• Depth-Limited Search
– This search places a limit on how deep
a depth-first search can go (imposes a
cutoff on the maximum depth of a path)
Depth-first search
Data driven search
A
B
D
C
E
F
H
B- the initial node
I
J
H – the goal
Iteration
Goal
G
OPEN
CLOSED
0
B

1
DFG
B
2
IJFG
BD
3
JFG
BDI
4
FG
BDIJ
5
HG
BDIJF
Depth limited search
Data driven search
A
B- the initial node
F- the goal
Depth limit - 2
OPEN
CLOSED
0
B0

1
D1 G1 E1
B
2
F2 H2 G1 E1
BD
Iteration
Goal
B
C
D
E
F
G
H
Node depth
I
J
Uninformed
Search Strategies (4)
• Iterative Deepening Search
– This search call depth-limited search with
increasing limits until a goal is found
– This search expands many states multiple
times
• Bidirectional Search
– This search goes both forwards from the initial
state and backward from the goal, and stop
when the two searches meet in the middle
Bidirectional search
A
A- the initial node
B
C
D
E
F
G
H
J- the goal
Data-driven search
Goal-driven search
I
OPEN
CLOSED
0
J

A
1
GH
J
AC
2
HCD
JG
OPEN
CLOSED
0
A

1
CD
2
DFG
Iteration
Iteration
Solution is found because the node D is found in both OPEN
lists
J
Evaluation of Uninformed Search
Strategies
• Four Criteria
– Completeness (is a solution
guaranteed?)
– Time Complexity (time needed for
search)
– Space Complexity (memory needed for
search)
– Optimality (is highest-quality solution
guaranteed when there are several
different solutions?)
Comparing Uninformed Search
Strategies (1)
Criterion
BreadthFirst
Uniform
cost
DepthFirst
Complete?
+
+
−
Time Complexity
bd
bd
bm
Space Complexity
bd
bd
bm
Optimal?
+
+
−
b is the branching factor (every state can be expanded
to yield b new states),
d is the depth of solution, m is the maximum depth of
the search tree, and l is the depth limit
Comparing Uninformed Search
Strategies (2)
Criterion
DepthLimited
Iterative
Deepening
Bidirectional
Complete?
+, if l  d
+
+
Time Complexity
bl
bd
bd/2
Space Complexity
bl
bd
bd/2
Optimal?
−
+
+
b is the branching factor (every state can be expanded
to yield b new states)
d is the depth of solution
m is the maximum depth of the search tree
l is the depth limit
Strengths of Uninformed Search
Strategies (1)
• Breadth-First Search
–This search always finds the
shortest solution path
• Uniform-Cost Search
–When the cost of the path never
decrease, the first solution that is
found is guaranteed to be the
cheapest solution
Strengths of Uninformed Search
Strategies (2)
• Depth-First Search
–For problems that have very many
solutions, depth-first may actually
be faster than breadth-first search,
because chances to find a solution
after searching only a small part of
the whole space is rather good
Strengths of Uninformed Search
Strategies (3)
• Depth-Limited Search
– It avoids the pitfalls of depth-first search
• Iterative Deepening Search
– It is the preferred search method when
there is a large search space and the
depth of the solution is not known
• Bidirectional Search
– Can enormously reduce time complexity
Weaknesses of Uninformed
Search Strategies (1)
• Breadth-First Search
– Impractical in most cases due to the memory
requirements
– It is optimal only when all operators have the
same cost
• Uniform-Cost Search
– If some operators have negative cost, only an
exhaustive search of all nodes would
guaranteed the optimal solution
Weaknesses of Uninformed
Search Strategies (2)
• Breadth-First Search
(assume that 1 million nodes can be generated per second and
that a node requires 1000 bytes of storage)
• At depth 2 there are 110 nodes, time needed is 0,11 milliseconds
and 107 kilobytes of memory are needed
• At depth 4 there are 11110 nodes, time needed is 11 milliseconds
and 10,6 megabytes of memory are needed
• At depths 6, 8, 10, 12, 14, and 16 the number of nodes is10 in
corresponding power, time needed is 1,1 seconds, 2 minutes, 3
hours, 13 days, 3,5 years, and 350 years, respectively, while 1
gigabyte, 103 gigabites, 10 terabytes, 1 petabyte, 99 petabytes, and
10 exabytes of memory are needed
• Exponential-complexity search is a problem!
Weaknesses of Uninformed
Search Strategies (3)
• Depth-First Search
–Impractical in search trees with
large or infinite maximum depths (it
can get stuck going down the wrong
paths)
• Depth-Limited Search
–In cases when depth limit is too
small there is no guarantee that the
search will find the goal
Weaknesses of Uninformed
Search Strategies (4)
• Iterative Deepening Search
–It is wasteful, because many states
are expanded multiple times
• Bidirectional Search
–It is not always applicable and its
memory requirements may be
impractical
Informed
Search Strategies (1)
• Best-First Search
– This search expands the node that appears to
be the best according to the evaluation
function
* Greedy Search
– This is one of the simplest best-first search
strategies that uses minimization of the
estimated cost of the cheapest path
(heuristic function h(n)) to reach the goal
– This search expands the node whose state is
judged to be closest to the goal state
Best first search
B
6 =1+5
A
10 = 0+10
C
8 =1+7
D
6
4 =1+3
Node heuristic measures
The best measure is the highest
value
E
5 =2+3
F
7 =2+5
G
4 =2+2
A- the initial node
H- the goal
H
5 =3+2
Iteration
I
3 =3+0
OPEN
CLOSED
0
A(10)

1
C(8) B(6) D(4)
A(10)
2
B(6) E(5) D(4) G(4)
A(10) C(8)
3
F(7) E(5) D(4) G(4)
A(10) C(8) B(6)
4
E(5) D(4) G(4) I(3)
A(10) C(8) B(6) F(7)
5
H(5) D(4) G(4) I(3)
A(10) C(8) B(6) F(7) E(5)
Informed
Search Strategies (2)
• A* Search
– This search expands the node n with the
lowest value of the estimated cost of the
cheapest solution through n:
f(n) = g(n) + h(n)
Informed
Search Strategies (3)
• Memory-Bounded Search
– This search conserves memory
• Iterative Deepening A* Search (IDA*)
– In this search each iteration is a depth-first search
that is modified to use an f-cost limit (not depth limit)
– This search expands all nodes inside the contour for
the current f-cost, peeping over the contour to find out
where the next contour is (contour in the state space
is a set of nodes where all nodes have f(n) less than
or equal to f-cost of that contour)
Informed
Search Strategies (4)
• Simplified Memory-Bounded A*
Search (SMA*)
– This search drops nodes that are
unpromising (nodes with high f-cost)
when it needs to generate a successor
but has no memory left
Informed
Search Strategies (5)
• Iterative Improvement Algorithms
– This search explores the state space trying to
find the best value of the estimated cost,
which is the optimal solution
• Hill-Climbing Search
– This search continually expands nodes that
have better estimated costs of the remaining
distance to the goal then previous ones
Hill climbing
A
10 = 0+10
6
B
9= 1+8
C
5 =1+4
D
8 =1+7
Node heuristic measures
The best measure is the lowest
value
A- the initial node
E
4 =2+2
F
2 =2+0
H
3 =3+0
I
8 =3+5
Iteration
G
6 =2+4
H- the goal
OPEN
CLOSED
0
A(10)

1
C(5)
A(10) B(9) D(8)
2
E(4)
A(10) B(9) D(8) C(5) G(6)
3
H(3)
A(10) B(9) D(8) C(5) G(6) E(4) I(8)
Informed
Search Strategies (6)
• Simulated Annealing
– This search picks a randomly selected
successor of the current node. If the move
improves the situation, it is always executed.
Otherwise, the algorithm makes the move
with some probability less than 1
– The probability decreases exponentially with
the “badness” of the move calculated as the
difference of values between next and current
states
Informed
Search Strategies (7)
• Beam Search
–This search proceeds as in
breadth-first search, except that
only the best W states are
chosen at each level
Beam search
A
10 =0+10
6
B
6 =1+5
C
8 =1+7
D
4 =1+3
E
5 =2+3
F
7 =2+5
G
4 =2+2
Node heuristic measures
The best measure is the highest
value
A- the initial node
H- the goal
H
4 = 3+1
Iterācija
I
Beam width - 2
3 =3+0
OPEN
CLOSED
0
A(10)

1
C(8) B(6)
A(10) D(4)
2
F(7) E(5)
A(10) D(4) C(8) B(6) G(4)
3
H(4) I(3)
A(10) D(4) C(8) B(6) G(4) F(7) E(5)
The goal is reached
Strengths of Informed Search
Strategies (1)
More information leads to reduced time and space
complexity. The time complexity depends on the
quality of the heuristic function
• Best-First Search
– This search can find solutions more effectively
than uninformed search
– It is good when there is natural measure of
goal distance and a good partial path may
look like a bad option before more promising
partial paths are played out
Strengths of Informed Search
Strategies (2)
* Greedy Search
– This search substantially reduces the time
and space complexity if a good heuristic
function is used
– This search cuts the search cost considerably
* A* Search
– This search is optimally efficient for any given
heuristic function (no other optimal algorithm
is guaranteed to expand fewer nodes)
Strengths of Informed Search
Strategies (3)
• Memory-Bounded Search
– This search conserves memory
* IDA* Search
– IDA* only goes through two or three
iterations since typically f only increases
two or three times along any solution
path
Strengths of Informed Search
Strategies (4)
* SMA Search
–SMA* can make use of all available
memory to carry out the search,
and avoids repeated states as far
as its memory allows
–Given a reasonable amount of
memory, SMA* can solve
significantly more difficult problems
than A*
Strengths of Informed Search
Strategies (5)
• Iterative Improvement
Algorithms
–This search keeps track of only the
current state and do not look ahead
beyond the immediate neighbors of
that state
Strengths of Informed Search
Strategies (6)
* Hill-Climbing Search
– This search does not maintain a search
tree, so the node data structure need
only record the state and its evaluation
– It is good when there is a natural
measure of distance from each place to
the goal and a good path is likely to be
among the partial paths that appear to
be good at each choice point
Strengths of Informed Search
Strategies (7)
* Random-Restart Hill-Climbing Search
– This search eventually finds the optimal solution if
enough iterations are allowed
– Usually a reasonably good solution can be found after
a small number of iterations
* Simulated Annealing
– This search provides a way to escape local maxima
by picking a random move instead of the best move
– It is applied widely to large-scale optimization tasks
Strengths of Informed Search
Strategies (8)
* Beam Search
– This search moves downward only through
the best W nodes at each level, the other
nodes are ignored
– The number of nodes explored remains
manageable, even if there is a great deal of
branching and the search is deep
– It is good when there is natural measure of
goal distance and a good path is likely to be
among the partial path that appear to be good
at all levels
Weaknesses of Informed Search
Strategies (1)
Because heuristics use limited
information they can lead a search
algorithm to a suboptimal solution or
fail to find any solution at all
• Best-First Search
– In this search evaluation function
sometimes can lead search astray. It is
not good when the branching factor is
too large
Weaknesses of Informed Search
Strategies (2)
* Greedy Search
– This search is susceptible to false starts
– heuristic may cause unnecessary
nodes to be expanded. The algorithm is
neither complete nor optimal
* A* Search
– This search is not an answer to all
searching needs because at the worst
case exponential growth will occur
Weaknesses of Informed Search
Strategies (3)
• Memory-Bounded Search
* IDA* Search
– If the heuristic value is different for every
state then each contour only included
one more state than the previous
contour, and IDA* will expand N2 nodes
in N iterations (too long to wait in
complex domains)
Weaknesses of Informed Search
Strategies (4)
* SMA* Search
– On very hard problems this search is
forced to continually switch back and forth
between a set of candidate solution paths
– Extra time is required for repeated
generation of the same nodes, and as a
consequence memory limitations can make
a problem intractable from the point of view
of computation time (algorithm is not
optimal)
Weaknesses of Informed Search
Strategies (5)
• Interactive Improvement Algorithms
* Hill-Climbing Search
– This search suffers from local maxima (on it
the algorithm will halt even though the
solution may be far from satisfactory),
plateaux (the search will conduct a random
walk because the evaluation function is
essentially flat), ridges (if there are not
operators that move directly to the top of the
ridge, the search may oscillate from side to
side, making little progress)
Weaknesses of Informed Search
Strategies (6)
* Random-Restart Hill-Climbing Search
– If it is a complex problem the solution is not
guaranteed due to the inherent limitation of
heuristic search
* Simulated Annealing
– In cases when the values of the parameter
used to determine the probability of allowing
moves are not lowered slowly enough the
algorithm will not find a global optimum
Weaknesses of Informed Search
Strategies (7)
* Beam Search
–The solution is not guaranteed due
to the inherent limitations of
heuristic search (the algorithm is
not complete)
Download