Topic 2 Goal Tree and Problem Solving
Topic 2 Goal Tree and Problem Solving
09/01/2023 INTRODUCTION TO AI 1
Outline
• Problem solving
◦ Review
◦ Goal trees
• Problem Reduction
◦ Symbolic Integration [The start of AI]
◦ Box Staking Problem
• Understanding Goal Trees
• Conclusion
09/01/2023 INTRODUCTION TO AI 2
Problem solving - Review
• As we concluded from previous lectures, successful problem solving
is aided by:
◦ choosing the best representation for the problem, e.g., using
visual perception
◦ identifying the initial and goal states
◦ identifying all possible states
◦ exposing constraints
09/01/2023 INTRODUCTION TO AI 3
Problem solving – Goal trees
• A tree is commonly encountered data shape Root
hierarchical relationships
Level 1 2 3
meaningful
Leaf
09/01/2023 INTRODUCTION TO AI 4
Problem solving – Goal trees
• Properties of trees: Root
Level 2 4 5 6 7 8
09/01/2023 INTRODUCTION TO AI 5
Tower Of Hanoi
• The objective of the game is to move all n disks from pin A over to
pin C but with the following constraints:
◦ You cannot place a larger disk onto a smaller disk.
◦ You can move one disk at a time
• Example n = 3
09/01/2023 INTRODUCTION TO AI 6
Example of Tower of Hanoi
• The Tree starts from the Initial state and details the steps on how to reach the goal
state
Level 0
Level 1
violate violate
constraints constraints
Level 2
depth
• The above Tree is up to the 2nd level, you can continue until you reach the goal state.
09/01/2023 INTRODUCTION TO AI 7
Example of Tower of Hanoi
09/01/2023 INTRODUCTION TO AI 8
Example of Tower of Hanoi
09/01/2023 INTRODUCTION TO AI 9
Example of Tower of Hanoi
09/01/2023 INTRODUCTION TO AI 10
Example of Tower of Hanoi
09/01/2023 INTRODUCTION TO AI 11
Example of Tower of Hanoi
09/01/2023 INTRODUCTION TO AI 12
Example of Tower of Hanoi
09/01/2023 INTRODUCTION TO AI 13
Example of Tower of Hanoi STEPS=
09/01/2023 INTRODUCTION TO AI 14
Example of Tower of Hanoi
• One possible solution (path from root to goal) is shown on
the right.
09/01/2023 INTRODUCTION TO AI 16
Example of Tower of Hanoi
# Recursive Python function to solve the tower of Hanoi
def TowerOfHanoi(n, source, destination, auxiliary):
if n==1:
print ("Move disk 1 from source", source, "to destination
",destination)
return
TowerOfHanoi(n-1, source, auxiliary, destination)
print ("Move disk", n, “from source", source, "to destination",
destination)
TowerOfHanoi(n-1, auxiliary, destination, source)
# Driver code
n = 3
TowerOfHanoi(n,'A','C','B')
# A, C, B are the names of rods
09/01/2023 INTRODUCTION TO AI 17
Problem Reduction
• Sometimes we must divide the complex
problem into different sets of easier
independent problems
n
and Test methodology where we will try to
generate different sub-solutions (sub-goals)
then test them to see if the goal is reached
09/01/2023 INTRODUCTION TO AI 18
Problem Reduction
• In problem reduction we will use a goal
tree which is a form of tree structure
used to represent problems that can be
broken down into smaller problems
◦ Similar to that in Tower of Hanoi example
09/01/2023 INTRODUCTION TO AI 19
Problem Reduction
• Sometimes we have different ways to
solve the problem, so we use OR node like
the one shown
• Note that the AND node has the arch
while the OR node does not
09/01/2023 INTRODUCTION TO AI 20
AND node vs. OR node
09/01/2023 INTRODUCTION TO AI 21
AND-OR Shortcut
S1
S1
S2
S2
S’2
S5
S3 S4 S5
S3 S4
09/01/2023 INTRODUCTION TO AI 22
Example of Tower Of Hanoi – Problem reduction
• The root node, labeled “3AC” represents the original problem of
transferring all 3 disks from A to C
• The goal can be decomposed into three sub-goals: 2AB, 1AC, 2BC. In
order to achieve the goal, all 3 sub-goals must be achieved.
3AC
09/01/2023 INTRODUCTION TO AI 23
Example of Tower Of Hanoi – Problem reduction
3AC
2AB
09/01/2023 INTRODUCTION TO AI 24
Example of Tower Of Hanoi – Problem reduction
3AC
2AB
1AC
09/01/2023 INTRODUCTION TO AI 25
Example of Tower Of Hanoi – Problem reduction
3AC
2AB
1AC 1AB
09/01/2023 INTRODUCTION TO AI 26
Example of Tower Of Hanoi – Problem reduction
3AC
2AB
09/01/2023 INTRODUCTION TO AI 27
Example of Tower Of Hanoi – Problem reduction
3AC
2AB 1AC
09/01/2023 INTRODUCTION TO AI 28
Example of Tower Of Hanoi – Problem reduction
3AC
09/01/2023 INTRODUCTION TO AI 29
Example of Tower Of Hanoi – Problem reduction
3AC
09/01/2023 INTRODUCTION TO AI 30
Example of Tower Of Hanoi – Problem reduction
3AC
https://www.youtube.com/watch?v=rf6uf3jNjbo
09/01/2023 INTRODUCTION TO AI 31
Example of Tower Of Hanoi – Problem reduction
3AC
https://www.youtube.com/watch?v=rf6uf3jNjbo
09/01/2023 INTRODUCTION TO AI 32
Symbolic Integration using Problem Reduction
• The Start of AI was with Symbolic Integration 4
−5 𝑥
• Can you integrate the following equation: ∫ (1 − 𝑥 ) 𝑑𝑥
2 5 /2
09/01/2023 INTRODUCTION TO AI 33
Symbolic Integration using Problem Reduction
• Modeling the way a human solves an integration problem
• Solution approach:
◦ Simplify the integral given to an easier problem that will help us in
solving the integral
• Problem Reduction will utilize a known transform to reduce the
original problem to a simpler one.
• We will denote each step of problem reduction by a Node
• Review your calculus basics!
09/01/2023 INTRODUCTION TO AI 34
Review of Integration Facts
• Safe Transformations: always good to do
No Name Safe Transform
1. Sign Rule
2. Constant Rule
3. Sum Rule
4. Division Divide (if the degree of is greater than the degree of perform long division
Note that point 1 and 2 are the same but we will treat them differently for ease of understanding
09/01/2023 INTRODUCTION TO AI 35
Review of Integration Facts
• Heuristic Transformations: sometimes useful, do not always work
No Name Safe Transform
A. Trigonometric
B. Trigonometric to
polynomial
09/01/2023 INTRODUCTION TO AI 36
Trigonometric Identities
09/01/2023 INTRODUCTION TO AI 37
Solving the Symbolic Integration Problem
If no solutio n
Apply Safe Find a problem to
Transformation work on
© AKRAM AHMED 38
Symbolic Integration Problem
• The original integration problem can be simplified to:
• The reduced problem is simpler now but still significantly hard, need
more transformations
09/01/2023 INTRODUCTION TO AI 39
Symbolic Integration Problem
• By substituting Heuristic Transformation (C) and (A)
• Since the power of the numerator is larger than the power of the
denominator, we can simplify by doing long division (safe
transformation 4), thus the equation is further simplified to:
09/01/2023 INTRODUCTION TO AI 41
Symbolic Integration Problem
• Using Safe Transformation 3 (Integral Sum Rule) we can write:
09/01/2023 INTRODUCTION TO AI 42
Symbolic Integration Problem
• By doing the following substitution
• We can write:
09/01/2023 INTRODUCTION TO AI 43
Symbolic Integration Problem (Summary)
A B C 4 D
sin 𝑦
→∫ 5 /2
cos 𝑦𝑑𝑦
( 1 −sin 𝑦 )
2
1 F
E
sin 4 𝑦
∫ cot 4 𝑦 𝑑𝑦
∫ cos4 𝑦 𝑑𝑦
∫ tan 𝑦𝑑𝑦
G 4 H
4 𝑧
→∫ 𝑑𝑧 J
∫ 𝑧 𝑑𝑧 2
2
1+𝑧
L
∫ −1𝑑𝑧 →∫ 𝑑𝑧
I K
∫ ( 2
𝑧 −1+
1
1+𝑧
2
𝑑𝑧 ) M N
∫ 1+𝑧 𝑑𝑧→∫ 𝑑𝑤
1
2
09/01/2023 INTRODUCTION TO AI 44
Symbolic Integration Problem - Goal Trees
• Rearranging nodes with symbols we get A
F G
J K M
• A Goal Tree L N
09/01/2023 INTRODUCTION TO AI 45
Understanding Goal Trees
• General Tree structure A
one edge E
I
• The tree depth for the integration problem is 9
J K M
L N
09/01/2023 INTRODUCTION TO AI 46
Understanding Goal Trees
• Tree depth gives a lot of information such as:
◦ Complexity of the problem:
As the tree depth grows, the problem is viewed as being more complex since it needs
more steps to solve the problem
◦ Note multiple solutions of a problem exist with different tree depth, the
smart choice is to use the shortest tree.
09/01/2023 INTRODUCTION TO AI 47
Understanding Goal Trees
• In the integration program, the following was observed: A
09/01/2023 INTRODUCTION TO AI 48
Strategy to Solve Symbolic Integration Summary
• Start with safe transformations, the ones you are sure will work in any case. Then
apply heuristic transformations, the ones that could work.
• The problem simplification schema, may create
◦ "and node" where the problem forks in several sub problems and
◦ "or node" where the problem may be solved with either one or another
transformation.
• The resulting schema is usually called a "problem reduction tree", "and/or tree"
or "goal tree".
• Note: In an "or node", it helps to understand the depth of functional composition
(number of transformations to be applied after the "or" options of the branch)
and the simplicity of solving each option to complete the problem resolution.
09/01/2023 INTRODUCTION TO AI 49
To get the Goal Tree of a Certain Problem
1.Start by evaluating what kind of knowledge is involved.
[Integration Tables; Transformations; Goal Tree]
2.Understand how the knowledge is represented. Each category of
knowledge has its own way of being represented.
[Expressions; Tables; Goal Trees as Procedures]
3.Know how the knowledge is used
[Transformations to make problems simpler; Integration Tables to trim bottom
of Tree]
4.Know how much knowledge is required to solve the problem.
[26 integration tables; 12 safe transformations; 12 heuristic transformations]
09/01/2023 INTRODUCTION TO AI 50
Goal Trees Application: Box Stacking Problem
• Box Stacking is a typical application of Goal Trees. Robot
Arm
• Given figure shows the distribution of boxes on top of
a table. The shown arm can pick a box, move it and
place it in another location.
• The goal is to place some box x on top of another box y
with the following constraints:
◦ The robot arm can only handle a single box at a time
◦ A box can be placed on an empty space on the table
or on top of another box
◦ Can not put a box with larger width on top of a box
with smaller width
09/01/2023 INTRODUCTION TO AI 51
Goal Trees Application: Box Stacking Problem
• To make an intelligent box stacking algorithm we need to define the
following functions:
1. Put on or Table: place box x on top of box y or Table
2. Clear Top : clear the top of box x
3. Find Location for on : remove box on top of box y to enable putting
box x on box y.
4. Grasp : grasp or hold box x.
5. Move x: move the arm to location x.
6. Ungrasp : let go of box x.
7. Get rid of : remove box x and place it on the table or on another box if
no free space on table
09/01/2023 INTRODUCTION TO AI 52
Goal Trees Application: Box Stacking Problem
• Put B1 on B2
09/01/2023 INTRODUCTION TO AI 53
Goal Trees Application: Box Stacking Problem
• Put B2 on B6
09/01/2023 INTRODUCTION TO AI 54
Goal Trees Application: Box Stacking Problem
• The generated goal tree is as follows
09/01/2023 INTRODUCTION TO AI 55
Goal Trees Application: Box Stacking Problem
• Put B1 on B2
• Not that B4 and B7 are blocking the arm from grasping B1 and releasing
it on top of B2.
• We need to get rid of B4 and B7 by placing them on the table
• To get rid of B4, we call the function put B4 on Table
• To get rid of B7, we call the function put B7 on Table
09/01/2023 INTRODUCTION TO AI 56
Goal Trees Application: Box Stacking Problem
• The generated goal tree is as follows
09/01/2023 INTRODUCTION TO AI 57
Goal Trees Application: Box Stacking Problem
• Structuring the function as shown enables
building programs that can answer
questions about their behavior.
• Such structure can answer “How” and
“Why” questions.
◦ The answer to “How” question is going
down in the tree level by level
◦ The answer to “Why” question is going
up in the tree by one level
• At the early stages, such programs were
considered “intelligent” programs.
09/01/2023 INTRODUCTION TO AI 58
Conclusion
• Many problems can be visually represented in form of goal trees
• Trees aid our understanding of the problem and show the difficulty
of the problem by looking at the depth of the tree
• A Goal Tree program can answer questions about its own behavior
by reporting steps up (why questions) or down (how questions) in
the actions it takes.
09/01/2023 INTRODUCTION TO AI 59