Professional Documents
Culture Documents
Module-1
Chapter 2 & 3
AI/JB/ISE/SIT/2019-20
Problems, Problem Space and Search
To build a system to solve a particular problem we need
to do four things:
AI/JB/ISE/SIT/2019-20
Example 2: A Water Jug Problem :
You are given two jugs a 4 Gallon Jug one and
3 Gallon Jug one .Neither has any measuring
markers on it. There is a pump that can be
used to fill the jugs with water. How can you
get exactly 2 Gallon of Water into the 4 Gallon
Jug .
AI/JB/ISE/SIT/2019-20
Solution
• State Space: The state space for this problem can
be described as the set of ordered pairs of
integers (x, y). Where
– x represents the number of Gallons of water in the 4
Gallon Jug , such that x = 0,1,2,3 or 4
– y represent the quantity of water in the 3 gallon jug ,
such that y = 0, 1, 2 or 3.
• Initial State : The Start State is (0,0)
• Goal State : The Final State is (2,n)
• Rules : The Production rule for the Water Jug
Problem is given below :
AI/JB/ISE/SIT/2019-20
Rule Rule Descriptions
#
1 (x,y) if x<4 →(4,y) Fill the 4 Gallon Jug
2 (x,y) if y<3 → (x,3) Fill the 3 Gallon Jug
3 (x,y) if x>0 → (x-d,y) Pour Some Water out of 4 Gallon Jug
4 (x,y) if y>0 → (x,y-d) Pour Some Water out of 3 Gallon Jug
5 (x,y) if x>0 → (0,y) Empty the 4 Gallon Jug on the Ground
6 (x,y) if y>0 → (x,0) Empty the 3 Gallon Jug on the Ground
7 (x,y) if x+y ≥ 4 and y>0 → (4,(y-(4-x)) Pour the water from the 3 Gallon Jug into
the 4 Gallon Jug until the 4 Gallon Jug is full
8 (x,y) if x+y ≥3 and x>0 → (x- (3-y),3) Pour water from the 4 Gallon jug into the 3
Gallon jug until the 3 Gallon jug is full
9 (x,y) if x+y ≤ 4 and y>0 → (x+y,0) Pour all the water from the water from the 3
Gallon jug into the 4 Gallon jug.
10 (x,y) if x+y ≤3 and x>0 → (0,x+y) Pour all the water from the 4 G jug into the 3
Gallon jug
11 (0,2) → (2,0 ) Pour the 2 Gallon water from the 3 Gallon
jug into the 4 Gallon Jug
12 (2,y) → (0,y ) Empty the 2 Gallon water in the 4 Gallon Jug
on the Ground.
AI/JB/ISE/SIT/2019-20
One Solution to the Problem
Gallons in the 4 Gallon Jug Gallons in the 3 Gallon Jug Rule Applied
0 0 Initial State
0 3 2
3 0 9
3 3 2
4 2 7
0 2 5 or 12
2 0 9 or11
AI/JB/ISE/SIT/2019-20
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.
AI/JB/ISE/SIT/2019-20
Production system consists of
•Control Strategy – It specifies the order in which the rules
will be compared to the database and the way of resolving the
conflicts that arise when several rules match at one.
AI/JB/ISE/SIT/2019-20
AI/JB/ISE/SIT/2019-20
Artificial Intelligence
Module1 :
Syllabus: Problems, Problem Spaces and search,
Heuristic search technique (TextBook1: Ch 1, 2
and 3)
AI/JB/ISE/SIT/2019-20
AI/JB/ISE/SIT/2019-20
AI/JB/ISE/SIT/2019-20
Control Strategies
• A control strategy that determines the order in which the rules are applied to
the database, and provides a way of resolving any conflicts that can arise
when several rules match at once.
AI/JB/ISE/SIT/2019-20
Breadth first search Algorithm
1. Create a variable called NODE_LIST and set it to the initial state
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
AI/JB/ISE/SIT/2019-20
Example
• Construct a tree with initial state as its root . Generate all the offspring off the
root by applying each of the applicable rules to the initial state. Figure below
shows how tree looks at this point.
(0,0)
(4,0) (0,3)
AI/JB/ISE/SIT/2019-20
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)
AI/JB/ISE/SIT/2019-20
AI/JB/ISE/SIT/2019-20
Depth first search Algorithm
1. If the initial state is a goal state quit and return success
2. Otherwise do the following until success or failure is
signaled
AI/JB/ISE/SIT/2019-20
Water Jug Problem Solution using DFS
(0,0)
(4,0) (0,3)
(1,3)
(1,0)
(0,1)
(4,1)
(2,3)
GOAL
AI/JB/ISE/SIT/2019-20
Advantages of BFS
• The breadth first search 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.
AI/JB/ISE/SIT/2019-20
Heuristic Search
• A heuristic technique (meaning : “Guide” "find" or "discover"), often
called simply a heuristic, is any approach to problem solving, learning, or
discovery that employs a practical method not guaranteed to be optimal
or perfect, but sufficient for the immediate goals.
E.g. imagine that you are lost in a jungle and you are searching
for road which can lead you to a particular city.
AI/JB/ISE/SIT/2019-20
Following are the problems where
heuristics are applied.
1)Problems for which no exact algorithms are known and one
needs to find an approximation and satisfying solution .
AI/JB/ISE/SIT/2019-20
Example
One example of a good general purpose heuristic is
nearest neighbor heuristic applied to the Travelling
Salesman Problem :
1. Arbitrarily select a starting city
2. To select the next city, look at all cities not yet visited and
select the one closest to the current city. Go to it next
AI/JB/ISE/SIT/2019-20
Heuristic Function
• Is a function that maps from problem state descriptions to
measures of desirability, usually represented as a number.
AI/JB/ISE/SIT/2019-20
1. Is the Problem Decomposable
Decomposable problem can be solved easily. Suppose we
want to solve the problem of computing the expression.
AI/JB/ISE/SIT/2019-20
1. Is the Problem Decomposable
-- At each step it checks to see whether the problem it is
working on is immediately solvable.
-- If so, then the answer is returned directly.
-- If the problem is not easily solvable, the integrator
checks to see whether it can decompose the problem into
smaller problems.
-- It can create those problems and calls itself recursively
on using this technique of problem decomposition we
can often solve very large problem easily.
AI/JB/ISE/SIT/2019-20
Example : Blocks World
A
C B
A B C
GOAL
START
ON(B, TABLE)
ON(C, TABLE)
ON(A, TABLE)
ON(B, C)
ON(C, A)
ON(A, B)
CLEAR(C)
CLEAR(A)
CLEAR(B)
AI/JB/ISE/SIT/2019-20
AI/JB/ISE/SIT/2019-20
2. Can the solution step be ignored or not
• In mathematical theorem proving the solution steps can be ignored.
• In bridge or chess the solution steps are not ignorable. Also they are not
recoverable.
• Classes of problems
AI/JB/ISE/SIT/2019-20
AI/JB/ISE/SIT/2019-20
2. Can the solution step be ignored or not
•The recoverability of a problem plays an important role in
determining the complexity of the control structure necessary for
problem solution.
•Ignorable problems can be solved using a simple control structure
that never backtracks.
•Recoverable problems can be solved by slightly complicated
control strategy that does sometimes make mistakes using
backtracking.
•Irrecoverable problems can be solved by recoverable style methods
via planning that expands a great deal of effort making each
decision since the decisionAI/JB/ISE/SIT/2019-20
is final.
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)
AI/JB/ISE/SIT/2019-20
4. Is a good solution absolute or relative?
Consider the problem of answering question based on a database of
simple facts, such has the following:
1. Marcus was a man.
2.Marcus was a Pompeian.
3.Marcus was born in 40 A.D.
4.All men are mortal.
5.All Pompeian's died when the volcano erupted in 79 A.D.
6.No mortal lives longer than 150 years.
7.It is now 1991 A.D.
AI/JB/ISE/SIT/2019-20
Suppose we ask a question
“ Is Marcus alive? “
Two ways to decide the answer
1 Marcus was a man 1
7 It is now 1991 A.D. 7
4 All men are mortal. 4
All Mortal’s died when the volcano
8 Marcus is a mortal 1,4 5 erupted in 5
3 Marcus was born in 40 A.D. 3 79 A.D.
7 It is now 1991 A.D. 7 11 All Mortal’s are dead now 7,5
9 Marcus age is 1951 years 3,7 2 Marcas was pompeian 2
6 No mortal lives longer than 6
150 years 12 Marcus is dead 11,2
10 Marcus is dead 8,6,9
•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
AI/JB/ISE/SIT/2019-20
5. Is the solution a state or a path?
• For the problem of the natural language understanding the
solution is a state of the world. Consider the problem of
finding a consistent interpretation for the sentence “The bank
president ate a dish of pasta salad with the fork “ .
AI/JB/ISE/SIT/2019-20
6.What is the role of knowledge?
• Is a large amount of knowledge absolutely required to solve the
problem or is knowledge important only to constrain the search.
AI/JB/ISE/SIT/2019-20
Problem Classification
• There is a variety of problem‐solving methods, but there is no one
single way of solving all problems.
AI/JB/ISE/SIT/2019-20
Heuristic Search
1. Generate‐and‐test
2. Hill climbing
3. Best‐first search
4. Problem reduction
5. Constraint satisfaction
6. Means‐ends analysis
AI/JB/ISE/SIT/2019-20
1. Generate‐and‐Test
Algorithm
AI/JB/ISE/SIT/2019-20
Generate-And-Test
2017/8/27 AI/JB/ISE/SIT/2019-20
EIE426-AICV 51
Generate‐and‐Test
AI/JB/ISE/SIT/2019-20 53
TSP Example
A 6 B
1 2
5 3
D 4 C
AI/JB/ISE/SIT/2019-20 54
Generate-and-test Example
cities:
1. A - B - C - D B C D
2. A - B - D - C
3. A - C - B - D
4. A - C - D - B C D B D C B
...
D C D B B C
AI/JB/ISE/SIT/2019-20 55
2.Hill Climbing
• Hill Climbing is a variant of generate and test.
AI/JB/ISE/SIT/2019-20
Algorithm: Simple Hill Climbing (Local Search)
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.
AI/JB/ISE/SIT/2019-20
2.2 Steepest-Ascent Hill Climbing
• Instead of moving to the first state that is better, move to the best
possible state that is one move away.
AI/JB/ISE/SIT/2019-20
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 (SUCC ) 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 SUCC. If it is better,
then set S to this state. If it is not better, leave S alone.
(c) If the SUCC is better than CS, then set CS to SUCC.
AI/JB/ISE/SIT/2019-20
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.
AI/JB/ISE/SIT/2019-20
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.
AI/JB/ISE/SIT/2019-20 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:
Compute E = Val(current state) - Val(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 make it the current state with
probability
P = eE/kT
c. Revise T as necessary according to the annealing schedule
5. Return BEST –So-FAR as the answer.
AI/JB/ISE/SIT/2019-20 62
3 Best First Search
•Best-First Search (BFS) is a way of combining the advantages of
both depth-first search and breadth first search into a single method,
i.e., is to follow a single path at a time but switch paths whenever
completing path looks more promising than the current one does.
OR Graphs
A graph is called OR graph, since each of its branches represents
alternative problems solving path.
AI/JB/ISE/SIT/2019-20
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.
• If not, all those new nodes are added to the set of nodes
generated so far.
AI/JB/ISE/SIT/2019-20
Best First Search Algorithm
• It finds a least cost path from a given initial node to one goal
node.
– It evaluates nodes by combining g(n) and h'(n)
i.e Evaluate Function f'(n) = g(n) + h'(n)
– Where
• g(n) = cost so far to reach n
• h'(n) = estimated cost from n to goal(heuristic value)
• f'(n) = estimatedAI/JB/ISE/SIT/2019-20
total cost of path through n to goal 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.
AI/JB/ISE/SIT/2019-20
Advantages
AI/JB/ISE/SIT/2019-20
The A* procedure
A simple search problem: S is the start node, G is the goal
node, the real distances are shown.
A 4 B 4 C
3
S 5 5
4 G
3.5
D2 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 C 3.4
9.2
3.5 D 9.2
D E 7.1 F
E 7.1
F 3.5
G 0
AI/JB/ISE/SIT/2019-20
Hill-climbing happens to
succeed here:
S
A 4 B 4 C 10.1 9.2
3
S 5 5 A D
4 G
3.5
D2 E 4
F 10.1 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
AI/JB/ISE/SIT/2019-20
A*, step 1 The A* procedure
S
f(n) = h(n) + g(n)
3+10.1 4+9.2
A 4 B 4 C A D
3
S 5 5
4 G
3.5 City Straight Line Distance to Goal
D2 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
AI/JB/ISE/SIT/2019-20
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
D2 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
AI/JB/ISE/SIT/2019-20
A*, step 4
The A* procedure
f(n) = h(n) + g(n)
A 4 B 4 C
3
S
S 5 5
4 G 13.1 13.2
3.5
D2 E 4
F
A D
AI/JB/ISE/SIT/2019-20
A*, step 5
The A* procedure
f(n) = h(n) + g(n)
A 4 B 4 C
3 S
S 5 5
4 G 13.1 13.2
3.5
D2 E 4
F A D
AI/JB/ISE/SIT/2019-20
A*, step 6 The A* procedure
f(n) = h(n) + g(n)
4 4 S
A B C
3 13.1 13.2
S 5 5
4 G
3.5 A D
D2 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
AI/JB/ISE/SIT/2019-20
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.
AI/JB/ISE/SIT/2019-20
The Problem-Reduction (Goal Reduction) Method
2017/8/27 AI/JB/ISE/SIT/2019-20 78
A Decomposable Problem
2017/8/27 AI/JB/ISE/SIT/2019-20
EIE426-AICV 79
Problem Reduction
Goal: Steal TV set Goal: Earn some money Goal: Buy TV set
AND-OR Graphs
AI/JB/ISE/SIT/2019-20 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.
AI/JB/ISE/SIT/2019-20
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.
AI/JB/ISE/SIT/2019-20
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.
AI/JB/ISE/SIT/2019-20
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.
AI/JB/ISE/SIT/2019-20
5.Constraint Satisfaction Problem
AI/JB/ISE/SIT/2019-20
Constrains Satisfaction Algorithm
1. Propagate available constraints
a. All objects should be opened and must be assigned values in a
complete solution
b. Repeat the succeeding steps until inconsistency or all objects
assigned valid values
• Select an object and strengthen this object as much as possible by a
set of constraints that is applied to the object.
• If the set of constraints is not matched from the previous set, then
open all objects that share any of these constraints.
• Remove selected objects
2. Return Solution, if the union of constraints exposed above
defines a solution.
3. Otherwise return failure , if the union of constraints
discovered above defines a contradiction
AI/JB/ISE/SIT/2019-20
Example 1: Cryptarithmetic Problems
AI/JB/ISE/SIT/2019-20
Example : Cryptarithmetic
Assign numbers to letters so that the sum is correct
Solution
F ORTY 2 9 7 86
F=2, O=9
+ T EN + 8 50 R=7, T=8
+ T EN + 8 50 Y=6, E=5
S I XTY 3 1 4 86 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:
AI/JB/ISE/SIT/2019-20
Example
Step 1: Here Y+N+N = Y ;
F ORTY 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.
+ T EN So c1 = 0 , c2 = 1
+ T EN
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
2 9 7 86 T and R must be higher numbers
+ 850 Then only we get a carry c3 = 2
So T = 8 and R = 7
+ 850
3 1 4 86 Step3: Just Assume F = 2 , Then S= 3
AI/JB/ISE/SIT/2019-20
Other Examples
S END 8 542 9 567
+ M O RE + 0 9 15 + 1 0 85
M O NEY 0 9 4 57 1 0 6 52
D O N ALD 5 2 6 485
+ G E R A LD + 1 9 7 4 85
RO B ERT 7 2 3 9 70
CROSS 96233
+ R O A DS + 62513
D A N G ER
158746
AI/JB/ISE/SIT/2019-20
6. Means End Analysis
• MEA is a technique that was first used in
general problems solver by Newell and Simon.
• It is a problem solving method in which the
solution with minimum difference between
the current state and the goal state is
determined.
AI/JB/ISE/SIT/2019-20
Means-Ends Analysis Algorithm
AI/JB/ISE/SIT/2019-20
The Task:
2017/8/27 AI/JB/ISE/SIT/2019-20
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 AI/JB/ISE/SIT/2019-20
EIE426-AICV 98
A Difference Table
Operators
differences
AI/JB/ISE/SIT/2019-20 99
The Progress of the Means-Ends Analysis Method
2017/8/27 AI/JB/ISE/SIT/2019-20
Algorithm: Means-Ends Analysis (CURRENT, GOAL)
<- MEA (O-RESULT, GOAL)) are successful, then signal success and
return the result of concatenating FIRST-PART,O, and LAST-PART.
AI/JB/ISE/SIT/2019-20