You are on page 1of 40

Problem-Solving: State-Space

Search and Control Strategies


IMP

State-Space: Set of all possible states from start


to goal states is called state space.

Control Strategy: The order of application of the


rules to the current state is called control
strategy.
Problem Solving
1.General Problem Solving:
1.1) Production System
2.1) State-Space Search
3.1) Control Strategies
2.Exhaustive Searches
2.1) Breadth-first Search
2.2) Depth-First search
2.3)Depth-First Iterative Deepening
2.4)Bidirectional Search
3. Heuristic Search Techniques
3.1) General-Purpose heuristics
3.2) Branch and Bound Search (Unifrom Cost search)
3.3)Hill Climbing
3.4)Beam Search
3.5)Best-first Search
3.6) A* Algorithm
3.7) Monotonic Functions
4. Control Strategies
1.1
Example:
Water-Jug Problem

Problem:
You are given two jugs, a 5-gallon one and a 3-gallon one. Neither has
any measuring mark on it. There is a pump that can be used to fill the
jugs with water. How can you get exactly 4 gallons of water into the 5-
gallon jug.

Solution:
The state space for this problem can be described as the set of ordered
pairs of integers (x,y) Where,
• X represents the quantity of water in the 5-gallon jug X= 0,1,2,3,4,5
• Y represents the quantity of water in 3-gallon jug Y=0,1,2,3
• Start State: (0,0)
• Goal State: (4,N) for any value of N<=3
Production rules for the problem
Applying production rules and getting the solution
Water Jug Problem:

Problem: You are given two jugs, a 4-gallon one and a 3-gallon one.Neither has
any measuring mark on it.There is a pump that can be used to fill the jugs
with water.How can you get exactly 2 gallons of water into the 4-gallon jug.

Solution:
The state space for this problem can be described as the set of ordered pairs of
integers (x,y)
Where,
X represents the quantity of water in the 4-gallon jug X= 0,1,2,3,4
Y represents the quantity of water in 3-gallon jug Y=0,1,2,3
Start State: (0,0)
Goal State: (2,0)
Generate production rules for the water jug problem
Missionaries and Cannibals
Question: In this problem, three missionaries and three cannibals
must cross a river using a boat which can carry at most two
people, under the constraint that, for both banks, that the
missionaries present on the bank cannot be outnumbered by
cannibals. The boat cannot cross the river by itself with no
people on board.
Production Rules
Solution
1.2 State-Space Search

State space is another method of problem representation that


facilitates easy search.

A State Space basically contains 4 components


1) A Set S containing start states of the problem
2)A Set G containing goal states of the problem.
3) Set of nodes (states) in the graph/tree. Each node represents
the state in problem solving process.
4) Set of arcs connecting nodes. Each arc corresponds to
operator that is a step in a problem solving process.
Start state

State space for


Operator missionaries and
cannibals problem
1.3 Control Strategies : IMP

Describes the order of application of the rules to the current


state.
Two types:
1) Data-Driven : Forward Chaining
2)Goal-Driven: Backward Chaining
Forward chaining

It is also known as data driven inference technique.


Forward chaining matches the set of conditions and infer results from these conditions.
Basically, forward chaining starts from a new data and aims for any conclusion.
It is bottom up reasoning.
It is a breadth first search.

It continues until no more rules can be applied or some cycle limit is met.
For example:
If it is cold then I will wear a sweater.
Here “it is cold” is the data and “I will wear a sweater” is a decision. It was already
known that it is cold that is why it was decided to wear a sweater, This process is
forward chaining.
It is mostly used in commercial applications i.e event driven systems are common
example of forward chaining.
It can create an infinite number of possible conclusions.
Backward chaining.

It is also called as goal driven inference technique.


It is a backward search from goal to the conditions used to get the goal. Basically it starts
from possible conclusion or goal and aims for necessary data.
It is top down reasoning.
It is a depth first search.

It process operations in a backward direction from end to start, it will stop when the
matching initial condition is met.
For example:
If it is cold then I will wear a sweater.
Here we have our possible conclusion “I will wear a sweater”. If I am wearing a sweater
then it can be stated that it is cold that is why I am wearing a sweater. Hence it was
derived in a backward direction so it is the process of backward chaining.
It is used in interrogative commercial applications i.e finding items that fulfill possible
goals.
Number of possible final answers is reasonable.
Characteristics of Problem:
There are there types of problems in real life:
Ignorable: These are the problems where we can ignore the solution
steps. For example, in proving a theorm, if osme lemma is proved to
prove another lemma. Such problems can be solved using simple
control strategy.
Recoverable: These are the problems where solution steps can be
undone. For example. In water jus problem, if we have filled up the
jug, we an empty t also. Any state can be reached again by undoing
the steps. These problems can be solved using backtracking.
Irrecoverable: The problems where solution steps cannot be undone.
For example. Any two player game such as chess, playing cards etc
Characteristics of problem are:

1) Decomposability of a problem: Divide the problem into a set of


