Introduction to Problem Solving
AI Unit II
1
from initial description of the problem to the desired solution
Introduction to Problem Solving
AI Unit II
2
problems
solution and test it
Control Strategy
General Problem Solving
AI Unit II
3
Production System (PS)
process more conveniently in state space problems
General Problem Solving
AI Unit II
4
Production System (PS)
rules are applied when several rules match at once
opinion in a specific domain
disturbing the rest of the system
input to the database changes the behaviour of the system
General Problem Solving
AI Unit II
5
Water Jug Problem: We have two jugs, a 5-gallon and 3-gallon capacity respectively with no measuring marker on them. There is endless supply of water through tap
5 -g Jug
3 -g Jug
General Problem Solving
AI Unit II
6
Water Jug Problem : Our task is to get 4 gallon of water in the 5-g jug
5 -g Jug
3 -g Jug
4 Gallon
General Problem Solving : Water Jug Problem
AI Unit II
7
General Problem Solving : Water Jug Problem
AI Unit II
8
Possible operations that can be used in this problem are as follows:
down the drain
down the drain
These rules can be formally be defined as production rules
Table 1: Production rules for Water Jug problem
AI Unit II
9
Rule No. | Left of Rule | Right of Rule | Description |
1 | ( X, Y | X < 5 ) | ( 5, Y) | Fill 5-g jug |
2 | ( X, Y | X > 0 ) | ( 0, Y) | Empty 5-g jug |
3 | ( X, Y | Y < 3 ) | ( X, 3) | Fill 3-g jug |
4 | ( X, Y | Y > 0 ) | ( X, 0) | Empty 3-g jug |
5 | ( X, Y | X +Y ≤ 5 𝖠 Y > 0 ) | ( X+Y, 0) | Empty 3-g into 5-g jug |
6 | ( X, Y | X +Y ≤ 3 𝖠 X > 0 ) | ( 0, X+Y) | Empty 5-g into 3-g jug |
7 | ( X, Y | X +Y ≥ 5 𝖠 Y > 0 ) | ( 5, Y – (5-X)) Until the 5-g jug is full | Pour water from 3-g jug into 5-g jug |
8 | ( X, Y | X +Y ≥ 3 𝖠 X > 0 ) | ( X-(3-Y), 3) Until the 3-g jug is full | Pour water from 5-g jug into 3-g jug |
Table 2: Solution Path 1
AI Unit II
10
Rule applied | 5-g jug | 3-g jug | Step No. |
Start State | 0 | 0 | |
1 | 5 | 0 | 1 |
8 | 2 | 3 | 2 |
4 | 2 | 0 | 3 |
6 | 0 | 2 | 4 |
1 | 5 | 2 | 5 |
8 | 4 | 3 | 6 |
Goal State | 4 | - | |
Table 3: Solution Path 2
AI Unit II
11
Rule applied | 5-g jug | 3-g jug | Step No. |
Start State | 0 | 0 | |
3 | 0 | 3 | 1 |
5 | 3 | 0 | 2 |
3 | 3 | 3 | 3 |
7 | 5 | 1 | 4 |
2 | 0 | 1 | 5 |
5 | 1 | 0 | 6 |
3 | 1 | 3 | 7 |
5 | 4 | 0 | 8 |
Goal State | 4 | - | |
State Space Search
AI Unit II
12
easy search
State Space Search
AI Unit II
13
graph
some heuristic function
state of problem to another
The Eight Puzzle Problem
AI Unit II
14
Problem Statement : It has a 3 x 3 Grid with 8 randomly numbered (1 to 8) tiles arranged on it with one empty cell. At any point, the adjacent tile can move to the empty cell, creating a new empty cell. Tiles are arranged such that we get the goal state from start state.
The Eight Puzzle Problem
AI Unit II
15
3 | 7 | 6 |
5 | 1 | 2 |
4 | | 8 |
5 | 3 | 6 |
7 | | 2 |
4 | 1 | 8 |
Start State
Goal State
The Eight Puzzle Problem
AI Unit II
16
AI Unit II
17
Partial Search Tree for Eight
Puzzle Problem
3 | 7 | 6 |
5 | 1 | 2 |
4 | | 8 |
3 | 7 | 6 |
5 | | 2 |
4 | 1 | 8 |
3 | 7 | 6 |
5 | 1 | 2 |
| 4 | 8 |
3 | 7 | 6 |
5 | 1 | 2 |
4 | 8 | |
3 | | 6 |
5 | 7 | 2 |
4 | 1 | 8 |
3 | 7 | 6 |
| 5 | 2 |
4 | 1 | 8 |
3 | 7 | 6 |
5 | 2 | |
4 | 1 | 8 |
Right
Up
Left
Up
Left
Right
Initial State
Control Strategies
approach is not systematic.
exhaustive, uninformed, blind searches in nature
systematic will lead to a solution.
AI Unit II
18
Control Strategies
There are two directions in which a search could proceed
and works towards a conclusion.
For eg. Language OPS5 uses forward reasoning rules. Rules are expressed in the form of if-then rules.
this strategy
AI Unit II
19
Control Strategies
AI Unit II
20
Characteristics of Problem
AI Unit II
21
For eg. In Water Jug Problem, if we have filled the jug, we can empty it also
For eg. Any two player game such as Chess, Playing Cards, Snake and Ladder
Characteristics of Problem
AI Unit II
22
For eg. If it is humid, it will rain. If it is sunny, it is daytime. It is sunny day. It is
nighttime.
Characteristics of Problem
AI Unit II
23
For eg. Water Jug problem –Any path problem-Solved in reasonable amount
of time
Exhaustive Searches
AI Unit II
24
Systematic uninformed exhaustive searches:
1. Breadth-First Search(BFS)
AI Unit II
25
Breadth-First Search(BFS) Algorithm
AI Unit II
26
Input: START and GOAL states
Local Variables: OPEN, CLOSED, STATE-X, SUCCs, FOUND;
Output: Yes or No Method:
{
{
}
}
Table 1: Production rules for Water Jug problem
AI Unit II
27
Rule No. | Left of Rule | Right of Rule | Description |
1 | ( X, Y | X < 5 ) | ( 5, Y) | Fill 5-g jug |
2 | ( X, Y | X > 0 ) | ( 0, Y) | Empty 5-g jug |
3 | ( X, Y | Y < 3 ) | ( X, 3) | Fill 3-g jug |
4 | ( X, Y | Y > 0 ) | ( X, 0) | Empty 3-g jug |
5 | ( X, Y | X +Y ≤ 5 𝖠 Y > 0 ) | ( X+Y, 0) | Empty 3-g into 5-g jug |
6 | ( X, Y | X +Y ≤ 3 𝖠 X > 0 ) | ( 0, X+Y) | Empty 5-g into 3-g jug |
7 | ( X, Y | X +Y ≥ 5 𝖠 Y > 0 ) | ( 5, Y – (5-X)) Until the 5-g jug is full | Pour water from 3-g jug into 5-g jug |
8 | ( X, Y | X +Y ≥ 3 𝖠 X > 0 ) | ( X-(3-Y), 3) | Pour water from 5-g jug into 3-g jug until 3-g jug is full |
AI Unit II
28
Search Tree Generation using BFS for Water Jug Problem
1. Breadth-First Search(BFS)
AI Unit II
29
2. Depth-First Search (DFS)
AI Unit II
30
keeps track of states already expanded. Both are maintained as stacks.
Depth-First Search (DFS) Algorithm
AI Unit II
31
Input: START and GOAL states
Local Variables: OPEN, CLOSED, RECORD_X, SUCCESSORS, FOUND;
Output: A path sequence from START to GOAL state, if one exists, otherwise return No
Method:
{
{
}
}
the CLOSED list else return No
AI Unit II
32
Search Tree Generation using DFS
AI Unit II
33
2. Depth-First Search (DFS)
The path is obtained from the list stored in CLOSED. The solution path is (0,0) 🡪 (5,0) 🡪 (5,3) 🡪 (0,3) 🡪(3,0) 🡪 (3,3) 🡪 (5,1) 🡪 (0,1) 🡪 (1,0) 🡪
(1,3) 🡪 (4,0)
AI Unit II
34
Comparison between BFS and DFS:
search tree
only one connection point to the rest of the states
tree
from the GOAL has been chosen
Measuring Problem Solving Performance
The output of the problem solving algorithm is either failure or a solution.
We can evaluate an algorithm’s performance in four ways.
Completeness: Is the algorithm guaranteed to find a solution when there is one?
Optimality: Does the strategy find the optimal solution?
Time Complexity: How long does it take to find a solution?
Space Complexity: How much memory is needed to perform the search?
Searching with Partial Information
What happens when knowledge of the states or actions is incomplete?
We find that different types of incompleteness lead to three distinct problem types:
1. Sensorless Problems:
3. Depth-First Iterative Deepening Search(DFID)
AI Unit II
37
goal state
Depth-First Iterative Deepening Search(DFID) Algorithm
AI Unit II
38
Input: START and GOAL states Local Variables: FOUND Output: Yes or No
Method:
{
}
AI Unit II
39
Search Tree Generation using DFID
3. Depth-First Iterative Deepening Search(DFID)
AI Unit II
42
reaching the goal depth
4. Bidirectional Search
AI Unit II
43
from the goal and stops when the two meet in the middle
state
depth k+1, not storing states but simply matching against the stored states
generated from forward direction
4. Bidirectional Search
AI Unit II
44
from matched state to goal state
help generating complete path from start to goal states
can be generated as a part of search
Find a route /path from node labeled 1 to node labeled 16
AI Unit II
45
Graph to be searched using Bidirectional Search
Trace of Bidirectional Space
AI Unit II
46
Analysis of Search Methods
Effectiveness of any search strategy in problem solving is measured in terms of :
AI Unit II
54
Analysis of Search Methods
AI Unit II
55
Let b be the branching factor and d be the depth of tree in worst case
Search Technique | Time | Space | Solution |
DFS | O(b d) | O(d) | -- |
BFS | O(b d) | O(b d) | Optimal |
DFID | O(b d) | O(d) | Optimal |
Bidirectional | O(b d/2) | O(b d/2) | -- |
Analysis of Search Methods
AI Unit II
56
of the search tree increases, such as Travelling Salesman Problem
relevant problem information and finds solutions faster
Analysis of Search Methods
AI Unit II
57
returned
cities grows, then the time required to wait a salesman to get the information about the shortest path is not a practical solution. This phenomenon is called a combinatorial explosion
than the shortest path length found so far
that is directly proportional to some number raised to ‘n’
AI Unit II
58
Graph for Travelling Salesman Problem
AI Unit II
61
Performance
Comparison
Heuristic Search Techniques
AI Unit II
60
alternatives will be the most effective to achieve some goal
systematic and completeness
very good solution
Strategies
Hill Climbing
AI Unit II
61
solutions are better than others
Simple Hill Climbing Algorithm
AI Unit II
62
Input: START and GOAL states
Local Variables: OPEN, NODE, SUCCs, FOUND;
Output: Yes or No
Method:
{
{
front of OPEN list;
}
}
Problems with Hill Climbing
AI Unit II
63
moves look to be worse. In such case backtrack to some earlier state and try going in different direction to find a solution
section of the search space
Problems with Hill Climbing
AI Unit II
64
Best First Search
AI Unit II
65
search, sorting is done on the entire list
solution faster than solution obtained from any other method
function
Best First Search Algorithm
AI Unit II
66
Input: START and GOAL states
Local Variables: OPEN, CLOSED, NODE, FOUND;
Output: Yes or No
Method:
{
OPEN list and put it in CLOSED list;
node, the estimate to reach to the goal node;
}
Best First Search
AI Unit II
67
Condition for termination
A* Algorithm
AI Unit II
68
determine the order in which the search visits nodes in the tree
f(N) = g(N) + h(N)
where –
g is a measure of the cost of getting from the start node to the current node N i.e. sum of costs of the rules that were applied along the best path to the current node
h is an estimate of additional cost of getting from current node N to the
goal node
A* Algorithm
AI Unit II
69
finds the shortest path to a goal
f(X) value
The Eight Puzzle Problem
AI Unit II
3 | 7 | 6 |
5 | 1 | 2 |
4 | | 8 |
5 | 3 | 6 |
7 | | 2 |
4 | 1 | 8 |
Start State
70
Goal State
where h(X) = number of tiles not in their goal position in a given state X
g(X) = depth of node X in the search tree
AI Unit II
71
AI Unit II
mentioned before
3 | 5 | 1 |
2 | | 7 |
4 | 8 | 6 |
5 | 3 | 6 |
7 | | 2 |
4 | 1 | 8 |
Start State Goal State
in a given state X
72
A* Algorithm
AI Unit II
73
For each successor, m, insert m in OPEN only if if m∉ [OPEN𝖴CLOSED]
set g(m)= g[n]+C[n,m]
set f(m)=g(m)+h(m)
if m∈[OPEN𝖴CLOSED]
set g(m)= min{g[m], g(n)+C[n,m]} set f(m)=g(m)+h(m)
if f[m] has decreased and m∈CLOSED move m to OPEN
Optimal Solution by A* Algorithm
AI Unit II
node in the graph/tree.
Example search graph for Underestimation
74
Optimal Solution by A* Algorithm
AI Unit II
Example search graph for Overestimation
75
Optimal Solution by A* Algorithm
AI Unit II
76
in an optimal path from start state to goal state, if path exists
heuristic function