Problem Solving
• The goal is to develop a program that can
solve puzzles:
• Solution ProblemSolver(problem){
… //algoithm
}
Problem Specification
• Initial state description
• Goal state description
• A set of operations
• [Sometimes] The cost of each operation
(needed to find the cost of the solution)
Problem Search Space
• The set of all states that can be reached
by applying a sequence of zero or more
operations starting at the initial state
• Represented as a directed graph. Nodes
are states and edges are operations
• A solution of the problem is a sequence of
operations along a path from the initial to
the goal state
8-puzzle
• Initial state
• Goal state
• Operations: move blank up, down, left,
right
• Cost for every operation = 1
• Search space size <= 9!=362,880
• Part of the search space …
3 2 1
6 5 7
8 4
1 2 3
4 5 6
7 8
Part of Search Space of 8-puzzle
3 2 1
6 5 7
8 4
3 2 1
6 5 7
8 4
3 2 1
6 7
8 5 4
3 2 1
6 5 7
8 4
left up right
right
down
left
Coins Problem
• Initial state HHH
• Goal state TTT
• Operations:
1. flip first coin
2. flip second coin
3. flip third coin
• Cost=1
• Search space and solutions …
Search Space for 3-coins Problem
HHH
HTH THH
TTH
TTT
THT
HHT
HTT
1
1
1
1
2
2
2
2
3
3
3
3
Missionaries and Canibals
• 3 missionaries (M) and 3 cannibals (C)
and a boat on the left bank of a river
• Boat carries only 1 or 2 persons at a time
• Boat cannot move alone
• Cannibals should not outnumber
missionaries on either side
• Find a way to move the six persons to the
right side
Missionaries and Canibals (cont.)
• Initial state (MMMCCCB,-)
• Goal state (-,MMMCCCB)
• Operations:
C C
CC CC
MC MC
MM MM
M M
• Cost=1. Other logical values?
• Search space size is 15 states
Missionaries and Canibals Search Space
Part of search space
MMMCCCB, ----
MMMCC, CB MMMC, CCB MMCC, MCB
MMMCCB, C
MMM,CCCB
C <-
C ->
C ->
C <-
MC <-
MC ->
CC ->
CC <-
CC <- CC ->
C ->
…
Route Finding
Problem: Given a map (Graph) Find a route
from X to Y.
– Initial state: in X
– Goal state: in Y
– Operations: edges
– Cost: distance, travel time, …
– Search space is the graph itself
Example
Searching for solutions
• State expansion: applying operations and
finding resulting states. Examples from
coin, 8-puzzle, MC
• Searching for a solution is done by
building a search tree
Building Search tree
1. Initialize search tree to initial state (root)
2. Select a terminal node for expansion
using some search strategy. If no
candidates return failure
3. If the chosen node contains a goal state
then return the solution else expand the
node and add resulting nodes to the tree
4. Go to 2
Search tree examples
• Route finding
• 8-puzzle
• 3-coins
• MC
A
B D
G
C
E
F
Data structures for search tree
• To be able to return a solution, a node in the
search tree is a structure containing:
1. state
2. a pointer to the parent
3. the operator used to generate the state
4. cost = cost(parent) + cost(operator)
• Expand operation computes each of these
components
• Examples: 8-puzzle, MC
Search Tree Node Example
Initial state node in 8-puzzle
state Parent Operation Cost
NULL none 0
2 3 2
4 7
5 6 8
Search Strategies Evaluation
• Completeness: Guaranteeing reaching a
solution if it exists.
• Optimality: Guaranteeing reaching the
best solution.
• Time complexity
• Space complexity
Search Strategies Types
• Blind: No study of states
breadth-first, depth-first search, uniform-
cost search
• Informed: search strategy is based on
states evaluation
Breadth-First Search
• Select the terminal node with minimum
depth. Break ties randomly
• Travels the search space level by level
• Best implemented using a queue
Breadth-First Search Example
Find a route from A to G
A
B
C
D E F G
Breadth Example Cont
• Do search tree trace
– States expanded: A, B, C, D, E, F, G
– Solution A, C, G
• Tracing using OPEN (queue) and
CLOSED lists
OPEN CLOSD
A -
B, C // or C,B A
C, D, E A, B
D, E, F, G A, B, C
E, F, G A, B, C, D
F, G A, B, C, D, E
G A, B, C, D, E, F
- A, B, C, D, E, F, G
Repeated states
• Example
• Allowing repeated states costs memory
and execution time
• Avoiding repeated states requires
checking every resulting state during
expansion
A B C
Breadth-First search Algorithm
(without repeated states)
Breadth First search Algorithm
Repeated states are not allowed
1. create a list of nodes called OPEN containing one node representing the
initial state of the problem.
2. create an empty list of nodes called CLOSED.
3. while (OPEN is not empty) do {
3.1. N=first node in OPEN.
3.2 Delete N from OPEN.
3.3 add N to CLOSED.
3.4 if N contains a goal state return N and the solution.
3.5. E= expand(N). // E is the set of states that result from applying the
operators to the state inside N
3.6 for every state i in E do
if (i is not neither in any OPEN node nor in any CLOSED node)
Create a node for i and add it at the end of OPEN;
// i should point to N which is on the CLOSED list
}//while
4. return failure.
Breadth-First Evaluation
• BFS is complete
• BFS is not optimal
• Branching factor: average number of
states resulting from expansion. E.g. 8-
puzzle is approx 3.
• Assume goal is at depth d and branching
factor is b.
Breadth-First Evaluation Cont.
• Time and memory analysis assumes all
nodes at level d are dead ends
• Number of nodes expanded is
1+b+b^2+b^3+…+b^d
• Time complexity is O(b^d)
• Space complexity (OPEN+CLOSED size)
is O(b^d)
Example
• Assume b=10
• CPU can expand 1 million nodes/second
• Node size 1000 bytes
Example Cont.
Depth Nodes Time Memory
0 1 1 ms 100 bytes
2 111 0.1 sec 11 kb
4 11,111 11 sec 1mb
6 10^6 18 min 111 mb
8 10^8 31 hrs 11 gb
10 10^10 128 days 1 tb
12 10^12 35 years 111 tb
14 10^14 3500 years 11,111 tb
Depth-First Search
• Select the terminal node with maximum
depth. Break ties randomly
• Travels the search space down
• Best implemented using a stack
Depth-First Search Example
Find a route from A to G
A
B
C
D E F G
Depth-First Example Cont.
• Do search tree trace
– States expanded: A, B, D, E, C, F, G
– Solution A, C, G
• Tracing using OPEN (stack) and CLOSED
lists
OPEN CLOSD
A -
B, C // or C,B A
D, E, C A, B
E, C A, B, D
C A, B, D, E
F, G A, B, D, E, C
G A, B, D, E, C, F
- A, B, D, E, C, F, G
Depth-First search Algorithm
Depth First search Algorithm
Repeated states are not allowed
1. create a list of nodes called OPEN containing one node representing the
initial state of the problem.
2. create an empty list of nodes called CLOSED.
3. while (OPEN is not empty) do {
3.1. N=first node in OPEN.
3.2 Delete N from OPEN.
3.3 add N to CLOSED.
3.4 if N contains a goal state return N and the solution.
3.5. E= expand(N). // E is the set of states that result from applying
the //operators to the state inside N
3.6 for every state i in E do
if (i is not neither in any OPEN node nor in any CLOSED node)
Create a node for i and add it at the front of OPEN;
// i should point to N which is on the CLOSED list
}//while
4. return failure.
Depth-First Evaluation
• DFS is not complete; can go into an
infinite section of search space missing
goal
• Depth-First is not also complete when
states are repeated:
A G
B
C
States expanded: A, B, C, A, B, C, …
Depth-First Evaluation Cont.
DFS is not optimal
S
G
A
5
1 1
Depth-First Evaluation Cont.
• Number of nodes expanded (worst case)
is
1+b+b^2+b^3+…+b^d
• Time complexity is O(b^d)
• Space complexity (OPEN+CLOSED size)
is O(b^d)
• When states are not repeated and path to
the goal is not needed, space complexity
is O(b.d)
Uniform Cost Search
• Search Strategy: select the terminal node
form OPEN that has minimum cost. Break
ties randomly
• Implemented by avoiding repeated states.
Keep the node that has lower cost
Uniform Example
S
A
B
C
G
1 10
5 5
15
5
Implementation
• Use two lists OPEN, CLOSED
• OPEN is a minimum heap. Key is cost.
• Previous example
Evaluation
• Uniform is both complete and optimal
provided that the search space has no
loop with a total negative cost.
• Example
S A
B
G
2
3
-8
11
Memory and Time
• Branching factor = b
• Goal at depth = d
• Operators have all equal cost
• Uniform works as breadth and worst case
memory and time complexities are O(b^d)
Informed Search Methods
• Search strategy is based on states
evaluation
• States are evaluated using a heuristic
• A heuristic estimates the cost of reaching
the goal from state
• A heuristic is represented by a function
h:state  number
• h(goal)=0
Example: 8-puzzle Cont
• h1 = # of tiles in the wrong location. h1 is between
0 and 8
• Example
Goal X Y
• Problem: although Y is much better than X, h1
assigns both X and Y an equal value 2
1 2 3
4 5 6
7 8
8 2 3
4 5 6
7 1
1 2 3
4 5 6
7 8
Example: 8-puzzle, cont.
• h2 = sum of Manhattan distances of tiles from correct
location. Manhattan distance is minimum number of
moves between locations
• Example
Goal X Y
• Problem: h2 gives a good evaluation for adjacent tiles
that need to be exchanged. h2(X)=2 and h2(Y)=2
• h3=h1+ w*number of adjacent pairs when exchanged
become in correct locations
1 2 3
4 5 6
7 8
4 2 3
1 5 6
7 8
1 2 3
4 5 6
7 8
Example: Missionaries and
Canibals
• h= # of persons on the left side of the river
• Initial: mmmcccb,- h=6
Goal: -,mmmcccb h=0
cb,mmmcc h=1
Route Finding
• Short-line distance heuristic
• h(s)=short-line distance between s and
goal
• h(s)=0
Best-First search
• Select the terminal node from OPEN that
has minimum h value. Break ties randomly
• Example
S H
A
D
C E
B
F
G
Exercize
3-puzzle
initial goal
h = sum of Manhatten Distances
3 2
1
1 2
3
Algorithm
Best First search Algorithm
Repeated states are not allowed
// The algorithm is capable of finding the path to the goal state
Steps:
1. create a list of nodes called OPEN containing one node representing the initial state of the
problem. Compute h value for the node.
2. create an empty list of nodes called CLOSED.
3. while (OPEN is not empty) do {
3.1. N=the node in OPEN having best h value.
3.2. Delete N from OPEN;
3.3 add N to CLOSED.
3.4 if N contains a goal state return N and the solution.
3.5. E=expand(N); // E is the set of states that result from applying the operators to the
state inside N
3.6. for every state i in E do{
compute h(i);
if (i is not neither in any OPEN node nor in any CLOSED node){
Create a node for i and add it to OPEN;
Make i point to N which is on the CLOSED list;
}//if
}//for
}//while
4. return failure.
Evaluation
• Not complete. Can go through an infinite search
space in which all the nodes have a better
heuristic than the node at the other branch
leading to the goal
• The algorithm might not also be complete when
states are repeated
S
A
B C
Evaluation Cont
• Not optimal
• In the worst case the algorithm works
similar to breadth first search; h always 1.
Worst case time and memory complexities
is O(b^d).
• Performance largely dependent on
heuristic quality
A* Search
• Search strategy is based on:
f(n)=g(n)+h(n), where
g(n)=the cost of the path from initial state to n
h(n)=estimate of the cost of the path from n
to goal
• f(n)=an estimate of the cost of a solution
through n
Example
• Repeated states are avoided
G
D
S
A
B
7
1
10
7
1
h=17
h=5
h=9
h=7 h=0
A* Algorithm
1. Create OPEN containing one node representing initial state
2. Create CLOSED, empty
3. While (OPEN is not empty){
3.1 N=node on OPEN that has best f
3.2 delete N from OPEN
3.3 add N to CLOSED
3.4 if (N contains goal) return N
3.5 E=expand(N)
3.6 for every state (i,op) in E do
if (i is new)
create a new node for i and add it to OPEN
else
if ((g(N) + cost(op)) < g(oldNode)){
remove oldNode;
create a new node for (i,op) and add it to OPEN
}
}//for
}//while
4. Return Failure
Admissability
• A hueristic function h is admissable if it
never over estimates the actual cost
• Shortest-line-distance is admissable
• So is SLD-10, sqrt(SLD)
• But not SLD+10, SLD^2
Evaluation
A* is complete and optimal if
1.H is admissable
2.Search space has no cycle with a total
negative weight
Example
H is not admissable and A* is not optimal
S
h=5
A
B C
D
E G
1
1
1
1
1
1
1
h=4
h=3
h=2
h=1 h=0
Evaluation Cont.
• Worst case time and memory is O(b^d):
• H=0
• All operators has equal cost=1
• A* works similar to breadth first search
Hill-climbing
• Based on a heuristic
• Follows a single path when searches for a
solution
• Stops when current state is better than
neighboring states
Algorithm
Current=initial-state;
E=expand(Current);
S=best state in E;
while (S is better than Current){
S=Current;
E=expand(Current);
S=best state in E;
}
Return Current; //not complete
Example
S A B
D E
G
Hill-Climbing problems
• Hill-climbing scenario
• Local maxima problem
• Plateau problem
• Possible solution: run algorithm multiple
times starting from different random initial
states and return the best result found.

