0% found this document useful (0 votes)
100 views

Artificial Intelligence and Machine Learning

This document discusses state space search techniques for problem solving in artificial intelligence. It defines a problem as a state space containing all possible configurations, with initial and goal states. A state represents the problem elements at a given time, and the state space forms a graph where nodes are states and arcs are actions. Two examples are provided to illustrate defining problems as state space searches - the water jug problem and the 8-puzzle problem. Production systems are introduced as a way to structure AI programs to facilitate search processes. Key components of production systems and how they can be used to model solving problems as searches through state spaces are outlined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

Artificial Intelligence and Machine Learning

This document discusses state space search techniques for problem solving in artificial intelligence. It defines a problem as a state space containing all possible configurations, with initial and goal states. A state represents the problem elements at a given time, and the state space forms a graph where nodes are states and arcs are actions. Two examples are provided to illustrate defining problems as state space searches - the water jug problem and the 8-puzzle problem. Production systems are introduced as a way to structure AI programs to facilitate search processes. Key components of production systems and how they can be used to model solving problems as searches through state spaces are outlined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

UNIT-2

State Space Search & Heuristic Search Techniques 


 Defining The Problems  As A State Space Search
Production Systems
 Production Characteristics
 Production System Characteristics
 Generate and Test
 Hill Climbing
Depth  first search (DFS)
 Breadth first search (BFS)
 Problem reductionProduct Reduction
 Constraint  satisfaction
 Means-end analysis

Introduction
● Problem solving is the major area of concern in Artificial Intelligence.
● It is the process of generating solution from given observed data.
● To solve a particular problem, we need to build a system or a method which can generate
required solution.
● Following four things are required for building such system.
1. Define the problem precisely.
⮚ This definition must precisely specify the initial situation (input).
⮚ What final situation (output) will constitute the acceptable solution to the
problem.
2. Analyze the problem.
⮚ To identify those important features which can have an immense impact
on the appropriateness of various possible techniques for solving the
problem.
3. Isolate and represent the task knowledge that is necessary to solve the problem.
4. Choose the best problem solving technique and apply it to the particular
problem.

Defining the Problem as a State Space Search


1. Defining Problem & Search
● A problem is described formally as:
1. Define a state space that contains all the possible configurations of relevant objects.
2. 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 states.
3. Specify one or more states that would be acceptable as solutions to the problem. These
states are called goal states.
4. Specify a set of rules that describe the actions available.
● The problem can then be solved by using the rules, Some action and moves performed until
a path from an initial state to a goal state is found.
● This process is known as search.
● Search is fundamental to the problem-solving process.

2. Defining State & State Space


● A state is a representation of problem elements at a given moment.
● A State space is the set of all states reachable from the initial state.
● A state space forms a graph in which the nodes are states and the arcs between nodes
are actions.
● In state space, a path is a sequence of states connected by a sequence of actions.
● The solution of a problem is part of the graph formed by the state space.

1. Define the Problem as State Space Search


Ex.1:- Consider Water Jug problem
● A Water Jug Problem: You are given two jugs, a 4-gallon one and a 3-gallon one, a pump
which has unlimited water which you can use to fill the jug, and the ground on which
water may be poured. Neither jug has any measuring markings on it. How can you get
exactly 2 gallons of water in the 4-gallon jug?
● Here the initial state is (0, 0). The goal state is (2, n) for any value of n.
● State Space Representation: we will represent a state of the problem as a tuple (x, y)
where x represents the amount of water in the 4-gallon jug and y represents the amount
of water in the 3-gallon jug. Note that 0 ≤ x ≤ 4, and 0 ≤ y ≤ 3.
● To solve this we have to make some assumptions not mentioned in the problem. They
are:
o We can fill a jug from the pump.
o We can pour water out of a jug to the ground.
o We can pour water from one jug to another.
o There is no measuring device available.
● Operators – we must define a set of operators that will take us from one state to
another.
Sr. Current state Next Descriptio
State ns
1 (x, y) if x < 4 (4,y) Fill the 4 gallon jug

