Chapter 2 Problem State Space Search Heuristic Search Techniques
Chapter 2 Problem State Space Search Heuristic Search Techniques
Prepared By:
Subject : AI
Asst. Prof. Twinkal Panchal
Code : 2180703 (CSE Department, ACET)
State Spaces
• One general formulation of intelligent action is in terms
of state space.
• A state contains all of the information necessary to predict the
effects of an action and to determine if it is a goal state.
The agent has perfect knowledge of the state space and can
observe what state it is in
The agent has a set of actions that have known deterministic
effects;
Some states are goal states, the agent wants to reach one of
these goal states, and the agent can recognize a goal state;
A solution is a sequence of actions that will get the agent from
its current state to a goal state.
A state-space problem consists of
• A set of states;
• A distinguished set of states called the start states;
• A set of actions available to the agent in each state;
• An action function that, given a state and an action, returns a
new state;
• A set of goal states, often specified as a Boolean
function, goal(s), that is true when s is a goal state; and
• A criterion that specifies the quality of an acceptable solution.
Water jug problem
For example,
Production System and Its Characteristics
2. Modularity
• This means production rule code the knowledge available in
discrete pieces. Information can be treated as a collection of
independent facts which may be added or deleted from the
system with essentially no delete side effects.
3. Modifiability
• This means the facility of modifying rules.
• It allows the development of production rules in a skeletal form
first and then it is accurate to suit a specific application.
4. Knowledge intensive
• knowledge base of production system stores pure knowledge.
• Each production rule is normally written as an English sentence;
the problem of semantics is solved by the very structure of the
representation.
Disadvantages
1. Opacity
• This problem is generated by the combination of production
rules. The opacity is generated because of less prioritization of
rules. More priority to a rule has the less opacity.
2. Inefficiency
• During execution of a program several rules may active. A
well devised control strategy reduces this problem.
• As the rules of the production system are large in number and
they are hardly written in hierarchical manner, it requires some
forms of complex search through all the production rules for
each cycle of control program.
3. Absence of learning
• Rule based production systems do not store the result of the
problem for future use.
• Hence, it does not exhibit any type of learning capabilities.
4. Conflict resolution
• The rules in a production system should not have any type of
conflict operations.
• When a new rule is added to a database, it should ensure that it
does not have any conflicts with the existing rules.
Types of Search Algorithms
Uninformed Search Algorithms
Example:
• Question. Which solution would DFS find to move from
node S to node G if run on the graph below?
Solution. The equivalent search tree for the above graph is as
follows. As DFS traverses the tree “deepest node first”, it would
always pick the deeper branch until it reaches the solution (or it
runs out of nodes, and goes to the next branch). The traversal is
shown in blue arrows.
Path: S -> A -> B -> C -> G
• Let = the depth of the search tree
= number of levels of the search tree.
= number of nodes in level .
Time complexity
• Equivalent to the number of nodes traversed in DFS.
Space complexity
• Equivalent to how large can the fringe get.
Completeness
• DFS is complete if the search tree is finite, meaning for a
given finite search tree, DFS will come up with a solution if it
exists.
Breadth First Search
• Breadth-first search (BFS) is an algorithm for traversing or
searching tree or graph data structures.
• It starts at the tree root, and explores all of the neighbor nodes
at the present depth prior to moving on to the nodes at the next
depth level.
Example:
• Question. Which solution would BFS find to move from
node S to node G if run on the graph below?
Solution. The equivalent search tree for the above graph is as
follows. As BFS traverses the tree “shallowest node first”, it
would always pick the shallower branch until it reaches the
solution (or it runs out of nodes, and goes to the next branch).
The traversal is shown in blue arrows.
Path: S -> D -> G
• Let =the depth of the shallowest solution.
= number of nodes in level .
Time complexity
• Equivalent to the number of nodes traversed in BFS until the
shallowest solution.
Space complexity
• Equivalent to how large can the fringe get.
Completeness
• BFS is complete, meaning for a given search tree, BFS will
come up with a solution if it exists.
Optimality
• BFS is optimal as long as the costs of all edges are equal.
Uniform Cost Search
• UCS is different from BFS and DFS because here the costs
come into play. In other words, traversing via different edges
might not have the same cost. The goal is to find a path where
the cumulative sum of costs is least.
• cost(node) = cumulative cost of all nodes from root cost(root)
=0
Example:
• Question. Which solution would UCS find to move from
node S to node G if run on the graph below?
Solution. The equivalent search tree for the above graph is as
follows. Cost of each node is the cumulative cost of reaching that
node from the root.
Path: S -> A -> B -> G
Cost: 5
Let = cost of solution.
= arcs cost.
Advantages
UCS is complete.
UCS is optimal.
Disadvantages
Explores options in every “direction”.
No information on goal location.
Informed Search Algorithms
• Here, the algorithms have information on the goal state, which
helps in more efficient searching. This information is obtained
by something called a heuristic.
• Greedy Search
• A* Tree Search
• A* Graph Search
2. Greedy approach
• Hill-climbing algorithm search moves in the direction which
optimizes the cost.
3. No backtracking
• It does not backtrack the search space, as it does not remember
the previous states.
State Space Diagram for Hill Climbing
• The state-space landscape is a graphical representation of the
hill-climbing algorithm which is showing a graph between
various states of algorithm and Objective function/Cost.
3. Exit.
Simulated Annealing
• A hill-climbing algorithm which never makes a move towards
a lower value guaranteed to be incomplete because it can get
stuck on a local maximum.
1. Local Maximum
• A local maximum is a peak state in the landscape which is
better than each of its neighboring states, but there is another
state also present which is higher than the local maximum.
2. Plateau
• A plateau is the flat area of the search space in which all the
neighbor states of the current state contains the same value,
because of this algorithm does not find any best direction to
move. A hill-climbing search might be lost in the plateau area.
3. Ridges
• A ridge is a special form of the local maximum.
• It has an area which is higher than its surrounding areas, but
itself has a slope, and cannot be reached in a single move.
Best-first Search Algorithm (Greedy Search)
Advantages
Best first search can switch between BFS and DFS by gaining
the advantages of both the algorithms.
Disadvantages
It can behave as an unguided depth-first search in the worst
case scenario.
This algorithm is not optimal.
A* Search Algorithm
• A* search is the most commonly known form of best-first
search. It uses heuristic function h(n), and cost to reach the
node n from the start state g(n).
• A* search algorithm finds the shortest path through the search
space using the heuristic function. This search algorithm
• expands less search tree and provides optimal result faster. A*
algorithm is similar to UCS except that it uses g(n)+h(n)
instead of g(n).
Algorithm of A* search
Disadvantages
It does not always produce the shortest path as it mostly based
on heuristics and approximation.
A* search algorithm has some complexity issues.
The main drawback of A* is memory requirement as it keeps
all generated nodes in the memory, so it is not practical for
various large-scale problems.
Example
Solution
• Initialization: {(S, 5)}
• Iteration1: {(S--> A, 4), (S-->G, 10)}
• Iteration2: {(S--> A-->C, 4), (S--> A-->B, 7), (S-->G, 10)}
• Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S-
-> A-->B, 7), (S-->G, 10)}
• Iteration 4 will give the final result, as S--->A--->C--->G it
provides the optimal path with cost 6.
Problem Reduction ( AND - OR graphs - AO *
Algorithm)
• When a problem can be divided into a set of sub problems,
where each sub problem can be solved separately and a
combination of these will be a solution, AND-OR graphs or
AND - OR trees are used for representing the solution.