You are on page 1of 100

Artificial Intelligence

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:

1. Define the problem precisely ( Precise Specification ,


Initial Situation , Final Situation and Acceptable
Solution )
2. Analyze the problem (Features , Various Possible
techniques , etc)
3. Isolate and represent the task knowledge that is
necessary to solve the problem.
4. Choose the best problem solving techniques and
apply it to the particular problem
AI/JB/ISE/SIT/2019-20
Formal Description of a Problem :
In order to provide a formal description of a
problem we must do the following :
1. Define a state space that contains all possible
configuration of the relevant objects
2. Define the initial States
3. Define the Goal /Final States
4. Specify the Rules that describe the action
(operators) available.
AI/JB/ISE/SIT/2019-20
Example1: The Tic Tac Toe as a State
Space Search Representation
Answer:
• Configuration of the Board (State Space)
– Board is Vector of 9 squares of 3 X 3 Matrix Form
– Next Move of a Players : X or O
– Board Configuration may change accordingly to each move of the
player
• Initial State : Board is Empty by X’s Turn
• Final States : Three X’s in Row / Three O’s in Row / All Cells Full
• Rules :
– At a time one square can be filled in any direction
– Initial turn is of X
– Out of X and O players who will form the row First will be the winner
– If No Row is formed but the board is filled the Match is draw.

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.

• 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.
AI/JB/ISE/SIT/2019-20
Production system consists of
•A Set of Rules: a left side (a pattern) that determines the
applicability of the rule and right side that describes the operation
to be performed if the rule is applied.

• Knowledge Base – It contains whatever information is


appropriate for a particular task.
Some parts of the database may be permanent, while the parts of
it may pertain only to the solution of the current problem.

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.

•A rule applier: Production rule is like below


if(condition) then
consequence or action

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.

• A good control strategy should have the following requirement:

– The first requirement is that it causes motion. In a game playing


program the pieces move on the board and in the water jug problem
water is used to fill jugs.

– The second requirement is that it is systematic, this is a clear


requirement for it would not be sensible to fill a jug and empty it
repeatedly nor in a game would it be advisable to move a piece round
and round the board in a cyclic way.
AI/JB/ISE/SIT/2019-20
Search Techniques for Artificial
Intelligence
Search is a central topic in Artificial Intelligence. The basic
search algorithms/techniques can be classified as follows:

• Uninformed( Blind) search: Breadth-first, Depth- first,


depth limited, iterative deepening, and bidirectional search

• Informed (Heuristic) search: Generate and Test, Hill


Climbing , Best First Search , Problem Reduction,
Constraint Satisfaction , Means ends Analysis .

AI/JB/ISE/SIT/2019-20
Breadth first search Algorithm
1. Create a variable called NODE_LIST and set it to the initial state

2. Until a goal state is found or NODE_LIST is empty


a. Remove the First Element from NODE_LIST and Call it E
IF NODE _LIST was empty quit

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)

(4,3) (0,0) (1,3) (4,3) (0,0) (3,0)

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

a. Generate a successor E of initial State . If there are no


successor signal failure
b. Call DFS with E as the initial state

c. If success is returned , signal success , otherwise


continue in this loop

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.

• In the situations where solution exists, the breadth first search is


guaranteed to find it.

• In case of multiple solutions, the BFS finds the minimal


solution(the 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.
AI/JB/ISE/SIT/2019-20
Advantages of Depth First Search
(DFS)
• DFS requires less memory space since only the nodes on the
current path are stored. In BFS all the tree that has so far
being generated must be stored

• If care is taken in ordering the alternative successor states


DFS may find a solution without examining much of the
search space at all. In BFS all parts of the tree must be
examined to level n before any nodes level n+1 can be
examined.

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.

• Where finding an optimal solution is impossible or impractical, heuristic


methods can be used to speed up the process of finding a satisfactory
solution.

• Heuristic are the approximations used to reduce the search procedure.


AI/JB/ISE/SIT/2019-20
AI/JB/ISE/SIT/2019-20
Heuristic Search
• No longer guaranteed to give the best answer but that will almost
always find a very good answer.

• Heuristic actually works like a tour guide.

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 .

Example: Speech recognition, and computer vision etc.

2)Problems for which exact solutions are known, but


computationally they are infeasible.
E.g. chess and cube game

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

3. Repeat Step 2 until all cities have been visited

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.

• h(n), which takes a node n and returns a non- negative real


number that is an estimate of the path cost from node n to a
goal node.

• Purpose is to guide the search process in the most profitable


direction

• It provides an informed way to guess which neighbor of a


node will lead to a goal.
AI/JB/ISE/SIT/2019-20
Some Simple Heuristic Functions
• Chess : The material advantage of our side over the opponent

• Travelling Salesman Program : The sum of the distances


travelled so far

• Tic Tac Toe :

1 for each row in which we could win and in which we


already have one piece

2 for each such row in which we have two pieces


AI/JB/ISE/SIT/2019-20
(Seven) Problem Characteristics

1. Is the problem decomposable?


2. Can solution steps be ignored or undone?
3. Is the problem’s universe predictable?
4. Is a good solution absolute or relative?
5. Is the solution a state or a path?
6. What is the role of knowledge?
7. Does the task require human‐interaction?

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.

• 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.

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)

• 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)

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 “ .

• With the water jug problem, what we really must report is


not the final state but the path that we found to that state.
Thus a statement of solution to this problem must be a
sequence of operation that produces the final state. This
problem solution is path to the state.

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.

• In 8 puzzle or Chess game we get a solution with the help of


knowledge base. (Rules for determining the legal moves).

• But when we consider the problem of scanning daily newspaper to