2 (x, y) if y <3 (x,3) Fill the 3 gallon jug

3 (x, y) if x > 0 (x-d, y) Pour some water out of the 4 gallon jug

4 (x, y) if y > 0 (x, y-d) Pour some water out of the 3 gallon jug

5 (x, y) if x>0 (0, y) Empty the 4 gallon jug

6 (x, y) if y >0 (x,0) Empty the 3 gallon jug on the ground

7 (x, y) if x+y >= 4 (4, y-(4- Pour water from the 3 gallon jug into
and y > 0 x)) the 4 gallon jug until the 4 gallon jug is
full
8 (x, y) if x+y >= 3 (x-(3-y), Pour water from the 4 gallon jug into
and x>0 3) the 3-gallon jug until the 3 gallon jug is
full
9 (x, y) if x+y <=4 (x+y, 0) Pour all the water from the 3 gallon jug
and y>0 into the 4 gallon jug

1 (x, y) if x+y <= 3 (0, x+y) Pour all the water from the 4 gallon jug
0 and x>0 into the 3 gallon jug

1 (0, (2,0) Pour the 2 gallons from 3 gallon jug


1 2) into the 4 gallon jug

1 (2, (0,y) Empty the 2 gallons in the 4 gallon jug


2 y) on the ground
There are several sequences of operators that will solve the problem.
● One of the possible solutions is given as:

Ex.2:- Consider 8 puzzle problem


● The 8 puzzle consists of eight numbered, movable tiles set in a 3x3 frame. One cell of the
frame is always empty thus making it possible to move an adjacent numbered tile into
the empty cell. Such a puzzle is illustrated in following diagram.

● The program is to change the initial configuration into the goal configuration.
● A solution to the problem is an appropriate sequence of moves, such as “move tiles 5 to
the right, move tile 7 to the left ,move tile 6 to the down” etc…
● To solve a problem, we must specify the global database, the rules, and the control
strategy.
● For the 8 puzzle problem that correspond to three components.
● These elements are the problem states, moves and goal.
● In this problem each tile configuration is a state.
● The set of all possible configuration in the problem space, consists of 3,62,880 different
configurations of the 8 tiles and blank space.
● For the 8-puzzle, a straight forward description is a 3X3 array of matrix of numbers.
Initial global database is this description of the initial problem state. Virtually any kind of
data structure can be used to describe states.
● A move transforms one problem state into another state.
Figure 1: Solution of 8 Puzzle problem

● The 8-puzzle is conveniently interpreted as having the following for moves.


o Move empty space (blank) to the left, move blank up, move blank to the right
and move blank down.
o These moves are modeled by production rules that operate on the state
descriptions in the appropriate manner.
● The goal condition forms the basis for the termination.
● The control strategy repeatedly applies rules to state descriptions until a description of a
goal state is produced.
● It also keeps track of rules that have been applied so that it can compose them into
sequence representing the problem solution.
● A solution to the 8-puzzle problem is given in fig. 1.

