02-Problem Decomposition and Planning
02-Problem Decomposition and Planning
Departmental Mission –
a) To provide quality education enabling
students for higher studies, research and
entrepreneurship.
b) To inculcate professionalism and ethical
values through day to day practices.
AI& R COURSE OUTCOMES:
CO1 : Able to identify and apply the concept of AI
and various search strategies in various AI
applications
CO2 : Able to apply Artificial Intelligence
control.
CO6 : To understand and analyze various types of
robots in practice
UNIT 2 : PROBLEM
DECOMPOSITION AND
PLANNING
CONTENTS:
Problem Decomposition: Goal Trees, Rule Based
Systems, Rule Based Expert Systems.
Problem Analysis.
AA BB C C
Problem Reduction Space
A B C
3AC
Problem Reduction Space
A B C
3AC
2AB
1AC
Problem Reduction Space
A B C
3AC
2AB
1AC 1AB
Problem Reduction Space
A B C
3AC
2AB
A B C
3AC
2AB 1AC
A B C
3AC
A B C
3AC
A B C
3AC
A
(9)
A
(3) B D (5) 38
(4) C B C D
17 9 27
E F G H I J
(5) (10) (3) (4) (15) (10)
Thus we can see that to search an AND-OR graph,
the following three things must be done.
1. Traverse the graph starting at the initial node
and following the current best path, and
accumulate the set of nodes that are on the path
and have not yet been expanded.
2. Pick one of these unexpanded nodes and
expand it. Add its successors to the graph and
computer f ' (cost of the remaining distance) for
each of them.
3. Change the f ' estimate of the newly expanded
node to reflect the new information produced by
its successors. Propagate this change backward
through the graph. Decide which of the current
best path.
RULE-BASED SYSTEMS
KBS ARCHITECTURE (1)
Thetypical architecture of an KBS is
often described as follows:
ABCDEECDBBACDACDBCDECDADCADBADE
ECDBBACDACDBCDECDADCADBADCDBBACDA
BCDEECDBBACDACDBCDECDAD
BBACDACDBCDECDADCADBADEDCDBBA
DCDBBADCDBBABCDECDADCADBADEACDA
BACDACDBCDECDADBACDACDBCDECDAD
THE EDWIN SMITH PAPYRUS
It contains medical descriptions of 48
different types of head wound.
There is a fixed format for each problem
Some writers just talk about the if-part and the then-part.
TERMINOLOGY
If a production system chooses a particular
rule, because the conditions match the
current state of affairs, and puts the
conclusions into effect, this is known as firing
the rule.
TERMINOLOGY
In a production system, the rules are stored
together, in an area called the rulebase.
HISTORICAL NOTE
Mathematicians, linguists, psychologists and
artificial intelligence specialists explored the
possibilities of production rules during the
40s, 50s and 60s.
When the first expert systems were invented
working
select memory modify
rule
Inference
memory fire output
engine
REASONING WITH
PRODUCTION RULES
Architecture of a typical production
system:
New information
working
select memory modify
rule
interpreter
memory fire output
REASONING WITH
PRODUCTION RULES
Architecture of a typical production
system:
New information
select working
memory modify
rule
interpreter
memory fire output
REASONING WITH
PRODUCTION RULES
Architecture of a typical production
system:
New information
working
select memory modify
Inference
rule engine
memory output
fire executes
actions
REASONING WITH
PRODUCTION RULES
Architecture of a typical production
system:
New information
working
select memory modify
Inference
rule engine
memory
fire executes output
actions
REASONING WITH
PRODUCTION RULES
Architecture of a typical production
system:
New information
select working
memory modify
rule
interpreter
memory fire output
REASONING WITH
PRODUCTION RULES
Architecture of a typical production
system:
New information
working
select memory modify
Inference
rule engine
memory executes output
fire
actions
REASONING WITH
PRODUCTION RULES
Architecture of a typical production
system:
New information
working
select memory modify
Inference
rule engine
memory executes
fire output
actions
ARCHITECTURE OF A TYPICAL
PRODUCTION SYSTEM
Has a working memory.
Holds items of data. Their
presence, or their absence,
causes the inference engine to trigger
certain rules.
e.g. W.M. contains [john, age, 29]
& [john, employment, none]
The system decides: does this
match any rules in the rulebase? If
so, choose the rule.
ARCHITECTURE OF A TYPICAL
PRODUCTION SYSTEM
has an inference engine. Behaviour of the
inference engine :
the system is started by putting a
suitable data item into working
memory.
recognise-act cycle: when data in
the working memory matches the
conditions of one of the rules in
the system, the rule fires (i.e.is
brought into action).
ADVANTAGES OF PRODUCTION
SYSTEMS ... AT FIRST GLANCE
The principle advantage of production rules
is notational convenience - it’s easy to
express suitable pieces of knowledge in this
way.
A
C B
A B C
Start state Goal state
ON(C, A) ON(A, B)
ONTABLE(A) ON(B, C)
ONTABLE(B) ONTABLE(C
CLEAR(B) )
CLEAR(C)
GOAL-STACK PLANNING
ALGORITHM
:= // plan is initially empty
C := start state // C is the current state Push the goal state on the stack
Push all its subgoals on the stack (in any order) Repeat until the stack is empty:
X := Pop the top of the stack
IF X is a compound goal THEN
push its subgoals which are unsatisfied in C on the stack
ELSE IF X a single goal FALSE in C THEN
push an action Q that satisfies X
push all preconditions of Q
ELSE IF X is an action THEN
execute X in current state C, change the new current state C
using the action’s effects, add X to plan
ELSE IF X is a goal which is TRUE in current state C THEN NOTHING
C STAT
Stack
EC
ON(A, B) A B
ON(B, C)
:= []
ON(A, B) ON(B, C) ONTABLE(C) Plan
C Current
state C
ON(B, C) A B
ON(A, B) ON(B, C)
ONTABLE(C) := []
Plan
X := ON(A, B)
single goal
FALSE in C
ON(A, B) is in
the effect of
action
Q := STACK(A,
B).
C Current
state C
HOLDING(A) A B
CLEAR(B)
CLEAR(B) HOLDING(A)
:= [] Plan
STACK(A, B)
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
ARMEMPTY
ARMEMPTY ON(C, A) CLEAR(C) := [] Plan
UNSTACK(C, A)
ARMEMPTY
ARMEMPTY CLEAR(A) X := O N(C, A)
ONTABLE(A) a singl So e goal TRUE in
PICKUP(A) do C
CLEAR(B) othing
CLEAR(B) HOLDING(A)
STACK(A, B)
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
C Current
state C
A B
:= [] Plan
UNSTACK(C, A)
ARMEMPTY
ARMEMPTY CLEAR(A) X := ARMEMPTY ON(C,
ONTABLE(A) A)
PICKUP(A) CLEAR(C)
CLEAR(B) a compound goal TRUE in
CLEAR(B) HOLDING(A) C
STACK(A, B)
So do nothing
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
C Current
state C
A B
:= [] Plan
ARMEMPTY
ARMEMPTY CLEAR(A) X := UNSTACK(C, A)
ONTABLE(A) action
PICKUP(A) Add to plan
CLEAR(B) Create new state by
CLEAR(B) HOLDING(A) executing
STACK(A, B)
X in current state C.
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
C New
Current
A B state C
:= [UNSTACK(C, A)]
ARMEMPTY
ARMEMPTY CLEAR(A) X := ARMEMPTY is FALSE in C
ONTABLE(A)
PICKUP(A) ARMEMPTY is in the effect of
CLEAR(B) action Q := PUTDOWN(C).
CLEAR(B) HOLDING(A)
STACK(A, B) Push Q and its preconditions on stack
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
C Current
state C
A B
HOLDING(C)
:= [UNSTACK(C,
PUTDOWN(C) A)]
ARMEMPTY
ARMEMPTY CLEAR(A) X := HOLDING(C) is TRUE in C
ONTABLE(A) So do not hing
PICKUP(A)
CLEAR(B)
CLEAR(B) HOLDING(A)
STACK(A, B)
ON(B, C)
C Current
state C
A B
:= [UNSTACK(C, A)]
ARMEMPTY
ARMEMPTY CLEAR(A) X := PUTDOWN(C) is action.
ONTABLE(A) Add it to plan
PICKUP(A) Create new state by executing
CLEAR(B) X in current state C.
CLEAR(B) HOLDING(A)
STACK(A, B)
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
New
Current
C A B state C
:= [UNSTACK(C, A),
PUTDOWN(C)]
X := ARMEMPTY CLEAR(A)
ONTABLE(A) is TRUE in C
PICKUP(A) So do nothing.
CLEAR(B)
CLEAR(B) HOLDING(A)
STACK(A, B)
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
CURRENT STATE C C A B
:= [UNSTACK(C, A),
PUTDOWN(C)]
X := PICKUP(A) is action.
Add it to plan
Create new state by executing
CLEAR(B) X in current state C.
CLEAR(B) HOLDING(A)
STACK(A, B)
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
A New
Current
C B state C
:= [UNSTACK(C, A),
PUTDOWN(C), PICKUP(A)]
X := CLEAR(B) is TRUE in C
So do nothing
CLEAR(B) HOLDING(A)
STACK(A, B)
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
A Current
state C
C B
:= [UNSTACK(C, A),
PUTDOWN(C), PICKUP(A)]
X := CLEAR(B) HOLDING(A)
is TRUE in C
So do nothing
STACK(A, B)
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
A Current
state C
C B
:= [UNSTACK(C, A),
PUTDOWN(C), PICKUP(A)]
X := STACK(A, B) is action.
Add it to plan
Create new state by executing
X in current state C.
ON(B, C)
ON(A, B) ON(B, C) ONTABLE(C)
A
NEW CURRENT STATE C C B
:= [UNSTACK(C, A),
PUTDOWN(C), PICKUP(A),
STACK(A, B)]
X := ON(B, C) is FALSE in
C
B Current
state C
A C
ON(A, B) ON(B, C)
:= [UNSTACK(C, A),
ONTABLE(C) PUTDOWN(C), PICKUP(A),
STACK(A, B), UNSTACK(B,
A), PUTDOWN(B),
PICKUP(B), STACK(B, C)]
Subgoal ON(A, B) is FALSE in this state. So it is pushed on
stack
RENT
B STAT
EC
A C
:= [UNSTACK(C, A),
PUTDOWN(C), PICKUP(A),
ON(A, B)
STACK(A, B), UNSTACK(B,
ON(A, B) ON(B, C) ONTABLE(C)
A), PUTDOWN(B),
PICKUP(B), STACK(B, C)]
RENT
B STAT
EC
A C
:=
[UNSTACK(C, A),
PUTDOWN(C),
ON(A, B) ON(B, C) ONTABLE(C) PICKUP(A),
STACK(A, B),
UNSTACK(B, A),
X := ON(A, B) is FALSE in C. PUTDOWN(B),
ON(A, B) is in the effect of action Q := PICKUP(B),
STACK(A,
B). STACK(B, C)]
X := CLEAR(B) is TRUE in C.
So do nothing.
B Current
state C
A C
:= [UNSTACK(C, A),
HOLDING(A) CLEAR(B) PUTDOWN(C), PICKUP(A),
STACK(A, B)
STACK(A, B), UNSTACK(B,
ON(A, B) ON(B, C) ONTABLE(C)
A), PUTDOWN(B),
PICKUP(B), STACK(B, C)]
X := HOLDING(A) is FALSE in
C.
HOLDING(A) is in effects of
action Q := PICKUP(A). Push Q
and its preconditions to stack
B Current
CLEAR(A) state C
ONTABLE(A) A C
ONTABLE(A) CLEAR(A)
PICKUP(A) := [UNSTACK(C, A),
HOLDING(A) CLEAR(B) PUTDOWN(C), PICKUP(A),
STACK(A, B)
STACK(A, B), UNSTACK(B,
ON(A, B) ON(B, C) ONTABLE(C)
A), PUTDOWN(B),
PICKUP(B), STACK(B, C)]
B Current
state C
ONTABLE(A) A C
ONTABLE(A) CLEAR(A)
PICKUP(A) := [UNSTACK(C, A),
HOLDING(A) CLEAR(B) PUTDOWN(C), PICKUP(A),
STACK(A, B)
STACK(A, B), UNSTACK(B,
ON(A, B) ON(B, C) ONTABLE(C)
A), PUTDOWN(B),
PICKUP(B), STACK(B, C)]
X := CLEAR(A) is TRUE in C.
So do nothing
B Current
state C
A C
ONTABLE(A) CLEAR(A)
PICKUP(A) := [UNSTACK(C, A),
HOLDING(A) CLEAR(B) PUTDOWN(C), PICKUP(A),
STACK(A, B)
STACK(A, B), UNSTACK(B,
ON(A, B) ON(B, C) ONTABLE(C)
A), PUTDOWN(B),
PICKUP(B), STACK(B, C)]
X := ONTABLE(A) is TRUE in
C.
So do nothing
B Current
state C
A C
PICKUP(A) := [UNSTACK(C, A),
HOLDING(A) CLEAR(B) PUTDOWN(C), PICKUP(A),
STACK(A, B)
STACK(A, B), UNSTACK(B,
ON(A, B) ON(B, C) ONTABLE(C)
A), PUTDOWN(B),
PICKUP(B), STACK(B, C)]
X := ONTABLE(A) CLEAR(A)
is TRUE in C.
So do nothing
B Current
state C
A C
:= [UNSTACK(C, A),
HOLDING(A) CLEAR(B) PUTDOWN(C), PICKUP(A),
STACK(A, B)
STACK(A, B), UNSTACK(B,
ON(A, B) ON(B, C) ONTABLE(C)
A), PUTDOWN(B),
PICKUP(B), STACK(B, C)]
X := PICKUP(A) is an action.
Add it to plan
Create new state by executing
X in current state C.
A B New
Current
C state C
:=
HOLDING(A) CLEAR(B) [UNSTAC
STACK(A, B)
K(C, A),
ON(A, B) ON(B, C) ONTABLE(C)
PUTDOW
N(C),
PICKUP(
A),
STACK(A
, B),
UNSTAC
K(B, A),
PUTDOW
N(B),
PICKUP(
RENT
A B STAT
C EC
:=
[UNSTACK(C, A),
STACK(A, B) PUTDOWN(C),
ON(A, B) ON(B, C) ONTABLE(C) PICKUP(A),
STACK(A, B),
UNSTACK(B, A),
X := HOLDING(A) CLEAR(B) TRUEPUTDOWN(B),
in C.
So do nothing. PICKUP(B),
STACK(B, C),
PICKUP(A)]
RENT
A B STAT
C EC
:=
[UNSTACK(C, A),
PUTDOWN(C),
ON(A, B) ON(B, C) ONTABLE(C) PICKUP(A),
STACK(A, B),
UNSTACK(B, A),
X := STACK(A, B) is an action. PUTDOWN(B),
Add it to plan, execute it in C and createPICKUP(B),
the new
state. STACK(B, C),
PICKUP(A)]
A
B New
Current
C state C
:= [UNSTACK(C, A),
PUTDOWN(C), PICKUP(A),
STACK(A, B), UNSTACK(B,
A), PUTDOWN(B),
PICKUP(B), STACK(B, C),
PICKUP(A), STACK(A, B)]
A
B New
Current
C state C
:= [UNSTACK(C, A),
PUTDOWN(C), PICKUP(A),
X := ON(A, B) ON(B, C) STACK(A, B), UNSTACK(B,
ONTABLE(C) is TRUE in A), PUTDOWN(B),
C. PICKUP(B), STACK(B, C),
So do nothing. PICKUP(A), STACK(A, B)]
A
B New
Current
C state C
:= [UNSTACK(C, A),
PUTDOWN(C), PICKUP(A),
Stack is empty. So STACK(A, B), UNSTACK(B,
STOP. A), PUTDOWN(B),
PICKUP(B), STACK(B, C),
PICKUP(A), STACK(A, B)]
• Note that the resultant plan is inefficient!
• ON(A, B) was first done and then undone.
• Could we fix it? For example, suppose in the first step
we pushed the subgoals so that ON(B, C) was on the
top of stack (instead of ON(A, B)).
– HOMEWORK: Check what happens!
• Sussman proved that the Goal-Stack Planning algorithm
does not always produce the most efficient plan.
– This is because Goal-Stack Planning is a linear planning
algorithm: given a conjunction of goals, it achieves the goals
in a linear sequential manner.
– Achieving one goal (ON(A, B)) destroys the preconditions of
an action to achieve the second goal (CLEAR(B) to achieve
ON(B, C)). So we have to redo the first goal.
CONSTRAINT ASTISFACTION
PROBLEM
CONSTRAINT SATISFACTION
PROBLEMS (CSPS)
Standard search problem:
138
state is a "black box“ – any data structure that supports
successor function, heuristic function, and goal test
CSP:
state is defined by variables Xi with some values from
domain Di
a set of constraints Ci specifies allowable combinations of
values for subsets of variables
aconsistent state violates none of the constraints C
a complete assignment has values assigned to all
variables.
A Solution is a complete, consistent assignment.
Simple example of a formal representation
language
Allows useful general-purpose algorithms with more
power than standard search algorithms
Based on Hwee Tou Ng, aima.eecs.berkeley.edu/slides-ppt,
CSC 8520 Spring 2010. Paula Matuszek which are based on Russell, aima.eecs.berkeley.edu/slides-pdf.
EXAMPLE: MAP-COLORING
140
Solutions
are complete and consistent
assignments, e.g., WA = red, NT =
green,Q = red,NSW = green,V = red,SA
= blue,T = green
CONSTRAINT GRAPH
Binary CSP: each constraint relates two
141
variables
Constraint graph: nodes are variables, arcs
are constraints
VARIETIES OF CSPS
Discrete variables
finite domains:
n variables, domain size d O(dn) complete assignments
e.g., Boolean CSPs, incl.~Boolean satisfiability (NP-
complete)
infinite domains:
integers, strings, etc.
e.g., job scheduling, variables are start/end days for each
job
need a constraint language, e.g., StartJob + 5 ≤ StartJob
1 3
Continuous variables
e.g.,start/end times for Hubble Space Telescope
observations
linear constraints solvable in polynomial time by linear
programming algorithms from operations research
VARIETIES OF CONSTRAINTS
Unary constraints involve a single variable,
e.g., SA ≠ green
Binary constraints involve pairs of
variables,
e.g., SA ≠ WA
Higher-order constraints involve 3 or more
variables,
e.g., cryptarithmetic column constraints
Global constraints: arbitrary # of constraints, not
necessarily all the variables in a problem
e.g., AllDiff: all values must be different.
Sudoku rows, cols, squares
EXAMPLE: CRYPTARITHMETIC
Variables: F T U W R O X1 X2 X3
Domains: {0,1,2,3,4,5,6,7,8,9}
Constraints: Alldiff (F,T,U,W,R,O)
O + O = R + 10 · X1
X1 + W + W = U + 10 · X2
X2 + T + T = O + 10 · X3
X3 = F, T ≠ 0, F ≠ 0
REAL-WORLD CSPS
Common problems:
Assignment problems
e.g., who teaches what class
Timetabling problems
e.g., which class is offered when and
where?
Transportationscheduling
Factory scheduling
Notice that many real-world problems
involve real-valued variables
May also include preference constraints:
constraint optimization
STANDARD SEARCH FORMULATION
(INCREMENTAL)
Let's start with the straightforward approach, then fix
it:
States are defined by the values assigned so far
Initial state: the empty assignment { }
Successor function: assign a value to an
unassigned variable that does not conflict with
current assignment
fail if no legal assignments
Goal test: the current assignment is complete
Wikipedia.org
PROBLEMS N < 4
N<4
Cannot use N
3 Queens
1
What is the minimum number of queens
needed to occupy or attack all squares of an
8x8 board?
SEARCH
Solving problems by searching
Some problems have a straightforward solution
Just apply the formula, or follow a standardized procedure
Example: solution of the quadratic equation
Hardly a sign of intelligence
Search space:
– The set of objects among which we search for the
solution
Example: objects = routes between cities, or N-queen
configurations
Goal condition
– What are the characteristics of the object we want
to find in the search space?
– Examples:
Path between cities A and B
Path between A and B with the smallest number of links
Path between A and B with the shortest distance
Non-attacking n-queen configuration
N-QUEENS PROBLEM
Problem:
-- How do we represent the search space?
N-QUEENS PROBLEM
Problem:
-- How do we represent the search
space?
N-Queens
– We look for a target configuration,
not a sequence of moves
– No distinguished initial state, no
operators (moves)
-- Don’t use a graph
A SOLUTION: KNOW YOUR DOMAIN
Since there are N rows and N queens, there must be
a queen in each column (why?),