decide which political party will win in upcoming election, it
would have to know such things as
– The name of the candidate of each party
– Major issues/achievement to support party
– Major issues to oppose the party
– And so on –
AI/JB/ISE/SIT/2019-20
7.Does the task require human‐interaction?

• Solitary problem, in which there is no intermediate


communication and no demand for an explanation of the
reasoning process.

• Conversational problem, in which intermediate


communication is to provide either additional assistance to
the computer or additional information to the user.

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.

• Not all new problems should be considered as totally new.


Solutions of similar problems can be exploited.

• Broad classes to which the problems falls is associated with


a generic control strategy that is appropriate for solving the
problems.

– Classification: Medical diagnosis tasks, Diagnosis of fault in


mechanical devices.
– Propose and Refine AI/JB/ISE/SIT/2019-20
: Design and Planning Problems
Issues in the Design of Search
programs
1. The direction in which to conduct the search (forward vs
backward reasoning)

2. How to select applicable rules (matching)

3. How to represent each node of the search process (knowledge


representation problem and frame problem)

4. Search tree versus Graph

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

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.

AI/JB/ISE/SIT/2019-20
Generate-And-Test

2017/8/27 AI/JB/ISE/SIT/2019-20
EIE426-AICV 51
Generate‐and‐Test

• It may be a systematic form or random form.

– In systematic form it is simply an exhaustive


search of the problem space.

– The random form is also known as the British


Museum method a reference to a method for finding
an object in the British Museum by wandering
randomly.
.
AI/JB/ISE/SIT/2019-20
Example - Traveling Salesman Problem (TSP)

• Traveler needs to visit n cities.


• Know the distance between each pair of cities.
• Want to know the shortest route that visits all
the cities once.
• n=80 will take millions of years to
solve exhaustively!

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

• TSP - generation of possible


solutions is done in
lexicographical order of A B C D

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.

• 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
AI/JB/ISE/SIT/2019-20
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.

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

• 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.

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.

• 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.

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 = eE/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.

– 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


AI/JB/ISE/SIT/2019-20
continues
To implement such a graph procedure, we will need to use lists of nodes:
1) OPEN: nodes that have been generated and have had the heuristic
function applied to them which have not yet been examined. It is a
priority queue in which the elements with highest priority are those
with the most promising value of the heuristic function.

2) CLOSED: nodes that have already been examined whenever a new


node is generated we need to check whether it has been generated
before.

3) A heuristic function f which will estimate the merits of each node we


generate.

AI/JB/ISE/SIT/2019-20
Best First Search Algorithm

I. Start with OPEN containing just the


initial state.
2. Until a goal is found or there are
no nodes left on OPEN do:
(a)Pick the best node on OPEN.
(b)Generate its successors.
(c)For each successor do:
(i)If it has not been generated
before, evaluate it, add it to
OPEN, and record its parent.
(ii)If it has been generated
before, change the parent if
this new path is better than
the previous one. In that case,
update the cost of getting to
this node and to any
successors that this node may
OR Graphs for Best First Search already, have.
AI/JB/ISE/SIT/2019-20
A* Search
• A* (A star) is the most widely known form of Best-First search. It
uses f’, h’, and g functions and lists OPEN and CLOSED.

• 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.

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.

AI/JB/ISE/SIT/2019-20
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*.
AI/JB/ISE/SIT/2019-20
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.

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

City Straight Line Distance to Goal


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 3
The A* procedure
f(n) = h(n) + g(n)
A 4 B 4 C
3
S
S 5 5
4 G
3.5 13.1 13.2
D2 E 4
F
A D

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

12.8 17.2 4+5+10.1


City Straight Line Distance to Goal
City (h(n)) B D A
S 11.5
A 10.1 14.4 19.1 4+2+7.1
B 5.8
C 3.4 C E E
D 9.2
E 7.1
F 3.5
G 0

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

12.8 17.2 19.1


City Straight Line Distance to Goal
City (h(n)) B D A
S 11.5
A 10.1
14.4 19.1 13.1
B 5.8
C 3.4 C E E
D 9.2
4+2+5+5.8 4+2+4+3.5
E 7.1
F 3.5
B F
G 0

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: Acquire TV set

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

• A CSP is a problem composed of a finite set of variables, each of


which is associated with a finite domain, and a set of constraints.
• CPS is a search procedure that operates in a space of constraint
state. Constraints in the initial state are originally given in the given
problem. Any state is a goal state that has been constrained
‘enough’ where ‘enough’ means that each letter has been assigned
a unique numeric value.
• The solution process in CSP contains cycles wherein the following
things are done on each cycle :
• Propagate the constraints using rules that correspond to the arithmetic
properties
• Guess a value for some letter whose value is not yet determined.

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

• The problem is to plot integers from 0 to 9 for


the alphabet specified in the crypt arithmetic
problems with following constraints :
1. No two alphabets should have the same integer
value .
2. Having allotted the different values for different
alphabets we have to perform the arithmetic
operations specified in the problem.

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

 Until the goal is reached or no more procedures are available,


1. Describe the current state, the goal state, and Calculate the difference
between the two.
2. Use the difference, to select a promising procedure.
 Use the promising procedure and update the current state.
 If the goal is reached, announce success; otherwise, announce
failure.

Key idea is to reduce difference between the current state


and the goal state.

AI/JB/ISE/SIT/2019-20
The Task:

A robot moves a desk with two things on it from one


room to another.

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)

WALK(loc) none at(robot, loc)


PICKUP(obj) at(robot, obj) holding(obj)
PUTDOWN(obj) holding(obj) holding(obj)
PLACE(obj1, obj2) at(robot, obj2)^ on(obj1, obj2)
holding(obj1)

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)

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.
AI/JB/ISE/SIT/2019-20

You might also like