Production System
● Search process forms the core of many intelligence processes.
● So, it is useful to structure AI programs in a way that facilitates describing and performing
the search process.
● Production system provides such structures.
● A production system consists of:
1. A set of rules, each consisting of a left side that determines the applicability of the rule
and a right side that describes the operation to be performed if that rule is applied.
2. One or 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.
3. A control strategy that specifies 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.
4. A rule applier which is the computational system that implements the control strategy
and applies the rules.
● In order to solve a problem:
o We must first reduce it to the form for which a precise statement can be given. This
can be done by defining the problem’s state space (start and goal states) and a set of
operators for moving that space.
o The problem can then be solved by searching for a path through the space from an
initial state to a goal state.
o The process of solving the problem can usefully be modeled as a production system.
Production System Characteristics
1. Simplicity:  Due to the use of the IF-THEN structure, each sentence is unique in the
production system. This uniqueness makes the knowledge representation simple to
enhance the readability of the production rules.
2. Modularity: The knowledge available is coded in discrete pieces by the production
system, which makes it easy to add, modify, or delete the information without any side
effects. The production rule is made of collection of information and facts.
3. Modifiability: This feature allows for the modification of the production rules. The rules
are first defined in the skeletal form and then modified to suit an application.    
4. Knowledge-intensive: As the name suggests, the system only stores knowledge. All the
rules are written in the English language. This type of representation solves the
semantics problem.
Benefits of Production System
1. Production systems provide an excellent tool for structuring AI programs.
2. Production Systems are highly modular because the individual rules can be added,
removed or modified independently.
3. The production rules are expressed in a natural form, so the statements contained in the
knowledge base should be easily understandable.
Production System Characteristics
5. Monotonic Production System: the application of a rule never prevents the later
application of another rule that could also have been applied at the time the first rule
was selected. i.e., rules are independent.
6. Non-Monotonic Production system is one in which this is not true.
7. Partially commutative Production system: a production system with the property that if
application of a particular sequence of rules transforms state x to state y, then allowable
permutation of those rules, also transforms state x into state y.
8. Commutative Production system: A Commutative production system is a production
system that is both monotonic and partially commutative.
Heuristic Function
● Heuristic function maps from problem state descriptions to measures of desirability,
usually represented as numbers.
● Which aspects of the problem state are considered, how those aspects are evaluated, and
the weights given to individual aspects are chosen in such a way that the value of the
heuristic function at a given node in the search process gives as good an estimate as
possible of whether that node is on the desired path to a solution.
● Well-designed heuristic functions can play an important part in efficiently guiding a search
process toward a solution.
● Every search process can be viewed as a traversal of a directed graph, in which the nodes
represent problem states and the arcs represent relationships between states.
● The search process must find a path through this graph, starting at an initial state and
ending in one or more final states.
● Domain-specific knowledge must be added to improve search efficiency. Information about
the problem includes the nature of states, cost of transforming from one state to another,
and characteristics of the goals.
● This information can often be expressed in the form of heuristic evaluation function.
● In general, heuristic search improve the quality of the path that are exported.
● Using good heuristics we can hope to get good solutions to hard problems such as the
traveling salesman problem in less than exponential time.
Heuristic Search Techniques
I. Generate-and-Test
● Generate-and-test search algorithm is a very simple algorithm that guarantees to find a
solution if done systematically and there exists a solution.
Algorithm:
1. Generate a possible solution. For some problems, this means generating a particular
point in the problem space. For others it means generating a path from a start stat.
2. Test to see if this is actually a solution by comparing the chosen point or the endpoint
of the chosen path to the set of acceptable goal states.
3. If a solution has been found, quit, Otherwise return to step 1.
● It is a depth first search procedure since complete solutions must be generated before
they can be tested.
● In its most systematic form, it is simply an exhaustive search of the problem space.
● It operates by generating solutions randomly.

II. Simple Hill Climbing


● Hill climbing is a variant of generate-and test in which feedback from the test procedure
is used to help the generator decide which direction to move in search space.
● The test function is augmented with a heuristic function that provides an estimate of
how close a given state is to the goal state.
● Hill climbing is often used when a good heuristic function is available for evaluating
states but when no other useful knowledge is available.
● The key difference between Simple Hill climbing and Generate-and-test is the use of
evaluation function as a way to inject task specific knowledge into the control process.
Algorithm:
1. Evaluate the initial state. If it is also goal state, then return it and quit. Otherwise
continue with the initial state as the current state.
2. Loop until a solution is found or until there are no new operators left to be applied in
the current state:
a. Select an operator that has not yet been applied to the current state and
apply it to produce a new state.
b. Evaluate the new state
i. If it is the goal state, then return it and quit.
ii. If it is not a goal state but it is better than the current state, then
make it the current state.
iii. If it is not better than the current state, then continue in the loop
● Hill Climbing has three well-known drawbacks:
i. Local Maxima: a local maximum is a state that is better than all its neighbors but
is not better than some other states further away.
ii. Plateau: a plateau is a flat area of the search space in which, a whole set of
neighboring states have the same values.