problem solving for AI and Machine Learning

  • 1.
    Problem Solving • Thegoal is to develop a program that can solve puzzles: • Solution ProblemSolver(problem){ … //algoithm }
  • 2.
    Problem Specification • Initialstate description • Goal state description • A set of operations • [Sometimes] The cost of each operation (needed to find the cost of the solution)
  • 3.
    Problem Search Space •The set of all states that can be reached by applying a sequence of zero or more operations starting at the initial state • Represented as a directed graph. Nodes are states and edges are operations • A solution of the problem is a sequence of operations along a path from the initial to the goal state
  • 4.
    8-puzzle • Initial state •Goal state • Operations: move blank up, down, left, right • Cost for every operation = 1 • Search space size <= 9!=362,880 • Part of the search space … 3 2 1 6 5 7 8 4 1 2 3 4 5 6 7 8
  • 5.
    Part of SearchSpace of 8-puzzle 3 2 1 6 5 7 8 4 3 2 1 6 5 7 8 4 3 2 1 6 7 8 5 4 3 2 1 6 5 7 8 4 left up right right down left
  • 6.
    Coins Problem • Initialstate HHH • Goal state TTT • Operations: 1. flip first coin 2. flip second coin 3. flip third coin • Cost=1 • Search space and solutions …
  • 7.
    Search Space for3-coins Problem HHH HTH THH TTH TTT THT HHT HTT 1 1 1 1 2 2 2 2 3 3 3 3
  • 8.
    Missionaries and Canibals •3 missionaries (M) and 3 cannibals (C) and a boat on the left bank of a river • Boat carries only 1 or 2 persons at a time • Boat cannot move alone • Cannibals should not outnumber missionaries on either side • Find a way to move the six persons to the right side
  • 9.
    Missionaries and Canibals(cont.) • Initial state (MMMCCCB,-) • Goal state (-,MMMCCCB) • Operations: C C CC CC MC MC MM MM M M • Cost=1. Other logical values? • Search space size is 15 states
  • 10.
    Missionaries and CanibalsSearch Space Part of search space MMMCCCB, ---- MMMCC, CB MMMC, CCB MMCC, MCB MMMCCB, C MMM,CCCB C <- C -> C -> C <- MC <- MC -> CC -> CC <- CC <- CC -> C -> …
  • 11.
    Route Finding Problem: Givena map (Graph) Find a route from X to Y. – Initial state: in X – Goal state: in Y – Operations: edges – Cost: distance, travel time, … – Search space is the graph itself
  • 12.
  • 13.
    Searching for solutions •State expansion: applying operations and finding resulting states. Examples from coin, 8-puzzle, MC • Searching for a solution is done by building a search tree
  • 14.
    Building Search tree 1.Initialize search tree to initial state (root) 2. Select a terminal node for expansion using some search strategy. If no candidates return failure 3. If the chosen node contains a goal state then return the solution else expand the node and add resulting nodes to the tree 4. Go to 2
  • 15.
    Search tree examples •Route finding • 8-puzzle • 3-coins • MC A B D G C E F
  • 16.
    Data structures forsearch tree • To be able to return a solution, a node in the search tree is a structure containing: 1. state 2. a pointer to the parent 3. the operator used to generate the state 4. cost = cost(parent) + cost(operator) • Expand operation computes each of these components • Examples: 8-puzzle, MC
  • 17.
    Search Tree NodeExample Initial state node in 8-puzzle state Parent Operation Cost NULL none 0 2 3 2 4 7 5 6 8
  • 18.
    Search Strategies Evaluation •Completeness: Guaranteeing reaching a solution if it exists. • Optimality: Guaranteeing reaching the best solution. • Time complexity • Space complexity
  • 19.
    Search Strategies Types •Blind: No study of states breadth-first, depth-first search, uniform- cost search • Informed: search strategy is based on states evaluation
  • 20.
    Breadth-First Search • Selectthe terminal node with minimum depth. Break ties randomly • Travels the search space level by level • Best implemented using a queue
  • 21.
    Breadth-First Search Example Finda route from A to G A B C D E F G
  • 22.
    Breadth Example Cont •Do search tree trace – States expanded: A, B, C, D, E, F, G – Solution A, C, G • Tracing using OPEN (queue) and CLOSED lists OPEN CLOSD A - B, C // or C,B A C, D, E A, B D, E, F, G A, B, C E, F, G A, B, C, D F, G A, B, C, D, E G A, B, C, D, E, F - A, B, C, D, E, F, G
  • 23.
    Repeated states • Example •Allowing repeated states costs memory and execution time • Avoiding repeated states requires checking every resulting state during expansion A B C
  • 24.
    Breadth-First search Algorithm (withoutrepeated states) Breadth First search Algorithm Repeated states are not allowed 1. create a list of nodes called OPEN containing one node representing the initial state of the problem. 2. create an empty list of nodes called CLOSED. 3. while (OPEN is not empty) do { 3.1. N=first node in OPEN. 3.2 Delete N from OPEN. 3.3 add N to CLOSED. 3.4 if N contains a goal state return N and the solution. 3.5. E= expand(N). // E is the set of states that result from applying the operators to the state inside N 3.6 for every state i in E do if (i is not neither in any OPEN node nor in any CLOSED node) Create a node for i and add it at the end of OPEN; // i should point to N which is on the CLOSED list }//while 4. return failure.
  • 25.
    Breadth-First Evaluation • BFSis complete • BFS is not optimal • Branching factor: average number of states resulting from expansion. E.g. 8- puzzle is approx 3. • Assume goal is at depth d and branching factor is b.
  • 26.
    Breadth-First Evaluation Cont. •Time and memory analysis assumes all nodes at level d are dead ends • Number of nodes expanded is 1+b+b^2+b^3+…+b^d • Time complexity is O(b^d) • Space complexity (OPEN+CLOSED size) is O(b^d)
  • 27.
    Example • Assume b=10 •CPU can expand 1 million nodes/second • Node size 1000 bytes
  • 28.
    Example Cont. Depth NodesTime Memory 0 1 1 ms 100 bytes 2 111 0.1 sec 11 kb 4 11,111 11 sec 1mb 6 10^6 18 min 111 mb 8 10^8 31 hrs 11 gb 10 10^10 128 days 1 tb 12 10^12 35 years 111 tb 14 10^14 3500 years 11,111 tb
  • 29.
    Depth-First Search • Selectthe terminal node with maximum depth. Break ties randomly • Travels the search space down • Best implemented using a stack
  • 30.
    Depth-First Search Example Finda route from A to G A B C D E F G
  • 31.
    Depth-First Example Cont. •Do search tree trace – States expanded: A, B, D, E, C, F, G – Solution A, C, G • Tracing using OPEN (stack) and CLOSED lists OPEN CLOSD A - B, C // or C,B A D, E, C A, B E, C A, B, D C A, B, D, E F, G A, B, D, E, C G A, B, D, E, C, F - A, B, D, E, C, F, G
  • 32.
    Depth-First search Algorithm DepthFirst search Algorithm Repeated states are not allowed 1. create a list of nodes called OPEN containing one node representing the initial state of the problem. 2. create an empty list of nodes called CLOSED. 3. while (OPEN is not empty) do { 3.1. N=first node in OPEN. 3.2 Delete N from OPEN. 3.3 add N to CLOSED. 3.4 if N contains a goal state return N and the solution. 3.5. E= expand(N). // E is the set of states that result from applying the //operators to the state inside N 3.6 for every state i in E do if (i is not neither in any OPEN node nor in any CLOSED node) Create a node for i and add it at the front of OPEN; // i should point to N which is on the CLOSED list }//while 4. return failure.
  • 33.
    Depth-First Evaluation • DFSis not complete; can go into an infinite section of search space missing goal • Depth-First is not also complete when states are repeated: A G B C States expanded: A, B, C, A, B, C, …
  • 34.
    Depth-First Evaluation Cont. DFSis not optimal S G A 5 1 1
  • 35.
    Depth-First Evaluation Cont. •Number of nodes expanded (worst case) is 1+b+b^2+b^3+…+b^d • Time complexity is O(b^d) • Space complexity (OPEN+CLOSED size) is O(b^d) • When states are not repeated and path to the goal is not needed, space complexity is O(b.d)
  • 36.
    Uniform Cost Search •Search Strategy: select the terminal node form OPEN that has minimum cost. Break ties randomly • Implemented by avoiding repeated states. Keep the node that has lower cost
  • 37.
  • 38.
    Implementation • Use twolists OPEN, CLOSED • OPEN is a minimum heap. Key is cost. • Previous example
  • 39.
    Evaluation • Uniform isboth complete and optimal provided that the search space has no loop with a total negative cost. • Example S A B G 2 3 -8 11
  • 40.
    Memory and Time •Branching factor = b • Goal at depth = d • Operators have all equal cost • Uniform works as breadth and worst case memory and time complexities are O(b^d)
  • 41.
    Informed Search Methods •Search strategy is based on states evaluation • States are evaluated using a heuristic • A heuristic estimates the cost of reaching the goal from state • A heuristic is represented by a function h:state  number • h(goal)=0
  • 42.
    Example: 8-puzzle Cont •h1 = # of tiles in the wrong location. h1 is between 0 and 8 • Example Goal X Y • Problem: although Y is much better than X, h1 assigns both X and Y an equal value 2 1 2 3 4 5 6 7 8 8 2 3 4 5 6 7 1 1 2 3 4 5 6 7 8
  • 43.
    Example: 8-puzzle, cont. •h2 = sum of Manhattan distances of tiles from correct location. Manhattan distance is minimum number of moves between locations • Example Goal X Y • Problem: h2 gives a good evaluation for adjacent tiles that need to be exchanged. h2(X)=2 and h2(Y)=2 • h3=h1+ w*number of adjacent pairs when exchanged become in correct locations 1 2 3 4 5 6 7 8 4 2 3 1 5 6 7 8 1 2 3 4 5 6 7 8
  • 44.
    Example: Missionaries and Canibals •h= # of persons on the left side of the river • Initial: mmmcccb,- h=6 Goal: -,mmmcccb h=0 cb,mmmcc h=1
  • 45.
    Route Finding • Short-linedistance heuristic • h(s)=short-line distance between s and goal • h(s)=0
  • 46.
    Best-First search • Selectthe terminal node from OPEN that has minimum h value. Break ties randomly • Example S H A D C E B F G
  • 47.
    Exercize 3-puzzle initial goal h =sum of Manhatten Distances 3 2 1 1 2 3
  • 48.
    Algorithm Best First searchAlgorithm Repeated states are not allowed // The algorithm is capable of finding the path to the goal state Steps: 1. create a list of nodes called OPEN containing one node representing the initial state of the problem. Compute h value for the node. 2. create an empty list of nodes called CLOSED. 3. while (OPEN is not empty) do { 3.1. N=the node in OPEN having best h value. 3.2. Delete N from OPEN; 3.3 add N to CLOSED. 3.4 if N contains a goal state return N and the solution. 3.5. E=expand(N); // E is the set of states that result from applying the operators to the state inside N 3.6. for every state i in E do{ compute h(i); if (i is not neither in any OPEN node nor in any CLOSED node){ Create a node for i and add it to OPEN; Make i point to N which is on the CLOSED list; }//if }//for }//while 4. return failure.
  • 49.
    Evaluation • Not complete.Can go through an infinite search space in which all the nodes have a better heuristic than the node at the other branch leading to the goal • The algorithm might not also be complete when states are repeated S A B C
  • 50.
    Evaluation Cont • Notoptimal • In the worst case the algorithm works similar to breadth first search; h always 1. Worst case time and memory complexities is O(b^d). • Performance largely dependent on heuristic quality
  • 51.
    A* Search • Searchstrategy is based on: f(n)=g(n)+h(n), where g(n)=the cost of the path from initial state to n h(n)=estimate of the cost of the path from n to goal • f(n)=an estimate of the cost of a solution through n
  • 52.
    Example • Repeated statesare avoided G D S A B 7 1 10 7 1 h=17 h=5 h=9 h=7 h=0
  • 53.
    A* Algorithm 1. CreateOPEN containing one node representing initial state 2. Create CLOSED, empty 3. While (OPEN is not empty){ 3.1 N=node on OPEN that has best f 3.2 delete N from OPEN 3.3 add N to CLOSED 3.4 if (N contains goal) return N 3.5 E=expand(N) 3.6 for every state (i,op) in E do if (i is new) create a new node for i and add it to OPEN else if ((g(N) + cost(op)) < g(oldNode)){ remove oldNode; create a new node for (i,op) and add it to OPEN } }//for }//while 4. Return Failure
  • 54.
    Admissability • A hueristicfunction h is admissable if it never over estimates the actual cost • Shortest-line-distance is admissable • So is SLD-10, sqrt(SLD) • But not SLD+10, SLD^2
  • 55.
    Evaluation A* is completeand optimal if 1.H is admissable 2.Search space has no cycle with a total negative weight
  • 56.
    Example H is notadmissable and A* is not optimal S h=5 A B C D E G 1 1 1 1 1 1 1 h=4 h=3 h=2 h=1 h=0
  • 57.
    Evaluation Cont. • Worstcase time and memory is O(b^d): • H=0 • All operators has equal cost=1 • A* works similar to breadth first search
  • 58.
    Hill-climbing • Based ona heuristic • Follows a single path when searches for a solution • Stops when current state is better than neighboring states
  • 59.
    Algorithm Current=initial-state; E=expand(Current); S=best state inE; while (S is better than Current){ S=Current; E=expand(Current); S=best state in E; } Return Current; //not complete
  • 60.
  • 61.
    Hill-Climbing problems • Hill-climbingscenario • Local maxima problem • Plateau problem • Possible solution: run algorithm multiple times starting from different random initial states and return the best result found.