independent smaller sub problems. Solve them one by one and get the
final solution. Divide and conquer technique are example for it.
2) Role of knowledge: Knowledge plays a key role in solving any problem.
Knowledge could be in the form of rules and facts which help
generating search space.
3) Consistency of knowledge base: Make sure that knowledge is
consistent. Inconsistent wrong conclusions.
4) Requirement of solution: We should analyze the problem whether
solution required is absolute or relative. We call solution to be absolute
if we have to find exact solution. For example, water jug problem has
several ways of solving problem. When choosing a one problem it is
absolute no need to go back again. In traveling sales man problem , we
need to find the best path among the existing paths so it is relative
2.Exhaustive Searches or (Brute
force/Uninformed searches/ blind)
In exhaustive search the algorithm search exhaustively to find
the solutions:
Different exhaustive algorithms are:
1. Breadth first search
2. Depth first search
3. Depth first iterative Deeping.
4. Bidirectional searches.
1. Breadth first Search:
• BFS is a traversing algorithm where you should start traversing from a
selected node (source or starting node) and traverse the graph layerwise
thus exploring the neighbor nodes (nodes which are directly connected to
source node). You must then move towards the next-level neighbour
nodes.
• As the name BFS suggests, you are required to traverse the graph breadth
wise as follows:
• First move horizontally and visit all the nodes of the current layer
• Move to the next layer
2. Depth First Search (DFS)
• The DFS algorithm is a recursive algorithm that uses the idea
of backtracking. It involves exhaustive searches of all the
nodes by going ahead, if possible, else by backtracking.
• Here, the word backtrack means that when you are moving
forward and there are no more nodes along the current path,
you move backwards on the same path to find nodes to
traverse. All the nodes will be visited on the current path till all
the unvisited nodes have been traversed after which the next
path will be selected.
• This recursive nature of DFS can be implemented using stacks.
The basic idea is as follows:
Pick a starting node and push all its adjacent nodes into a stack.
Pop a node from stack to select the next node to visit and push all its
adjacent nodes into a stack. Repeat this process until the stack is empty.
However, ensure that the nodes that are visited are marked. This will
prevent you from visiting the same node more than once. If you do not
mark the nodes that are visited and you visit the same node more than
once, you may end up in an infinite loop.
Comparison of BFS and DFS:

• BFS is effective when the search tree has low branching factor
• BFS can work even in trees that are infinitely deep
• BFS requires lot of memory as number of nodes in level of the tree
increases exponentially
• BFS is superior when the GOAL exists in the upper right portion of a
search tree
• BFS gives optimal solution
• DFS is effective when there are few sub trees in the search tree that have
only one connection point to the rest of the states.
• DFS is best when the GOAL exists in the lower left portion of the search
tree.
• DFS is memory efficient as the path from start to current node is stored.
Each node should contain states and its parent.
• DFS may not give optimal solution.
Depth-First Itereative Deepning:
IDDFS combines depth-first search’s space-efficiency and breadth-first search’s
fast search (for nodes closer to root).
IDDFS calls DFS for different depths starting from an initial value. In every call,
DFS is restricted from going beyond given depth. So basically we do DFS in
a BFS fashion.
Bidirectional Search

• In normal graph search using BFS/DFS we begin our search in one


direction usually from source vertex toward the goal vertex, but what if
we start search form both direction simultaneously.

• Bidirectional search is a graph search algorithm which find smallest path


form source to goal vertex.

It runs two simultaneous search –


• Forward search form source/initial vertex toward goal vertex
• Backward search form goal/target vertex toward source vertex
• Bidirectional search replaces single search graph(which is likely to grow
exponentially) with two smaller sub graphs – one starting from initial
vertex and other starting from goal vertex. The search terminates when
two graphs intersect.
Analysis of Search Methods

• b is branching factor (i.e average number of child nodes)


• d is depth
Heuristic Search Techniques V.IMP

• A heuristic is a method that might not always find the best solution but is
guaranteed to find a good solution in reasonable time.
• By sacrificing completeness it increases efficiency.
• Useful in solving tough problems which
– could not be solved any other way.
– solutions take an infinite time or very long time to compute.
• The classic example of heuristic search methods is the travelling salesman
problem.
Generate and Test Algorithm
• generate a possible solution which can either be a point in the problem
space or a path from the initial state.
• test to see if this possible solution is a real solution by comparing the state
reached with the set of goal states.
• if it is a real solution, return. Otherwise repeat from 1.
Hill Climbing
• Hill Climbing is heuristic search used for mathematical optimization
problems in the field of Artificial Intelligence .
Given a large set of inputs and a good heuristic function, it tries to find a
sufficiently good solution to the problem. This solution may not be the
global optimal maximum.
• In the above definition, mathematical optimization problems implies that
hill climbing solves the problems where we need to maximize or minimize a
given real function by choosing values from the given inputs. Example-
Travelling salesman problem where we need to minimize the distance
traveled by salesman.
Features of Hill Climbing
• Variant of generate and test algorithm : It is a variant of generate and test
algorithm. The generate and test algorithm is as follows :
1. Generate a possible solutions.
2. Test to see if this is the expected solution.
3. If the solution has been found quit else go to step 1.

Hence we call Hill climbing as a variant of generate and test algorithm as it


takes the feedback from test procedure. Then this feedback is utilized by
the generator in deciding the next move in search space.

• Uses the Greedy approach : At any point in state space, the search moves in
that direction only which optimizes the cost of function with the hope of
finding the optimal solution at the end.
Draw-backs of Hill climbing

You might also like