Local Maxima Plate Rid


au ge
iii. Ridge: is a special kind of local maximum. It is an area of the search space that is
higher than surrounding areas and that itself has slop.
● In each of the previous cases (local maxima, plateaus & ridge), the algorithm reaches a
point at which no progress is being made.
● A solution is,
i. Backtrack to some earlier node and try going in a different direction.
ii. Make a big jump to try to get in a new section.
iii. Moving in several directions at once.

III. Breadth-First Search Strategy (BFS)


● This is an exhaustive search technique.
● The search generates all nodes at a particular level before proceeding to the next level of
the tree.
● The search systematically proceeds testing each node that is reachable from a parent
node before it expands to any child of those nodes.
● Search terminates when a solution is found and the test returns true.
Algorithm:
1. Create a variable called NODE-LIST and set it to initial state.
2. Until a goal state is found or NODE-LIST is empty do:
i. Remove the first element from NODE-LIST and call it E. If NODE-LIST was empty, quit.
ii. For each way that each rule can match the state described in E do:
a. Apply the rule to generate a new state.
b. If the new state is a goal state, quit and return this state.
c. Otherwise, add the new state to the end of NODE-LIST.

IV. Depth-First Search Strategy (DFS)


● Here, the search systematically proceeds to some depth d, before another path is
considered.
● If the maximum depth of search tree is reached and if the solution has not been found, then
the search backtracks to the previous level and explores any remaining alternatives at this
level, and so on.
Algorithm:
1. If the initial state is a goal state, quit and return success
2. Otherwise, do the following until success or failure is signaled:
a. Generate a successor, E, of initial state. If there are no more successors, signal
failure.
b. Call Depth-First Search, with E as the initial state
c. If success is returned, signal success. Otherwise continue in this loop.

Comparison: DFS & BFS


Depth First Search Breath First Search
DFS requires less memory since BFS guarantees that the space of
only the nodes on the current possible moves is systematically
path are stored. examined; this search requires
considerable memory resources.
By chance, DFS may find a The search systematically proceeds
solution without examining much testing each node that is reachable
of the search space at all. Then it from a parent node before it expands
finds to any
solution faster. child of those nodes.
If the selected path does not BFS will not get trapped exploring a
reach to the solution node, DFS blind alley.
gets stuck
into a blind alley.
Does not guarantee to find If there is a solution, BFS is guaranteed
solution. Backtracking is required to find it.
if wrong
path is selected.
V. Heuristic Search Techniques
● In order to solve many hard problems efficiently, it is often necessary to compromise the
requirements of mobility and systematicity and to construct a control structure that is no
longer guaranteed to find the best answer but will always find a very good answer.
● Usually very hard problems tend to have very large search spaces. Heuristics can be used to
limit search process.
● There are good general purpose heuristics that are useful in a wide variety of problem
domains.
● Special purpose heuristics exploit domain specific knowledge.
● For example nearest neighbor heuristics for shortest path problem. It works by selecting
locally superior alternative at each step.
● Applying nearest neighbor heuristics to Travelling Salesman Problem:
1. Arbitrarily select a starting city
2. To select the next city, look at all cities not yet visited and select the one closest
to the current city. Go to next step.
3. Repeat step 2 until all cities have been visited.
● This procedure executes in time proportional to N2, where N is the number of cities to be
visited.
VI. Problem Reduction/Problem Reduction
AND-OR graphs
o AND-OR graph (or tree) is useful for representing the solution of problems that
can be solved by decomposing them into a set of smaller problems, all of which
must then be solved.
o This decomposition or reduction generates arcs that we call AND arcs.
o One AND arc may point to any numbers of successor nodes. All of which must
then be solved in order for the arc to point solution.
o In order to find solution in an AND-OR graph we need an algorithm similar to best
–first search but with the ability to handle the AND arcs appropriately.
o We define FUTILITY, if the estimated cost of solution becomes greater than the
value of FUTILITY then we abandon the search, FUTILITY should be chosen to
correspond to a threshold.
o In following figure AND arcs are indicated with a line connecting all the
components.

