You are on page 1of 23

General Problem Solving

To build a system to solve a particular problem,


following steps are required –
Define the problem precisely
Analyze problem
Isolate and represent the task knowledge
Choose the best problem solving techniques
Apply it to the particular problem.
State Space Search
The representation of configuration of
possible arrangements in a problem, as
a legal set of rules, from one state
(configuration) to another state is
referred as state space.

3
State Space Search
1. Define a state space that contains all the possible
configurations of the relevant objects.
2. Specify the initial states.
3. Specify the goal states.
4. Specify a set of rules:
 What are unstated assumptions?
 How general should the rules be?
 How much knowledge for solutions should be in
the rules?
4
Water Jug Problem
“You are given two jugs, a 4-litre one and
a 3-litre 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 litres of water into
4-litre jug.”

5
State Space Search – Solution
State: (x, y)
x = 0, 1, 2, 3, or 4 y = 0, 1, 2, 3
Start state: (0, 0).
Goal state: (2, n) for any n.
Attempting to end up in a goal state.
(x, y)  (4, y)

6
Rules
S.No Condition Action Explanation
1 if x  4  (4, y) Fill the 4 litres jug
2 (x, y)  (x, 3) Fill the 3 litres jug
if y  3
3 (x, y)  (x  d, y) Pour some water out of 4 litres
if x  0 jug
4 (x, y)  (x, y  d) Pour some water out of 3 litres
if y  0 jug
5 (x, y)  (0, y) Empty the 4 litres jug on the
if x  0 ground
6 (x, y)  (x, 0) Empty the 3 litres jug on the
if y  0 ground
7
S.No Condition Action Explanation
7 (x, y)  (4, y  (4  x)) Pour some water from the 3
litres jug into the 4 litres jug
if x  y  4, y  0 until the 4 litres jug is full
8 (x, y)  (x  (3  y), 3) Pour some water from the 4
litres jug into the 3 litres jug
if x  y  3, x  0 until the 3 litres jug is full
9 (x, y)  (x  y, 0) Pour all the water from the 3
litres jug into the 4 litres jug.
if x  y  4, y  0
10 (x, y)  (0, x  y) Pour all the water from the 4
litres jug into the 3 litres jug.
if x  y  3, x  0
11 (x, 2)  (0,2) Empty the x litres from the 4
x>0 litres jug on the ground

12 (0, 2)  (2, 0) Pour the 2 litres from the 3 litres


jug into the 4 litres jug 8
Solution to Water Jug Problem
Following is the trace of above production rules as directed –
Water in 4 L Jug Water in 3 L Jug Rule Applied

  0 0 INITIAL STATE
2
0 3 9
3 0 2
3 3 7
4 2 5
0 2 9
2 0 GOAL STATE
9
Formal description of a Problem
To provide a formal description of a problem, we
must do the following –
Define a state space that contains all the possible
configuration of the relevant objects.
Specify one or more states within that space that
describe possible situations from which the
problem solving process may start. These states
are called INITIAL STATE.

10
Formal description of a Problem
Specify one or more states that would be
acceptable as solution to the problem. These
states are called GOAL STATE.
Specify a set of rules that describe the actions
(operators) available.

11
Production System
A production system consists of –
A set of rules – each consisting of a left side (a pattern)
that determines the applicability of the rule and a right
side that describes the operation to be performed if the
rule is applied.
One of more knowledge databases – that contain
whatever information is appropriate for the particular
task. Some parts of the database may be permanent,
while other parts of it may pertain only to the solution
of the current problem. Information in these databases
may be structured in any appropriate way.

12
Production System
A control strategy – that satisfies the order in
which the rules will be compared to the database
and a way of resolving the conflicts that arise
when several rules match at once.
A rule applier.

13
Control Strategies
The requirements of good control strategies are –
It cause motion
It should be systematic
Control strategies are techniques to decide which
rule to apply next during the process of
searching for the solution to a problem. Control
strategies that do not cause motion will never
lead to a solution.

14
Control Strategies
The requirement that control strategy be
systematic corresponds to the need for
global motion (over the course of several
steps) as well as for local motion (over the
course of a single step).

15
Forward chaining
Forward chaining is a process of
searching in which we start with a given
initial state and when we connect it
(chain it) with the next state closest to
goal state compared with all successor
states of the initial state. Thus we find a
path (i.e. chain of states) consisting of
various states starting from initial state
to goal state.
16
Backward chaining
Backward chaining is a reverse of forward
chaining. In this process of searching we
start with a goal state and then we connect
it (chain it) with the next state closest to
the initial state compared with the all
predecessor states of the goal state. Thus
we find a path (i.e. chain of states)
consisting of various states starting from
goal state to initial state.
17
Depth First Search
Expand one of the nodes
at the deepest level.
Depth first search works by
taking a node, checking its
neighbors, expanding the
first node it finds among the
neighbors, checking if that
expanded node is our
destination, and if not,
continue exploring more
nodes.
18
Depth First Search – Algorithm
Place the starting node s on the queue.
If the queue is empty, return failure and stop.
If the first element on queue is a goal node g,
return success and stop. Otherwise,
Remove and expand the first element, and place
the children at the front of the queue (in any
order)
Return to step 2.

19
Depth First Search –
Advantages
DFS requires less memory since only the nodes
on the current path are stored. This contrasts
with BFS, where all parts of the tree that has so
far been generated must be stored.
By chance, DFS may find solution without
examining much of the search space at all. This
contrasts with BFS in which all parts of the tree
must be examined to level n before any nodes on
level n+1 can be examined.

20
Breadth First Search
Expand all the nodes
of
one level first.
In breadth first search,
newly explored nodes are
added to the end of your
Open list.

21
Breadth First Search –
Algorithm
Place the starting node s on the queue.
If the queue is empty, return failure and stop.
If the first element on the queue is a goal node g,
return success and stop. Otherwise,
Remove and expand the first element from the
queue and place all the children at the end of the
queue in any order.
Return to step 2.

22
Breadth First Search – Advantages
BFS will not get trapped exploring a blind alley.
This contrasts with DFS searching, which may
follow a single, unfruitful path for a very long time,
perhaps forever, before the path actually terminate
in the state that has no successors.
If there is a solution, then BFS search is guaranteed
to find it. Furthermore, if there are multiple
solutions, then a minimal solution will be found.
This is guaranteed by the fact that longer paths are
never examined until the shorter paths have
already been examined.
23

You might also like