UNIT - 2:problem Solving: State-Space Search and Control Strategies
UNIT - 2:problem Solving: State-Space Search and Control Strategies
UNIT - 2:problem Solving: State-Space Search and Control Strategies
Production System – PS
It consists of
Production Rules
A control strategy that specifies the order in which the rules will be
applied when several rules match at once.
Advantages of PS
Problem statement:
Solution:
State for this problem can be described as the set of ordered pairs
of integers (X, Y) such that
Production Rules
there are set of rules that describe the actions called production
rules.
Left side of the rules is current state and right side describes
new state that results from applying the rule.
Specify one or more states within that space that describe possible
situations from which the problem solving process may start.
These states are called initial states.
Control Strategy decides which rule to apply next during the process of
searching for a solution to a problem.
Consider 5 cities.
The problem is to find the shortest route for the salesman who has
to
Explore the search tree of all possible paths and return the shortest
path.
How should they use this boat to cross the river in such a way that
cannibals never outnumber missionaries on either side of the
river? If the cannibals ever outnumber the missionaries (on either
bank) then the missionaries will be eaten. How can they all cross
over without anyone being eaten?
PS for this problem can be described as the set of ordered pairs of left
and right bank of the river as (L, R) where each bank is represented as a
list [nM, mC, B]
In this method also problem is viewed as finding a path from start state
to goal state.
Problem Statement:
Solving this problem involves arranging tiles in the goal state from
the start state.
Start state Goal state
3 7 6 5 3 6
5 1 2 7 2
4 8 4 1 8
The start state could be represented as: [ [3,7,2], [5,1, 2], [4,0,6] ]
The operators can be thought of moving {up, down, left, right}, the direction in
which blank space effectively moves.
Initial State
3 7 6
5 1 2
6 8
up left right
3 7 6 3 7 6 3 7 6
5 2 5 1 2 5 1 2
6 1 8 6 8 6 8
up left right
3 6 3 7 6 3 7 6
5 7 2 5 2 5 2
6 1 8 6 1 8 6 1 8
Problem can have more than one intermediate states between start and
goal states.
All possible states of the problem taken together are said to form
a state space or
It is a control strategy that starts with known facts and works towards a
conclusion.
For example in 8 puzzle problem, we start from initial state to goal state.
In this case we begin building a tree of move sequences with initial state
as the root of the tree.
Generate the next level of the tree by finding all rules whose left
sides match with root and use their right side to create the new
state.
Language OPS5 uses forward reasoning rules. Rules are expressed in the
form of “if-then rule”.
Find out those sub-goals which could generate the given goal.
It is a goal directed control strategy that begins with the final goal.
Continue to work backward, generating more sub goals that must also be
satisfied in order to satisfy main goal.
It expands all the states one step away from the initial state, then
expands all states two steps from initial state, then three steps
etc., until a goal state is reached.
All nodes at the same level are searched before going to the next
level down.
Algorithm (BFS)
Output: Yes or No
Method:
• Initially OPEN list contains a START node and CLOSED list is empty;
Found = false;
Do {
} } /* end while */
Depth-First Search
So only path of nodes from the initial node to the current node is stored
in order to execute the algorithm.
For implementation, two lists called OPEN and CLOSED with the same
conventions explained earlier are maintained.
Algorithms (DFS)
Method:
Form a stack consisting of (START, nil) and call it OPEN list. Initially set
CLOSED list as empty; Found = false;
Else
If Found = true then return the plan used /* find it by tracing through
the pointers on the CLOSED list */ else return No
Stop
Comparisons
DFS
is effective when there are few sub trees in the search tree
that have only one connection point to the rest of the states.
can be dangerous when the path closer to the START and farther
from the GOAL has been chosen.
Is best when the GOAL exists in the lower left portion of the search
tree.
BFS
Advantages:
It takes advantages of both the strategies (BFS & DFS) and suffers
neither the drawbacks of BFS nor of DFS on trees
Disadvantages:
Heuristic Search
In many AI problems,
In AI approaches,
There are at least two reasons for the adhoc approaches in AI.
Function g(X) assigns some cumulative expense to the path from Start
node to X by applying the sequence of operators .
During search process there are many incomplete paths contending for
further consideration.
The shortest one is extended one level, creating as many new incomplete
paths as there are branches.
These new paths along with old ones are sorted on the values of function
g.
Since the shortest path is always chosen for extension, the path first
reaching to the destination is certain to be nearly optimal.
Termination Condition:
Hill Climbing- (Quality Measurement turns DFS into Hill climbing (Variant
of generate and test strategy)
Start
End
Straight line (as the crow flies) distance between two cities may be
a heuristic measure of remaining distance in traveling salesman
problem .
Remove the top element from OPEN list and call it NODE;
If NODE is the goal node, then Found = true else find SUCCs, of
NODE, if any, and sort SUCCs by estimated cost from NODE to
goal state and add them to the front of OPEN list.
} /* end while */
Stop
There might be a position that is not a solution but from there no move
improves situations?
Here make a big jump to some direction and try to get to new
section of the search space.
Here apply two or more rules before doing the test i.e., moving
in several directions at once.
It moves downward from the best W nodes only at each level. Other
nodes are ignored.
W is called width of beam search.
Best nodes are decided on the heuristic cost associated with the node.
If B is the branching factor, then there will be only W*B nodes under
consideration at any depth but only W nodes will be selected.
Found = false;
NODE = Root_node;
If NODE is the goal node, then Found = true else find SUCCs of NODE, if
any with its estimated cost and store in OPEN list;
Select top W elements from OPEN list and put it in W_OPEN list
and empty OPEN list;
} // end while
} // end while
Here forward motion is carried out from the best open node so far in the
entire partially developed tree.
Found = false;
If the first element is the goal node, then Found = true else remove
it from OPEN list and put it in CLOSED list.
Sort the entire list by the value of some heuristic function that
assigns to each node, the estimate to reach to the goal node
} /* end while */
If the Found = true, then announce the success else announce failure.
Stop.
Observations
Termination Condition
2.5.6. A* Method
The function g is a measure of the cost of getting from the Start node
(initial state) to the current node.
It is sum of costs of applying the rules that were applied along the
best path to the current node.
Algorithm (A*)
Remove the node with the lowest value of f from OPEN to CLOSED
and call it as a Best_Node.
} /* for loop*/
} /* else if */
} /* End while */
If Found = true then report the best path else report failure
Stop
Behavior of A* Algorithm
Underestimation
Here h is underestimated
A
Underestimated
(1+3)B (1+4)C (1+5)D
Then we go back and try another path, and will find optimal path.
A
Overestimated
(2+2) E
(3+1)F
(4+0) G
A is expanded to B, C and D.
Thus, we may find some other worse solution without ever expanding D.
Admissibility of A*:
Alternatively we can say that A* always terminates with the optimal path
in case
Monotonicity
h (goal) = 0
that search space which is every where locally consistent with heuristic
function employed i.e., reaching each state along the shortest path from
its ancestors.
3 7 6 5 3 6
5 1 2 7 2
4 8 4 1 8
3 7 6 5 3 6
5 1 2 7 2
4 8 4 1 8
f(initial_node) = 4
Start State
Search Tree f = 0+4
3 7 6
5 1 2
4 8
up left right
(1+3) (1+5) (1+5)
3 7 6 3 7 6 3 7 6
5 2 5 1 2 5 1 2
4 1 8 4 8 4 8
up left right
(2+3) (2+3) (2+4)
3 6 3 7 6 3 7 6
5 7 2 5 2 5 2
4 1 8 4 1 8 4 1 8
left right
(3+2) (3+4)
3 6 3 6
5 7 2 5 7 2
4 1 8 4 1 8
down
(4+1)
5 3 6 right 5 3 6 Goal
7 2 7 2 State
4 1 8 4 1 8
up left right
(1+3) (1+5) (1+5)
3 7 6 3 7 6 3 7 6
5 2 5 1 2 5 1 2
4 1 8 4 8 4 8
Harder Problem
IDA* Algorithm
At each iteration, perform a DFS cutting off a branch when its total cost
(g+h) exceeds a given threshold.
This threshold starts at the estimate of the cost of the initial state, and
increases for each iteration of the algorithm.
At each iteration, the threshold used for the next iteration is the
minimum cost of all values exceeded the current threshold.
O O O OO 6
8 4 89
O O
O O O O O O
7 5 9 8 4 7
O O
O O O
O O O O O O Goal
8 9 4 4 8
Crypt-Arithmetic puzzles.
Map colouring: Given a map, colour three regions in blue, red and
black, such that no two neighbouring regions have the same
colour.
They can be solved using any of the search strategies which can be augmented
with the list of constraints that change as parts of the problem are solved.
Algorithm:
Until a complete solution is found or all paths have lead to dead ends
Problem Statement:
S E N D
+ M O R E
M O N E Y
S = ? ; E = ? ;N = ? ; D = ? ; M = ? ;O = ? ; R = ? ;Y = ?
Carries :
C4 = ? ; C3 = ? ; C2 = ? ; C1 = ?
C4 C3 C2 C1 Carry
S E N D
+ M O R E
M O N E Y
Constraint equations:
Y= D+E C1
E = N + R + C1 C2
N = E + O + C2 C3
O = S + M + C3 C4
M = C4
We can easily see that M has to be non zero digit, so the value of C4 =1
1. M = C4 M=1
2. O = S + M + C3 C4
If C3 = 0, then S = 9 else if C3 = 1,
then S = 8 or 9.
C3 = 0 or 1
It can be easily seen that C3 = 1 is not possible as O = S + M + C3
O = 11 O has to be assigned digit 1 but 1 is already assigned
to M, so not possible.
Therefore, O = 0
M = 1, O = 0
C4 C3 C2 C1 Carry
S E N D
+ M O R E
M O N E Y
Y= D+E C1
E = N + R + C1 C2
N = E + O + C2 C3
O = S + M + C3 C4
M = C4
As O = 0, N = E + C2 .
Since N E, therefore, C2 = 1.
Hence N = E + 1
If E = 2, then N = 3.
If C1 = 1 then R = 8, then
From Y = D + E , we get 10 + Y= D + 2 .
C4 C3 C2 C1 Carry
S E N D
+ M O R E
M O N E Y
Y= D+E C1
E = N + R + C1 C2
N = E + O + C2 C3
O = S + M + C3 C4
M = C4
If E = 5, then N = 6
If C1 = 1 then R = 8, then
S=9;E=5;N=6;D=7;
M = 1 ; O = 0 ; R = 8 ;Y = 2
Constraints:
Y= D+E C1
E = N + R + C1 C2
N = E + O + C2 C3
O = S + M + C3 C4
M = C4
Initial State
M=1 C4 = 1
O = 1 + S + C3
O
S=9 S=8
O
C3 = 0 C3 = 1
O=0 O=1
Fixed
M=1
O=0
N = E + O + C2 = E + C2 C2 = 1 (must) N = E + 1
N=3 N=6
E = N + R + C1 E = N + R + C1
10 + 2 = 3 + R + C1 10 + 5 = 6 + R + C1
O O
R=9 R=8 R=9 R=8
C1 C1 = 1 C1 = 0 C1 = 1
=0
O O
10 + Y = D + E = D + 2 10 + Y = D + E = D + 5
O O
D=8 D=9 D=7
Y=0 Y=1 Y=2
M = 1, O = 0, S = 9, E = 5, N = 6, R = 8, D = 7, Y = 2
C4 C3 C2 C1 Carries
B A S E
+ B A L L
G A M E S
Constraints equations are:
E+L=S C1
S + L + C1= E C2
2A + C2 = M C3
2B + C3 = A C4
G = C4
G = ?; A = ?;M = ?; E = ?; S = ?; B = ?; L = ?
1. G = C4 G = 1
2. 2B+ C3 = A C4
2.1 Since C4 = 1, therefore, 2B+ C3 > 9 B can take values from 5 to 9.
2.2 Try the following steps for each value of B from 5 to 9 till we get a
possible value of B.
if C3 = 0 A = 0 M = 0 for C2 = 0 or M = 1 for C2 = 1
If B = 5
if C3 = 1 A = 1 (as G = 1 already)
For B = 6 we get similar contradiction while generating the search tree.
If B = 7 A=4
, then for C3 = 0, we get M = 8 if C2 = 0 that leads to
contradiction, so this path is pruned. If C2 = 1, then M = 9 .
3. Let us solve S + L + C1 = E and E + L = S
Using both equations, we get 2L + C1 = 0 L=5
and C1 = 0
Using L = 5, we get S + 5 = E that should generate carry C2 = 1 as shown
above
So S+5 > 9 Possible values for E are {2, 3, 6, 8} (with carry bit C2 = 1 )
If E = 2 then S + 5 = 12 S = 7 (as B = 7 already)
If E = 3 then S + 5 = 13 S = 8.
Therefore E=3 S=8
and are fixed up.
4. Hence we get the final solution as given below and on backtracking, we may find
more solutions. In this case we get only one solution.
G = 1; A = 4; M = 9; E = 3; S = 8;B = 7; L = 5
2.7. Problem Reduction & Game Playing
2..7.1.Problem Reduction
One AND arc may point to any number of successors, all of which must
be solved.
Such structure is called AND–OR graph rather than simply AND graph.
Acquire TV
AND–OR Graph
In search for AND-OR graph, we will also use the value of heuristic
function f for each node.
Traverse AND-OR graph, starting from the initial node and follow
the current best path.
Accumulate the set of nodes that are on the best path which have not yet
been expanded.
Add its successors to the graph and compute f (using only h) for each of
them.
Mark the best path which could be different from the current best path.
Let us assume that each arc with single successor will have a cost
of 1 and each AND arc with multiple successor will have a cost of 1
for each of its components for the sake of simplicity.
A
(20) (19) initially estimated values
Initially we start from start node A and compute heuristic values for
each of its successors, say {B, (C and D)} as {19, (8, 9)}.
The estimated cost of paths from A to B is 20 (19 + cost of one arc from A
to B) and from A to (C and D) path is 19 ( 8+9 + cost of two arcs A to C
and A to D).
The path from A to (C and D) seems to be better. So expend this AND
path by expending C to {(G and H)} and D to {(I and J)}.
These values are propagated up and the revised costs of path from A
through (C and D) is calculated as 28 (9 + 17 + cost of arcs A to C and A
to D).
This path is still best path so far, so further explore path from A to B.
The process continues until either a solution is found or all paths have
lead to dead ends, indicating that there is no solution.
Cyclic Graph
We can now state precisely the steps taken for performing heuristic
search of an AND-OR graph.
Solved Solved
Solved Solved
2.7.2. AO* Algorithm
Compute h(INIT).
{1
Traverse the graph starting from INIT and follow the current
best path.
Accumulate the set of nodes that are on the path which have not
yet been expanded or labeled as SOLVED.
Select one of these unexpanded nodes. Call it NODE and expand it.
{2
Until S is empty
{3
3}
2}
1}
2 3 4 Unsolvable
5 6
7 8
9 10
Explanation
Now node 10 is expanded at the next step and one of its successors is
node 5.
This new path to 5 is longer than the previous path to 5 going through 3.
But since the path through 3 will only lead to a solution as there is no
solution to 4, so the path through 10 is better.
A (10)
D (3)
E (2) C (5)
Assume that both C and E ultimately lead to a solution.
Looking just at the alternative from D, the path from node E is the best
path but it turns out that C is must anyways, so it is better also to use it
to satisfy D.
But to solve D, the path from node E is the best path and will try to solve
E.
AO* algorithm does not consider such interactions, so it will find a non-optimal
path.
Improve the test procedure so that the best moves (paths) will be
recognized and explored first.
Two-player games are easier to imagine & think and more common to
play.
For example,
The game begins from a specified initial state and ends in position that
can be declared win for one, loss for other or possibly a draw.
Its successors are the positions that the first player can reach in
one move, and
Each non-terminal nodes in the game tree can be labeled WIN, LOSS or
DRAW by a bottom up process similar to the "Solve" labeling
procedure in AND/OR graph.
Let us denote
• MAX X
• MIN Y,
• WIN W,
• DRAW D and
• LOSS L.
The status of the leaf nodes is assigned by the rules of the game
whereas, those of non-terminal nodes are determined by the
labeling procedure.
Solving a game tree means labeling the root node by WIN, LOSS,
or DRAW from Max player point of view.
MAX X (W)
For most of the games, tree of possibilities is far too large to be generated
and evaluated backward from the terminal nodes in order to determine
the optimal first move.
Examples:
Evaluation Function
E F G H I J K
(9) (-6) (0) (3) (2) (-4) (-3)