The AO* Algorithm


● Rather than the two lists, OPEN and CLOSED, that were used in the A* algorithm, the
AO* algorithm will use a single structure GRAPH, representing the part of the search
graph that has been explicitly generated so far.
● Each node in the graph will point both down to its immediate successors and up to
its immediate predecessors.
● Each node in the graph will also have associated with it an h' value, an estimate of
the cost of a path from itself to a set of solution nodes.
● We will not store g (the cost of getting from the start node to the current node) as
we did in the A* algorithm.
● And such a value is not necessary because of the top-down traversing of the edge
which guarantees that only nodes that are on the best path will ever be considered
for expansion.
Algorithm: AO*
1. Let GRAPH consist only of the node representing the initial state. Call this node INIT,
Compute VINIT.
2. Until INIT is labeled SOLVED or until INIT's h' value becomes greater than FUTILITY,
repeat the following procedure:
a. Trace the labeled arcs from INIT and select for expansion one of the as yet
unexpanded nodes that occurs on this path. Call the selected node NODE.
b. Generate the successors of NODE. If there are none, then assign FUTILITY as
the h' value of NODE. This is equivalent to saying that NODE is not solvable. If
there are successors, then for each one (called SUCCESSOR) that is not also
an ancestor of NODE do the following:
i. Add SUCCESSOR to GRAPH
ii. If SUCCESSOR is a terminal node, label it SOLVED and assign it an h'
value of 0
iii. If SUCCESSOR is not a terminal node, compute its h' value
c. Propagate the newly discovered information up the graph by doing the
following: Let S be a set of nodes that have been labeled SOLVED or whose h'
values have been changed and so need to have values propagated back to
their parents. Initialize S to NODE. Until S is empty, repeat the, following
procedure:
i. If possible, select from S a node none of whose descendants in GRAPH
occurs in S. If there is no such node, select any node from S. Call this
node CURRENT, and remove it from S.
ii. Compute the cost of each of the arcs emerging from CURRENT. The
cost of each arc is equal to the sum of the h' values of each of the
nodes at the end of the arc plus whatever the cost of the arc itself is.
Assign as CURRENT'S new h' value the minimum of the costs just
computed for the arcs emerging from it.
iii. Mark the best path out of CURRENT by marking the arc that had the
minimum cost as computed in the previous step.
iv. Mark CURRENT SOLVED if all of the nodes connected to it through the
new labeled arc have been labeled SOLVED.
v. If CURRENT has been labeled SOLVED or if the cost of CURRENT was
just changed, then its new status must be propagated back up the
graph. So add all of the ancestors of CURRENT to S.

VII. Constraint Satisfaction


● Constraint satisfaction is a search procedure that operates in a space of constraint sets. The
initial state contains the constraints that are originally given in the problem description.
● A goal state is any state that has been constrained “enough” where “enough” must be
defined for each problem.
● For example, in cryptarithmetic problems, enough means that each letter has been assigned
a unique numeric value.
● Constraint Satisfaction problems in AI have goal of discovering some problem state that
satisfies a given set of constraints.
● Design tasks can be viewed as constraint satisfaction problems in which a design must be
created within fixed limits on time, cost, and materials.
● Constraint Satisfaction is a two-step process:
1. First constraints are discovered and propagated as far as possible throughout the
system.
2. Then if there is still not a solution, search begins. A guess about something is made
and added as a new constraint.
Example: Cryptarithmetic Problem
Constraints:
• No two letters have the same value
• The sums of the digits must be as shown in the problem
Goal State:
• All letters have been assigned a digit in such a way that all the initial constraints are satisfied
Input State
● The solution process proceeds in cycles. At each cycle, two significant things are done:
1. Constraints are propagated by using rules that correspond to the properties of
arithmetic.
2. A value is guessed for some letter whose value is not yet determined.
Solution:

