Beruflich Dokumente
Kultur Dokumente
Topics
Problem Solving
Searching Methods
Game Playing
Introduction
Problem solving is mostly based on searching.
Every search process can be viewed as a traversal of a
directed graph in which each node represents a problem
state and each arc represents a relationship between the
states represented by the nodes it connects.
The search process must find a path through the graph,
starting at an initial state and ending in one or more final
states. The graph is constructed from the rules that define
the allowable moves in the search space. Most search
programs represent the graph implicitly in the rules to
avoid combinatorial explosion and generate explicitly only
those parts that they decide to explore.
Introduction
Goal : a description of a desired solution (may be a state
(8-puzzle) or a path (traveling salesman)).
Search space: set of possible steps leading from initial
conditions to a goal.
State: a snapshot of the problem at one stage of the solution.
The idea is to find a sequence of operators that can be applied
to a starting state until a goal state is reached.
A state space: the directed graph whose nodes are states and
whose arcs are the operators that lead from one state to another.
Problem solving is carried out by searching through the space
of possible solutions for ones that satisfy a goal.
Search
Five important issues that arise in search
techniques are:
The direction of the search
The topology of the search process
Representation of the nodes
Selecting applicable rules
Using heuristic function to guide the search
Explanation of reasoning
MYCIN program that diagnoses infectious diseases uses
backward reasoning to determine the cause of patient's
illness.
A doctor may reason as follows:
If an organism has a set of properties (lab results) then it is
likely that the organism is X.
Even though the evidence is most likely documented in the
reverse direction
(IF (ORGANISM X) (PROPERTIES Y)) CF
The rules justify why certain tests should be performed.
Goal Test
>(defvar *goal-state* (1 2 3 8 0 4 7 6 5 ))
>(equal *goal-state* (1 2 3 8 0 4 7 6 5 ))
t
Operators
Functions from state to subset of states
drive to neighboring city
place piece on chess board
add person to meeting schedule
slide a tile in 8-puzzle
Matching Conflict resolution:
order (priority)
recency
Indexing
2
1
fails to
distinguis
h
1
8
7
3
4
Start
5
Goal
more accurate
(1)
(2)
(3)
Types of Search
There are three broad classes of search processes:
1) Uninformed- Blind Search
Types of Search
2) Informed Heuristic search - there is specific information
to focus the search.
Hill climbing
Branch and bound
Best first
A*
Search Algorithms
Task
Depth-first search
Uses generate and test strategy. Nodes are generated by
applying the applicable rules. Then, each generated node
is tested if it is the goal. Nodes are generated in a
systematic form. It is an exhaustive search of the problem
space.
1. Form a one element queue consisting of the root node
2. Until the queue is empty or the goal has been reached,
determine if the first element in the queue is the goal
node.
a) If the first element is the goal do nothing.
b) If the first element is not the goal node remove the first element
from the queue and add the first element's children if any to the
front of the queue.
3.
Depth-first search
- lists: keep track of progress through state space
- open states generated but children not examined
- closed states already examined
begin
open := [Start]
/initialise
close := [];
while open <> [] do
begin
remove leftmost state from open, call it X;
if X is a goal then return (success)
else begin
generate children of X;
put X on close;
eliminate children of X on open or close;
/loop check
put remaining children on the left end of open /queue
end
end;
return (failure) /no states left
end.
Depth-first search
Depth-first search
Evolution of the closed
and open lists
1. [1] []
2. [2 3] [1]
3. [4 5 3] [1 2 ]
4. [8 9 5 3 ] [1 2 4]
.
Depth-first Evaluation
Branching factor b, depth of solutions d, max depth m:
Incomplete: may wonder down the wrong path. Bad
for deep and infinite depth state space
Time: bm nodes expanded (worst case)
Space: bm (just along the current path)
Does not guarantee the shortest path. Good when
there are many shallow goals.
Breadth-first search
It will first explore all paths of length one, then
two and if a solution exists it will find it at the
exploration of the paths of length N. There is a
guarantee of finding a solution if one exists.
It will find the shortest path from the solution, it
may not be the best one.
Breadth-first search
The algorithm:
1. Form one element queue consisting of the root node
2. Until the queue is empty or the goal has been reached,
determine if the first element in the queue is the goal node.
a) If the first element is the goal do nothing.
b) If the first element is not the goal node remove the first
element from the queue and add the first element's children
if any to the back of the queue.
3. If the goal node has been found announce success,
otherwise announce failure.
Breadth-first search
Breadth-first search procedure
begin
open := [Start]
/initialise
close := [];
while open <> [] do
begin
remove leftmost state from open, call it X;
if X is a goal then return (success)
else begin
generate children of X;
put X on close;
eliminate children of X on open or close; /loop check
put remaining children on the right end of open /queue
end
end;
return (failure)
/no states left
end.
Breadth-first search
Breadth-first search
Evolution of the open and
closed lists
1. [1] [ ]
2. [2 3 ] [ 1 ]
3. [3 4 5 ] [1 2 ]
4. [4 5 6 7 ] [1 2 3 ]
..
Breadth-first Evaluation
Heuristic Search
Reasons for heuristics
- impossible for exact solution,
heuristics lead to promising path
- no exact solution but an acceptable one
- fallible due to limited information
Intelligence for a system with limited processing resources
consists in making wise choices of what to do next
Heuristics = Search Algorithm + Measure
Hill climbing
Hill climbing is depth first search with a heuristic
measurement that orders choices as nodes are expanded.The
algorithm is the same only 2b differs slightly.
1. Form a one element queue consisting of the root node
2. Until the queue is empty or the goal has been reached,
determine if the first element in the queue is the goal node.
a) If the first element is the goal do nothing.
b) If the first element is not the goal node remove the first
element from the queue, sort the first elements children, if
any by estimated remaining distance, and add the first
element's children if any to the front of the queue.
3. If the goal node has been found announce success,
otherwise announce failure.
Hill climbing
Hill climbing
Problems that may arise:
A local maximum, is a state that is better than all its
neighbors, but is not better than some other states farther
away. At a local maximum, all moves appear to make
things worse.
A plateau, A whole set of neighboring states have the
same value.It is not possible to determine the best
direction.
A ridge,. Higher than surrounding area but can not be
traversed by single move in any one direction.
Hill climbing
Some ways of dealing with these:
Backtrack: local maximum
Make a big jump in one direction to try to get to
new section of search space (plateau)
Apply two or more rules before doing the test.
This corresponds to moving in several directions
at once (ridges).
Best-first Search
Best-first search is a combination of depth-first and breadthfirst search algorithms. Forward motion is from the best
open node (most promising) so far, no matter where it is on
the partially developed tree.
The second step of the algorithm changes as:
2. Until the queue is empty or the goal has been reached,
determine if the first element in the queue is the goal node.
a) If the first element is the goal do nothing.
b) If the first element is not the goal node remove the first
element from the queue and add the first element's
children if any to the queue and sort the entire queue by
estimated remaining distance..
Best-First Search
procedure best_first_search;
begin
open := [Start]; closed = [];
while open <> [] do
remove leftmost state from open, call it X;
if X = goal then return path from Start to X
else begin
generate children of X; for each child of X do
case
the child is not on open or closed:
begin
assign child heuristic value;
add child to open
end;
the child is already on open:
if the child reached by shorter path
then give state on open shorter path
the child is already on closed:
if child reached shorter path then
begin
remove state from closed;
add child to open
end;
end case;
put X on closed;
re-order states on open by heuristic method
end;
return failure
end.
C-4
D-6
J
N O-2 P-3 Q
A* Search
Dynamic-programming principal holds that when looking
for the best path from S to G, all paths from S to any
intermediate node, I, other than the minimum length path
from S to I, can be ignored.
The A* procedure is branch and bound search in a graph
space with an estimate of remaining distance, combined
with dynamic programming principle.
If one can show that h(n) never overestimates the cost to
reach the goal, then it can be shown that the A* algorithm
is both complete and optimal.
A* Search
To do A* search with lower bound estimates:
2b4) sort the queue by the sum of the cost
accumulated so far and a lower bound
estimate of the cost remaining, with least cost
paths in front.
2b5) If two or more paths reach a common
node, delete all those paths except for one
that reaches the common node with the
minimum cost.
move(1, 6)
move(3, 4)
move(6, 7)
move(1, 8)
move(3, 8)
move(6, 1)
move(2,7)
move(4, 3)
move(7, 6)
move(2, 9)
move(4, 9)
move(7, 2)
move(8,3)
move(9,4)
move(8,1)
move(9,2)
Farmer-Wolf-Cabbage Problem
A Farmer with his wolf, goat and cabbage come to the
edge of a river they wish to cross. There is a boat at the
rivers edge, but of course only the farmer can raw it. The
boat also can carry only two things. If the wolf is ever left
alone with the goat, the wolf will eat the goat. If the goat is
ever left alone with the cabbage, the goat will eat the
cabbage. Devise a sequence of crossings of the river so
that all four characters arrive safely on the other side of the
river.
The problem implementation.
(defun farmer-takes-self(state)
(make-state(opposite (farmer-side state))
(wolf-side state)
(goat-side state)
(cabbage-side state)))
>(safe (e w w e))
(defun safe(sate)
(cond((and (equal(goat-side state) (wolf-side state))
(not(equal(farmer-side state) (wolf-side state)))
nil)
; wolf eats goat
((and(equal(goat-side state) (cabbage-side state))
(not(equal(farmer-side state) (goat-side state)))
nil)
; goat eats cabba
(t state)))
(defun farmer-takes-wolf(state)
(cond((equal (farmer-side state) (wolf-side state))
(safe (make-state (opposite (farmer-side state))
(oppsite (wolf-side state))
(goat-side state)
(cabbage-side state))))
(t nil)))
(defun farmer-takes-goat(state)
(cond((equal (farmer-side state) (goat-side state))
farmer and on the same side
(defun farmer-takes-cabbage(state)
(cond((equal (farmer-side state) (cabbage-side state))
(safe (make-state (opposite (farmer-side state))
(wolf-side state)
(goat-side state)
(oppsite (cabbage-side state)))))
(t nil)))
(defun breadth-first ()
(cond ((null *open*) nil)
(t (let ((state (car *open*)))
(cond ((equal state *goal*) success)
(t (setq *closed* (cons state *closed*))
(setq *open* (append (cdr *open*)
(generate-descendants state *moves*)))
(breadth-first)))))))
References
Nilsson, N.J. Artificial Intelligence: A new
Synthesis, Morgan Kaufmann, 1998