Module 1 Reference
Module 1 Reference
Module1 :
Syllabus: Problems, Problem Spaces and search,
Heuristic search technique (TextBook1: Ch 1, 2
and 3)
Problems, Problem Space and Search
To build a system to solve a particular problem we need
to do four things:
0 0 Initial State
0 3 2
3 0 9
3 3 2
4 2 7
0 2 5 or 12
2 0 9 or 11
Production System
• A production system (or production rule system)
is a computer program typically used to provide
some form of artificial intelligence, which consists
primarily of a set of rules about behavior.
• These rules, termed productions, are a basic
representation found useful in automated
planning, expert systems and action selection.
• A production system provides the mechanism
necessary to execute productions in order to
achieve some goal for the system.
S1→A1
S2→A2
Working Memory Pattern S3→A3
S4→A4
-----------
Pattern → Action
----------
Sn→An
The major components of an AI
production system are
i. A Global database:
ii. A Set of production rules:
iii. A Control system/Strategy:
iv . Rule Applier :
Four classes of production systems:-
(0,0)
(4,0) (0,3)
Now for Each leaf node generate all its successors by
applying all the rules that are appropriate. The tree at this
point is shown in Figure below :
(0,0)
(4,0) (0,3)
b. For Each way that each rule can match the state described in E do
I. Apply the rule to generate a new state
II. If the new state is a goal state , quit and return this state
III. Otherwise add the new state to end of NODE_LIST
(0,0)
(0,0)
(4,0) (0,3)
(4,0) (0,3)
(4,3) (0,0) (1,3) (4,3) (0,0) (3,0)
Advantages of BFS
• The breadth first search is not caught in a blind alley. This
means that, it will not follow a single unfruitful path for
very long time or forever, before the path actually
terminates in a state that has no successors. In DFS may
follow single unfruitful path for a very long time.
• In the situations where solution exists, the breadth first
search is guaranteed to find it. Besides this, in the
situations where there are multiple solutions, the BFS finds
the minimal solution. The minimal solution is one that
requires the minimum number of steps. In contrast DFS
may find a long path to a solution in one part of the tree ,
when a shorter path exists in some other , unexplored part
of the tree.
Depth First Search
• Expand one of the nodes at the deepest level.
Water Jug Problem Solution using DFS
(0,0)
(4,0) (0,3)
(4,0) (0,3)
(1,3)
(1,0)
(0,1)
(4,1)
(2,3)
GOAL
Depth first search Algorithm
on(B, table)
on(C, table)
on(A, table)
on(B, C)
on(C, A)
on(A, B)
clear(C)
clear(A)
clear(B)
2. Can the solution step be ignored or not
• In mathematical theorem proving the solution steps
can be ignore. In bridge or chess the solution steps
are not ignorable. Also they are not recoverable. But
in 8 puzzle problem the solution steps are
recoverable.
• Classes of problems
– Ignorable ( Eg: Theorem Proving ) in which solution steps
can be ignored
– Recoverable (Eg: 8 Puzzle ) in which solution steps can be
undone
– Irrecoverable (Eg: Chess) in which solution steps cannot
be undone.
3. Is the Universe Predictable
• Predictable : In 8 puzzle every time we make a
move we know exactly what will happen , this
means that it is possible to plan an entire
sequence of moves and be confident that we
know what the resulting state will be .
(The Universe Out come is Certain)
• Un Predictable : In Playing Bridge , We Cannot
know exactly where all
the cards are or what the other players will do
on their turn. (Uncertain outcome)
4. Is a good solution absolute or relative?
•Any‐path problems can be solved using heuristics that suggest good paths to explore.
•For best‐path problems, much more exhaustive search will be performed
5.Is the solution a state or a path?
1. Generate‐and‐test
2. Hill climbing
3. Best‐first search
4. Problem reduction
5. Constraint satisfaction
6. Means‐ends analysis
1. Generate‐and‐Test
Algorithm
1. Generate a possible solution.
2. Test to see if this is actually a solution by
comparing to the set of acceptable goal states.
3. If a solution has been found, quit.
Otherwise, return to step 1.
Generate-And-Test
2017/8/27 EIE426-AICV 51
Generate‐and‐Test
53
TSP Example
A 6 B
1 2
5 3
D 4 C
54
Generate-and-test Example
cities:
1. A - B - C - D B C D
2. A - B - D - C
3. A - C - B - D
C D B D C B
4. A - C - D - B
...
D C D B B C
55
2.Hill Climbing
• Hill Climbing is a variant of generate and test in
which feedback from the test procedure is used
to help the generator decide which direction to
move in the search space.
• Following are the different types of Hill Climbing
algorithm.
1. Simple Hill Climbing
2. Steepest Ascent Hill Climbing
3. Simulated Healing
2.1 Simple Hill Climbing
– Use heuristic to move only to states that are better than the current state.
– Always move to better state when possible.
– The process ends when all operators have been applied and none of the resulting states are better
than the current state
The simplest way to implement hill climbing is as follows.
I. Evaluate the initial state. If it is also a goal state, then return it and quit. Otherwise,
continue with the initial state as the current state.
2. Loop until a solution is found or until there are no new operators left to be applied in
the current state:
(a) Select an operator that has not yet been applied to the current state and apply it to
produce a new state.
(b) Evaluate the new state.
(i) If it is a goal state, then return it and quit.
(ii) If it is not a goal state but it is better than the current state, then make it the
current state.
(iii) If it is not better than the current state, then continue in the loop.
2.2 Steepest-Ascent Hill Climbing
• A variation on simple hill climbing.
• Instead of moving to the first state that is better,
move to the best possible state that is one move
away.
• The order of operators does not matter.
• Not just climbing to a better state, climbing up
the steepest slope.
2.2 Steepest-Ascent Hill Climbing
(Gradient Search)
Algorithm: Steepest-Ascent Hill Climbing
1. Evaluate the initial state. If it is also a goal state, then return it and quit.
Otherwise, continue with the initial state as the current state.
2. Loop until a solution is found or until a complete iteration produces no change to
current state:
(a) Let SUCCESSOR (S ) be a state such that any possible successor of the current
state (CS) will be better than S.
(b) For each operator that applies to the current state do:
(i) Apply the operator and generate a new state (NS).
(ii) Evaluate the new state. If it is a goal state, then return it and quit. If not,
compare it to S. If it is better, then set S to this state. If it is not better,
leave S alone.
(c) If the S is better than CS, then set CS to S.
Problems with hill
climbing
1. Local maximum, or
the foothill problem:
there is a peak, but it is
lower than the highest
peak in the whole
space. Solutions to Problem
2. The plateau problem: • Backtrack to some earlier node and
all local moves are try going in a different direction
equally unpromising,
and all peaks seem far • Make a big jump in some direction
to try to get to a new section of the
away. search space.
3. The ridge problem: • Apply two or more rules before
almost every move doing the test. This corresponds to
takes us down. moving in several directions at once.
2.3 Simulated Annealing
• Physical Annealing : Physical substances are
melted and then gradually cooled until some
solid state is reached. The goal is to produce a
minimal-energy state.
• Annealing schedule: If the temperature is
lowered sufficiently slowly, then the goal will be
attained.
• The probability for a transition to a higher energy
state: e-E/kT.
61
Simulated Annealing Algorithm
1. Evaluate the initial state. If it is a goal state , then return it and quit. Otherwise
set initial state as the current state.
2. Initialize BEST SO FAR to the current state.
3. Initialize T according to the annealing schedule.
4. Loop until a solution is found or there are no new operators left to be applied:
a. Select and applies a new operator which has not yet applied .
b. Evaluate the new state:
- If the new state is goal state , then return it and quit.
- If it is not a goal state and better than the current state then make
it as the current state. Also set BEST–So- FAR to this new state.
- If it is not better than the current state, then
Compute E = Val(current state) - Val(new state) make it the
current state with probability P = e-E/kT
c. Revise T as necessary according to the annealing schedule
5. Return BEST –So-FAR as the answer.
62
3 Best First Search
• At each step of the best-first search process, we
select the most promising of the nodes we have
generated so far.
– This is done by applying an appropriate heuristic
function to each of them.
– We then expand the chosen node by using the rules to
generate its successors.
• If one of them is a solution, we can quit.
• If not, all those new nodes are added to the set of nodes
generated so far.
• Again the most promising node is selected and the process
continues
Best First Search Algorithm
65
A* Algorithm
1. Start with OPEN holding the initial nodes.
2. Pick the BEST node on OPEN such that
f(n) = g(n) + h(n) is minimal.
3. If BEST is goal node quit and return the path
from initial to BEST Otherwise
4. Remove BEST from OPEN and all of BEST's
children, labeling each with its path from
initial node.
Advantages
• It is complete and optimal.
• It is the best one from other techniques.
• It is used to solve very complex problems.
• It is optimally efficient, i.e. there is no
other optimal algorithm guaranteed to
expand fewer nodes than A*.
Disadvantages
• This algorithm is complete if the branching
factor is finite and every action has fixed cost.
• The speed execution of A* search is highly
dependant on the accuracy of the heuristic
algorithm that is used to compute h (n).
• It has complexity problems.
The A* procedure
A simple search problem: S is the start node, G is the goal
node, the real distances are shown.
4 4
A B C
3
S 5 5
4 G
3.5
D 2 E 4
F
A lower-bound estimate of the straight line distance to G could be as follows (note that
we do not need it for F): City Straight Line Distance to Goal
City (h(n))
A B 5.8 C S 11.5
10.1 3.4 A 10.1
S B 5.8
11.5 G
9.2 C 3.4
3.5 D 9.2
D E 7.1 F
E 7.1
F 3.5
G 0
Hill-climbing happens to
succeed here:
S
4 4
A B C 10.1 9.2
3
S 5 5 A D
4 G
3.5
2 4 10.1
D E F 11.5 7.1
A S E
City Straight Line Distance to Goal City (h(n))
S 11.5
5.8 9.2 3.5
A 10.1 B D F
B 5.8
C 3.4 7.1 0.0
D 9.2
E 7.1 E G
F 3.5
G 0
A*, step 1 The A* procedure
S
f(n) = h(n) + g(n)
3+10.1 4+9.2
4 4 A D
A B C
3
S 5 5
4 G
3.5 City Straight Line Distance to Goal
D 2 E 4
F City (h(n))
S 11.5
A 10.1
B 5.8
C 3.4
D 9.2
E 7.1
F 3.5
G 0
A*, step 2 The A* procedure
S f(n) = h(n) + g(n)
13.1 13.2
A D
4 4 3+4+5.8 3+5+9.2
A B C
3
B D
S 5 5
4 G
3.5
D 2 E 4
F
12.8 17.2
City Straight Line Distance to Goal
City (h(n))
B D
S 11.5
A 10.1 3+4+4+3.4 3+4+5+7.1
B 5.8
C 3.4 C E
D 9.2
E 7.1
F 3.5
G 0
A*, step 4
The A* procedure
f(n) = h(n) + g(n)
4 4
A B C
3
S
S 5 5
4 G 13.1 13.2
3.5
D 2 E 4
F
A D
4 4 S
A B C
3 13.1 13.2
S 5 5
4 G
3.5 A D
D 2 E 4
F 12.8 17.2 19.1
B D A
City Straight Line Distance to Goal
City (h(n)) 14.4 19.1 13.1
S 11.5
A 10.1 C E E
B 5.8
C 3.4 16.8 13.5
D 9.2
E 7.1 B F
F 3.5
G 0
G
4. Problem Reduction
• In problem reduction, a complex
problem is broken down or decomposed
into a set of primitive sub problem;
solutions for these primitive sub-
problems are easily obtained. The
solutions for all the sub problems
collectively give the solution for the
complex problem
• The problem Reduction technique can be
represented using AndOR Graph.
The Problem-Reduction (Goal Reduction) Method
2017/8/27 78
A Decomposable Problem
2017/8/27 EIE426-AICV 79
Problem Reduction
Goal: Steal TV set Goal: Earn some money Goal: Buy TV set
AND-OR Graphs
80
Problem Reduction
• To represent problem reduction techniques we
need to use an AND-OR graph/tree
• AND NODES successors must all be achieved,.
• OR NODES where one of the successors must be
achieved (i.e., they are alternatives).
• This decomposition or reduction, generates arcs
that we call AND arcs.
• One AND arc may point to a number of successor
nodes, all of which must be solved in order for the
arc to point to a solution.
Problem Reduction Algorithm using
AndOR Graphs /AO* Algorithm
1. Start with initial node say N
2. Expand the node with all possible successors say Ns1,Ns2,Ns3,---
Nsn each representing the simple sub solutions.
3. Categorize the Successors into AND Node successors and OR
Node Successors.
4. Estimate the Objective function f(N) w.r.t all solvable nodes of OR
Node and AND Node successors.
1. For AND Node f(N)) = [ f(Nsi) + c(N, Nsi) ]
2. For OR Node f(N) = min { f(Nsi) + c(N,Nsi) } where Nsi
represents successor of N
5. Select the optimal successor which have solution .
6. Repeat the Steps from 2 for selected optimal successor until the
goal is reached.
Problem Reduction: AO*
Example 1
A A 6
5 9
B C D
3 4 5
A 9 A 11
9 12
B C D 10 B 6 C D 10
3 4 4
E F G H E F
4 4 5 7 4 4
83
Problem Reduction: AO*
Example 2
A 11 A 14
B 13 C 10 B 13 C 15
D 5 E 6 F 3 D 5 E 6 F 3
G 5 G 10
84
Advantages Disadvantages
• It is an optimal algorithm. • Sometimes for
unsolvable nodes, it
• If traverse according to can’t find the optimal
the ordering of nodes. path.
• It can be used for both OR • Its complexity is more
and AND graph. than other algorithms.
Difference between A* and AO*
Algorithm
• A* algorithm is a OR graph algorithm and
• AO* is a AND-OR graph algorithm.
• In OR graph algorithm it just find only one
solution
• But in the AND-OR graph algorithm it
finds more than one solution by ANDing
two or more branches.
5.Constraint Satisfaction Problem
Solution
FORTY 29786
F=2, O=9
+ TEN + 850 R=7, T=8
+ TEN + 850 Y=6, E=5
S I XTY 31486 N=0, I=1
X=4
• State space: All letters and all numbers assigned to the letters
• Operations: replace all occurrences of a letter with a digit not
already there
• Initial State: Letters that make words, integers
• Goal State: only digits, sum is correct
• Solution:
Example
Step 1: Here Y+N+N = Y ;
FORTY So N is either 0 or 5 Also , T + E + E = T;
So E is either 0 or 5 , Also E is 5 and N is 0.
+ TEN So c1 = 0 , c2 = 1
+ TEN
Step2 : 1+ R+T+T = X with a carry c3 and c3 =2
S I XTY O+2 = I
Here , O must be a higher number
O = 9 and I = 1
I+F=S
29786 T and R must be higher numbers
+ 850 Then only we get a carry c3 = 2
So T = 8 and R = 7
+ 850
31486 Step3: Just Assume F = 2 , Then S= 3
Other Examples
SEND 8542 9567
+ MORE + 0915 + 1085
MONEY 09457 10652
DONALD 526485
+ G E R A LD + 1 9 7485
RO B ERT 7 2 3970
CROSS 96233
+ ROADS + 62513
DANGER 158746
Example: Map-Coloring
2017/8/27 EIE426-AICV 97
A Robot’s Operators
Operator Preconditions Results
PUSH(obj, loc) at(robot,obj)^ at(obj, loc)^
large(obj)^ at(robot, loc)
clear(obj)^
armempty
CARRY(obj, loc) at(robot,obj) ^ at(obj, loc)^
small(obj) at(robot, loc)
2017/8/27 EIE426-AICV 98
A Difference Table
Operators
differences
99
The Progress of the Means-Ends Analysis Method
2017/8/27
Algorithm: Means-Ends Analysis
(CURRENT, GOAL)
1. Compare CURRENT with GOAL. If there are no differences between
them then return.
2. Otherwise, select the most important difference and reduce it
doing the following until success or failure is signaled:
a. Select an as yet untried operator O that is applicable to the current
difference. If there are no such operators, then signal failure.
b. Attempt to apply O to CURRENT. Generate descriptions of two states:
O-START, a state in which O's preconditions are satisfied and ORESULT,
the state that would result if O were applied in O-START.
c. If (FIRST-PART <- MEA (CURRENT, O-START)) and (LAST-PART <- MEA
(O-RESULT, GOAL)) are successful, then signal success and return the
result of concatenating FIRST-PART,O, and LAST-PART.
Problem-Reduction and Mean End Analysis
PolyU Bejing U
PolyU HK Airport
Problem reduction
2017/8/27
History of AI