Algorithm: Constraint Satisfaction


1. Propagate available constraints. To do this first set OPEN to set of all objects that must
have values assigned to them in a complete solution. Then do until an inconsistency is
detected or until OPEN is empty:
a. Select an object OB from OPEN. Strengthen as much as possible the set of
constraints that apply to OB.
b. If this set is different from the set that was assigned the last time OB was
examined or if this is the first time OB has been examined, then add to OPEN
all objects that share any constraints with OB.
c. Remove OB from OPEN.
2. If the union of the constraints discovered above defines a solution, then quit and report
the solution.
3. If the union of the constraints discovered above defines a contradiction, then return the
failure.
4. If neither of the above occurs, then it is necessary to make a guess at something in order
to proceed. To do this loop until a solution is found or all possible solutions have been
eliminated:
a. Select an object whose value is not yet determined and select a way of
strengthening the constraints on that object.
b. Recursively invoke constraint satisfaction with the current set of constraints
augmented by strengthening constraint just selected.

VIII. Means-Ends Analysis


● Collection of strategies presented so far can reason either forward or backward, but for
a given problem, one direction or the other must be chosen.
● A mixture of the two directions is appropriate. Such a mixed strategy would make it
possible to solve the major parts of a problem first and then go back and solve the small
problems that arise in “gluing” the big pieces together.
● The technique of Means-Ends Analysis (MEA) allows us to do that.
● MEA process centers around the detection of differences between the current state and
the goal state.
● Once such a difference is isolated, an operator that can reduce the difference must be
found.
● If the operator cannot be applied to the current state, we set up a sub-problem of
getting to a state in which it can be applied.
● The kind of backward chaining in which operators are selected and then sub-goals are
set up to establish the preconditions of the operators is called operator sub-goaling
Algorithm: Means-Ends Analysis
1. Compare CURRENT to GOAL. If there are no differences between them then return.
2. Otherwise, select the most important difference and reduce it by doing the following
until success or failure is signaled:
a. Select an as yet untried operator O that is applicable to the current
difference. If there are no such operators, then signal failure.
b. Attempt to apply O to CURRENT. Generate descriptions of two states: O-
START, a state in which O’s preconditions are satisfied and O-RESULT, the
state that would result if O were applied in O-START.
c. If
(FIRST-PART 🡨 MEA( CURRENT, O-START))
and
(LAST-PART 🡨 MEA(O-RESULT, GOAL))
are successful, then signal success and return the result of concatenating
FIRST-PART, O, and LAST-PART.

Example of Mean-Ends Analysis:

example where we know the initial state and goal state as given below. In this problem, we need to get
the goal state by finding differences between the initial state and goal state and applying operators.
Solution:

To solve the above problem, we will first find the differences between initial states and goal states, and
for each difference, we will generate a new state and will apply the operators. The operators we have
for this problem are:

● Move

● Delete

● Expand

1. Evaluating the initial state: In the first step, we will evaluate the initial state and will compare the
initial and Goal state to find the differences between both states.

2. Applying Delete operator: As we can check the first difference is that in goal state there is no dot
symbol which is present in the initial state, so, first we will apply the Delete operator to remove this
dot.

3. Applying Move Operator: After applying the Delete operator, the new state occurs which we will
again compare with goal state. After comparing these states, there is another difference that is the
square is outside the circle, so, we will apply the Move Operator.
4. Applying Expand Operator: Now a new state is generated in the third step, and we will compare this
state with the goal state. After comparing the states there is still one difference which is the size of the
square, so, we will apply Expand operator, and finally, it will generate the goal state.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy