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

UNIT 2 AI

Uploaded by

Sadhana Ganesan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

UNIT 2 AI

Uploaded by

Sadhana Ganesan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

MASTER OF COMPUTER APPLICATIONS

Subject Name : Artificial Intelligence Subject Code : MCC1854


Year / Sem : II / III Batch : 2023 – 2025

UNIT II – PROBLEM SOLVING METHODS

Problem solving Methods - Search Strategies- Uninformed - Informed - Heuristics – Local


Search Algorithms and Optimization Problems - Searching with Partial Observations -
Constraint Satisfaction Problems – Constraint Propagation - Backtracking Search

PROBLLEM SOLVING METHODS

In Artificial Intelligence, Search techniques are universal problem-solving methods.


Rational agents or Problem-solving agents in AI mostly used these search strategies or
algorithms to solve a specific problem and provide the best result. Problem-solving agents are
the goal-based agents and use atomic representation. In this topic, we will learn various
problem-solving search algorithms.

Problem formulation is the process of deciding what actions and states to consider,
given a goal. Goal formulation, based on the current situation and the agent‟s performance
measure, is the first step in problem solving. The process of looking for a sequence of actions
that reaches the goal is called search. A search algorithm takes a problem as input and returns
a solution in the form of an action sequence. Once a solution is found, the actions it
recommends can be carried out. This is called the execution phase. The process of removing
detail from a representation is called abstraction

Search Algorithm Terminologies :

 A State Space. Set of all possible states where you can be.
 Search: Searching is a step by step procedure to solve a search-problem in a given
search space. A search problem can have three main factors:
o Search Space: Search space represents a set of possible solutions, which a
system may have.
o Start State: It is a state from where agent begins the search.
o Goal test: It is a function which observe the current state and returns whether
the goal state is achieved or not.
 Search tree: A tree representation of search problem is called Search tree. The root of
the search tree is the root node which is corresponding to the initial state.
 Actions: It gives the description of all the available actions to the agent.
 Transition model: A description of what each action do, can be represented as a
transition model.
 Path Cost: It is a function which assigns a numeric cost to each path.
 Solution: It is an action sequence which leads from the start node to the goal node.
 Optimal Solution: If a solution has the lowest cost among all solutions.

Properties of Search Algorithms :

 Completeness: A search algorithm is said to be complete if it guarantees to return a


solution if at least any solution exists for any random input.

 Optimality: If a solution found for an algorithm is guaranteed to be the best solution


(lowest path cost) among all other solutions, then such a solution for is said to be an
optimal solution.
 Time Complexity: Time complexity is a measure of time for an algorithm to
complete its task.
 Space Complexity: It is the maximum storage space required at any point during the
search, as the complexity of the problem.

EXAMPLE PROBLEMS :
 Toy Problem
A toy problem is intended to illustrate or exercise various problem-solving methods.
It can be given a concise, exact description and hence is usable by different
researchers to compare the performance of algorithms
 Real World Problem
A real-world problem is one whose solutions people actually care about. Such
problems tend not to have a single agreed-upon description, but we can give the
general flavor of their formulations

Toy Problem

 Vaccum World Problem


 Ball Picker Robot Problem
 8 Puzzle
 8 Queens
 Crypt Arithmetic
 Missionaries and Cannibals
 Water Jug Problem

Real World Problem

 Route finding problem


 Travelling Salesperson Problem
 VLSI Layout Problem
 Robot Navigation
 Assembly Sequencing

State Space Search :

It is one of the major application of artificial intelligence of problem solving, that is


how to solve a particular problem. Problem solving is used to solve the problems like toy
problems has to be solved through machines like humans. In problem solving area, State
Space Search Searching is very important. It is necessary to represent the problem precisely.
Then we can easily analyse it.

Types of Search Algorithms :

 Uninformed search
 Informed search

Uninformed Search (Blind Search) :

The search algorithms in this section have no additional information on the goal node
other than the one provided in the problem definition. The plans to reach the goal state from
the start state differ only by the order and/or length of actions. Uninformed search is also
called Blind search. These algorithms can only generate the successors and differentiate
between the goal state and non goal state.

The uninformed search does not contain any domain knowledge such as closeness, the
location of the goal. It operates in a brute-force way as it only includes information about
how to traverse the tree and how to identify leaf and goal nodes. Uninformed search applies a
way in which search tree is searched without any information about the search space like
initial state operators and test for the goal, so it is also called blind search. It examines each
node of the tree until it achieves the goal node.

Each of these algorithms will have:

 A problem graph, containing the start node S and the goal node G.
 A strategy, describing the manner in which the graph will be traversed to get to G.
 A fringe, which is a data structure used to store all the possible states (nodes) that you
can go from the current states.
 A tree, that results while traversing to the goal node.
 A solution plan, which the sequence of nodes from S to G.

Types of Search under Uninformed Search Algorithms :

 Breadth-first search
 Depth-first search
 Depth Limited Search
 Uniform cost search
 Iterative deepening depth-first search
 Bidirectional Search

Informed Search (Heuristic Search) :

Informed search algorithms use domain knowledge. In an informed search, problem


information is available which can guide the search. Informed search strategies can find a
solution more efficiently than an uninformed search strategy. Informed search is also called a
Heuristic search.
A heuristic is a way which might not always be guaranteed for best solutions but
guaranteed to find a good solution in reasonable time. Informed search can solve much
complex problem which could not be solved in another way.

Types of Informed Search Algorithms :

 Greedy best first search


 A* Search
 Memory bounded heuristic search
 Recursive best first search
 Simplified memory-bounded A*

Difference Between Uninformed and Informed Search

Parameters Informed Search Uninformed Search


Knowledge It applies knowledge during the It does not use any knowledge
Utilization search process. during the search process.
Speed It finds solutions faster. It finds solutions at a slower pace.
Completion It can be both complete and It is always complete.
incomplete.
Time Consumption It consumes less time due to faster It takes more time due to slower
searches. searches.
Cost Incurred It incurs lower costs. It incurs higher costs.
Guidance The AI receives suggestions on The AI does not receive any
how and where to find solutions. suggestions on finding solutions. It
relies on the information provided.
Efficiency It is more efficient due to lower It is less efficient due to higher
costs and faster results. costs and slower results.
Implementation It has a shorter implementation It has a lengthier implementation
Length period. period.
Examples Examples include A* Search and Examples include Uniform-Cost
Best-First Search. Search and Iterative Deepening
Search.

UNINFORMED SEARCH ALGORITHMS

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 (or some arbitrary node of a graph, sometimes referred
to as a „search key‟), and explores all of the neighbor nodes at the present depth prior to
moving on to the nodes at the next depth level. It is implemented using a queue.

Breadth-first search is the most common search strategy for traversing a tree or graph.
This algorithm searches breadthwise in a tree or graph, so it is called breadth-first search.
BFS algorithm starts searching from the root node of the tree and expands all successor node
at the current level before moving to nodes of next level. The breadth-first search algorithm is
an example of a general-graph search algorithm. Breadth-first search implemented using
FIFO queue data structure

Procedure:

In BFS root node is expanded first, then all the successor of root node are expanded
and then their successor and so on. That is the nodes are expanded level wise starting at root
level.

Implementation:

BFS can be implemented using first, in first out queue data structure where fringe will be
stored and processed. As soon as node is visited it is added to queue. All newly generated
nodes are added to the end of the queue, which means that shallow nodes are expanded
before deeper nodes.

Algorithm :

function BREADTH-FIRST-SEARCH(problem) returns a solution, or failure

node ←a node with STATE = problem.INITIAL-STATE, PATH-COST = 0

if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)

frontier ← a FIFO queue with node as the only element

explored ← an empty set

loop do

if EMPTY?(frontier ) then return failure

node ← POP(frontier ) /* chooses the shallowest node in frontier */

add node.STATE to explored

for each action in problem.ACTIONS(node.STATE) do

child ← CHILD-NODE(problem, node, action)

if child.STATE is not in explored or frontier then

if problem.GOAL-TEST(child.STATE) then return SOLUTION(child)

frontier ← INSERT(child,frontier )
Performance Measures :

 Time Complexity: Time Complexity of BFS algorithm can be obtained by the number
of nodes traversed in BFS until the shallowest Node. Where the d= depth of
shallowest solution and b is a node at every state.

T (b) = 1+b2+b3+.......+ bd= O (bd)

 Space Complexity: Space complexity of BFS algorithm is given by the Memory size
of frontier which is O(bd).
 Completeness: BFS is complete, which means if the shallowest goal node is at some
finite depth, then BFS will find a solution.
 Optimality: BFS is optimal if path cost is a non-decreasing function of the depth of
the node.

Advantages:

 BFS will provide a solution if any solution exists.


 If there are more than one solutions for a given problem, then BFS will provide the
minimal solution which requires the least number of steps.

Disadvantages

 It requires lots of memory since each level of the tree must be saved into memory to
expand the next level.
 BFS needs lots of time if the solution is far away from the root node.

Depth First Search

Depth-first search is a recursive algorithm for traversing a tree or graph data structure.
It is called the depth-first search because it starts from the root node and follows each path to
its greatest depth node before moving to the next path. DFS uses a stack data structure for its
implementation. The process of the DFS algorithm is similar to the BFS algorithm.

The algorithm starts at the root node (selecting some arbitrary node as the root node in
the case of a graph) and explores as far as possible along each branch before backtracking. It
uses last in- first-out strategy and hence it is implemented using a stack.

Procedure :

Depth-first search always expands the deepest node in the current unexplored node set
(fringe) of the search tree. The search goes in to depth until there is no more successor node.
As these nodes are expanded, they are dropped from the fringe, so then the search "backs up"
to the next shallowest node (previous level node) that still has unexplored successors.
Implementation :

DFS can be implemented with stack (LIFO) data structure which will explore the
latest added node first, suspending exploration of all previous nodes on the path. This can be
done using recursive procedure that calls itself on each of the children in turn.

Algorithm :

function findPath(robot, start, goal):


stack ← empty stack
visited ← empty set
stack.push(start)
while not stack.isEmpty( ):
current ← stack.pop( )
if current == goal:
return "Path found"
visited.add(current)
neighbors ← robot.getNeighbors(current)
for neighbor in neighbors:
if neighbor not in visted:
stack.push(neighbor)
return "Path not found"

Performance Measures :

 Completeness: DFS search algorithm is complete within finite state space as it will
expand every node within a limited search tree.
 Time Complexity: Time complexity of DFS will be equivalent to the node traversed
by the algorithm. It is given by:

T(n)= 1+ n2+ n3 +.........+ nm=O(nm)

Where, m= maximum depth of any node and this can be much larger than d
(Shallowest solution depth)

 Space Complexity: DFS algorithm needs to store only single path from the root node,
hence space complexity of DFS is equivalent to the size of the fringe set, which is
O(bm).
 Optimal: DFS search algorithm is non-optimal, as it may generate a large number of
steps or high cost to reach to the goal node.
Advantages:

 DFS requires very less memory as it only needs to store a stack of the nodes on the
path from root node to the current node.
 It takes less time to reach to the goal node than BFS algorithm (if it traverses in the
right path).

Disadvantage:

 There is the possibility that many states keep re-occurring, and there is no guarantee
of finding the solution.
 DFS algorithm goes for deep down searching and sometime it may go to the infinite
loop.

Depth Limited Search

A depth-limited search algorithm is similar to depth-first search with a predetermined


limit. Depth-limited search can solve the drawback of the infinite path in the Depth-first
search. In this algorithm, the node at the depth limit will treat as it has no successor nodes
further.

Depth-limited search can be terminated with two Conditions of failure:

 Standard failure value: It indicates that problem does not have any solution.
 Cutoff failure value: It defines no solution for the problem within a given depth limit.

Procedure :

If we can limit the depth of search tree to a certain level then searching will be more
efficient. This removes the problem of unbounded trees. Such a kind of depth first search
where in the depth is limited at a certain level is called as depth limited search. It solves
infinite path problem.

Implementation :

Same as DFS but limited to depth level 1. DLS will terminate with two kinds of
failure. The standard failure value indicates no solution and the cut-off value indicates no
solution within the depth limit.
Algorithm :

function DEPTH-LIMITED-SEARCH(problem, limit) returns a solution, or failure/cutoff

return RECURSIVE-DLS(MAKE-NODE(problem.INITIAL-STATE), problem, limit)

function RECURSIVE-DLS(node, problem, limit) returns a solution, or failure/cutoff

if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)

else if limit = 0 then return cutoff

else

cutoff occurred?←false

for each action in problem.ACTIONS(node.STATE) do

child ← CHILD-NODE(problem, node, action)

result ← RECURSIVE-DLS(child, problem, limit − 1)

if result = cutoff then cutoff occurred?← true

else if result = failure then return result

if cutoff occurred? then return cutoff else return failure

Performance Measures :

 Completeness: DLS search algorithm is complete if the solution is above the depth-
limit.
 Time Complexity: Time complexity of DLS algorithm is O(bℓ).
 Space Complexity: Space complexity of DLS algorithm is O(b×ℓ).
 Optimal: Depth-limited search can be viewed as a special case of DFS, and it is also
not optimal even if ℓ>d.

Advantages:

 Depth-limited search is Memory efficient.

Disadvantages:

 Depth-limited search also has a disadvantage of incompleteness.


 It may not be optimal if the problem has more than one solution.

Uniform Cost Search


Uniform-cost search is a searching algorithm used for traversing a weighted tree or
graph. This algorithm comes into play when a different cost is available for each edge. The
primary goal of the uniform-cost search is to find a path to the goal node which has the
lowest cumulative cost. Uniform-cost search expands nodes according to their path costs
form the root node. It can be used to solve any graph/tree where the optimal cost is in
demand. A uniform-cost search algorithm is implemented by the priority queue. It gives
maximum priority to the lowest cumulative cost. Uniform cost search is equivalent to BFS
algorithm if the path cost of all edges is the same.

Procedure:

Uniform cost search expands the node. 'n' with the lowest path cost. Uniform cost search
does not care about the number of steps a path has, instead it considers their total cost.
Therefore, their is a chance of getting stuck in an infinite loop if it ever expands a node that
has a zero-cost action leading back to the same state.

Implementation :

We can use queue data structure for storing fringe as in BFS. The major difference will be
while adding the node to queue, we will give priority to the node with lowest pathcost. (So
the data structure will be a priority queue)

Algorithm :

function UNIFORM-COST-SEARCH(problem) returns a solution, or failure

node ←a node with STATE = problem.INITIAL-STATE, PATH-COST = 0

frontier ← a priority queue ordered by PATH-COST, with node as the only element

explored ← an empty set

loop do

if EMPTY?(frontier ) then return failure

node ← POP(frontier ) /* chooses the lowest-cost node in frontier */

if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)

add node.STATE to explored

for each action in problem.ACTIONS(node.STATE) do

child ← CHILD-NODE(problem, node, action)

if child.STATE is not in explored or frontier then

frontier ← INSERT(child,frontier )

else if child.STATE is in frontier with higher PATH-COST then

replace that frontier node with child


Performance Measures :

 Completeness :
Uniform-cost search is complete, such as if there is a solution, UCS will find it.
 Time Complexity:
Let C* is Cost of the optimal solution, and ε is each step to get closer to the goal
node. Then the number of steps is = C*/ε+1. Here we have taken +1, as we start from state 0
and end to C*/ε. Hence, the worst-case time complexity of Uniform-cost search is O(b1 +
[C*/ε]
)/.
 Space Complexity:
The same logic is for space complexity so, the worst-case space complexity of
Uniform-cost search is O(b1 + [C*/ε]).
 Optimal :
Uniform-cost search is always optimal as it only selects a path with the lowest path
cost.

Advantages:

Uniform cost search is optimal because at every state the path with the least cost is
chosen.

Disadvantages:

It does not care about the number of steps involve in searching and only concerned
about path cost. Due to which this algorithm may be stuck in an infinite loop.

Iterative Deepening Depth First Search

The iterative deepening algorithm is a combination of DFS and BFS algorithms. This
search algorithm finds out the best depth limit and does it by gradually increasing the limit
until a goal is found. This algorithm performs depth-first search up to a certain "depth limit",
and it keeps increasing the depth limit after each iteration until the goal node is found. This
Search algorithm combines the benefits of Breadth-first search's fast search and depth-first
search's memory efficiency. The iterative search algorithm is useful uninformed search when
search space is large, and depth of goal node is unknown.

Procedure :

In iterative deepening depth-first search, dfs is applied along with the best depth limit.
In each step gradually it increases the depth limit until the goal is found. It increases depth
limit from level 0, then level 1, then level 2 till the shallowest goal is found at certain depth
'd'.

Implementation :

Iterative deepening depth first search can be implemented similar to BFS (where
queue is used for storing fringe) because it explores a complete layer of new nodes at each
iteration before going on to the next layer.
If we want to avoid memory requirements which are incurred in BFS then IDDFS can
be implemented like uniform-cost search. The key point is to use increasing path-cost limits
instead of increasing depth limits, is if we have such a implementations it is termed as
iterative lengthen search.

Algorithm :

function ITERATIVE-DEEPENING-SEARCH(problem) returns a solution, or failure

for depth = 0 to ∞ do

result ← DEPTH-LIMITED-SEARCH(problem, depth)

if result ≠ cutoff then return result

Performance Measures :

 Completeness - This algorithm is complete is if the branching factor is finite.


 Time Complexity - Let's suppose b is the branching factor and depth is d then the
worst-case time complexity is O(bd).
 Space Complexity - The space complexity of IDDFS will be O(bd).
 Optimal - IDDFS algorithm is optimal if path cost is a non- decreasing function of the
depth of the node.

Advantages:

 It combines the benefits of BFS and DFS search algorithm in terms of fast search and
memory efficiency.

Disadvantages:

 The main drawback of IDDFS is that it repeats all the work of the previous phase.

Bidirectional Search Algorithm

Bidirectional search algorithm runs two simultaneous searches, one form initial state
called as forward-search and other from goal node called as backward-search, to find the goal
node. Bidirectional search replaces one single search graph with two small subgraphs in
which one starts the search from an initial vertex and other starts from goal vertex. The
search stops when these two graphs intersect each other. Bidirectional search can use search
techniques such as BFS, DFS, DLS, etc.

Procedure :

As the name suggests bi-directional that is two directional searches are made in this
searching technique. One is the forward search which starts from initial state and the other is
the backward search which starts from goal state. The two searches stop when both the
searches meet in the middle

Implementation :

Bidirectional search is implemented by having one or both of the searches check, each
node before it is expanded, is examined to see if it is in the fringe of the other search tree. If
so solution is found. Fringe can be maintained in queue data structure, like BFS.

Schematic View of Bidirectional Search :

Performance Measures :

 Completeness: Bidirectional Search is complete if we use BFS in both searches.


 Time Complexity: Time complexity of bidirectional search using BFS is O(bd).
 Space Complexity: Space complexity of bidirectional search is O(bd).
 Optimal: Bidirectional search is Optimal.

Advantages:

 Bidirectional search is fast.


 Bidirectional search requires less memory

Disadvantages:

 Implementation of the bidirectional search tree is difficult.


 In bidirectional search, one should know the goal state in advance.
INFORMED SEARCH STRATEGIES

Heuristic Function

There are many different algorithms which employ the concept of best first search.
The main difference between all the algorithms is that they have different evaluation
function. The central component of these algorithms is heuristic function - h(n) which is
defined as, h(n) = estimate cost of the cheapest path from node 'n' to a goal node.

h(n) <= h*(n)

Where,
h(n) – Heuristic Cost
h*(n) – Estimated Cost

Note

1) Heuristic function is key component of best first search. It is denoted by h(n) and
h(n) = The shortest and cheapest path from initial node to goal node.

2) One can give additional knowledge about the problem to the heuristic function. For
example - In our problem of Pune-Chennai route we can give information about distances
between cities to the heuristic function.

3) A heuristic function guide the search in an efficient way.

4) A heuristic function h(n) consider a node as input but it rely only on the state at that
node.

5) h(n) = 0, if n is goal state.

Best First Search :

Procedure :

1) Search will start at root node.

2) The node to be expanded next is selected on the basis of an evaluation function,


f(n).
3) The node having lowest value for f(n) is selected first. This lowest value of f(n)
indicates that goal is nearest from this node (that is f(n) indicates distance from current node
to goal node).

Heuristic Function :

f(n) = h(n)

f(n) - a node is selected for expansion based on an evaluation function. We expand the node
that is closest to the goal node, and the closest cost is estimated by this Heuristic function

h(n) - estimated cost from node n to the goal, if n is a goal node, then h(n)=0

Implementation:

BFS can be implemented using priority queue where fringe will be stored. The nodes
in fringe will be stored in priority queue with increasing value of f(n) i.e. ascending order of
f(n). The high priority will be given to node which has low f(n) value.

As name says "best first" then, we would always expect to have optimal solution. But
in general BFS indicates that choose the node that appears to be best according to the
evaluation function. Hence the optimality based on 'best-ness' of evaluation function.

Steps for Best First Search :

1. Use two ordered lists OPEN and CLOSED.

2. Start with the initial node 'n' and put it on the ordered list OPEN.

3. Create a list CLOSED. This is initially an empty list.

4. If OPEN is empty then exit with failure.

5. Select first node on OPEN. Remove it from OPEN and put it on CLOSED. Call this
node n.

6. If 'n' is the goal node exit. The solution is obtained by tracing a path backward along
the arcs in the tree from 'n' to 'n1'.

7. Expand node 'n'. This will generate successors. Let the set of successors generated, be
S. Create arcs from 'n' to each member of S.

8. Reorder the list OPEN, according to the heuristic and go back to step 4.

Greedy Best First Search


Greedy best first search expand the node that is closest to the goal, expecting to get solution
quickly:

 It evaluates node by using the heuristic function f(n) = h(n).


 It is termed as greedy (asking for more) because at each step it tries to get as close to
the goal as it can.
 GBFS resembles DFS in the way that it prefers to follow a single path all the way to
the goal. It back tracks when it comes to dead end that is, to a node from which goal
state cannot be reached.
 Choosing minimum h(n) can lead to bad start as it may not yield always a solution.
Also as this exploration is not leading to solution, therefore unwanted nodes are
getting expanded.
 In GBFS, if repeated states are not detected then the solution will never found.

Heuristic Function :
f(n) = h(n)

f(n) - a node is selected for expansion based on an evaluation function. We expand the node
that is closest to the goal node, and the closest cost is estimated by this Heuristic function

h(n) - estimated cost from node n to the goal. Lower the value of h(n), closer is the node
from the goal.

Performance measurement

 Completeness: It is incomplete as it can start down an infinite path and never return to
try other possibilities which can give solution.
 Optimal: It is not optimal as it can initially select low value h(n) node but it may
happen that some greater value node in current fringe can lead to better solution.
Greedy strategies, in general, suffers from this, "looking for current best they loose on
future best and in turn finally the best solution" !
 Time and space complexity: Worst case time and space complexity is 0 (bm) where 'm'
is the maximum depth of the search space.
 The complexity can be reduced by devicing good heuristic function.
A* Search

A* Search, combines the strengths of uniform-cost search and greedy search. In this
search, the heuristic is the summation of the cost in Uniform Cost Search, denoted by g(x),
and the cost in the greedy search, denoted by h(x). The summed cost is denoted by f(x). A* is
most popular form of best first search.

Heuristic Function :

f(n)=g(n) + h(n)

A* evaluates node based on two functions namely

 g(n) - The cost to reach the node 'n'.


 h(n) - The cost to reach the goal node from node 'n'.
 f(n) = Estimated cost of the cheapest solution through 'n'.

Working of A*

1) The algorithm maintains two sets.

 OPEN list: The OPEN list keeps track of those nodes that need to be examined.
 b) CLOSED list: The CLOSED list keeps track of nodes that have already been
examined.

2) Initially, the OPEN list contains just the initial node, and the CLOSED list is empty. Each
node n maintains the following: g(n), h(1 h(n), f(n) as described above.

3) Each node also maintains a pointer to its parent, so that later the best solution, if found, can
be retrieved. A* has a main loop that repeatedly gets the node, call it 'n', with the lowest f(n)
value from the OPEN list. If 'n' is the goal node, then we are done, and the solution is given
by backtracking from 'n'. Otherwise, 'n' is removed from the OPEN list and added to the
CLOSED list. Next all the possible TSV successor nodes of 'n' are generated.

4) For each successor node 'n', if it is already in the CLOSED list and the copy there has an
equal or lower 'f' estimate, and then we can safely discard the newly generated 'n' and move
on. Similarly, if 'n' is already in the OPEN list and the copy there has an equal or lower f
estimate, we can discard the newly generated n and move on.
5) If no better version of 'n' exists on either the CLOSED or OPEN lists, we remove the
inferior copies from the two lists and set 'n' as the parent of 'n'. We also have to calculate the
cost estimates for n as follows:

 Set g(n) which is g(n) plus the cost of getting from n to n;


 Set h(n) is the heuristic estimate of getting from n to the goal node;
 Set f(n) is g(n) + h(n)

6) Lastly, add 'n' to the OPEN list and return to the beginning of the main loop.

Performance measurement for A*

1) Completeness: A* is complete and guarantees solution.

2) Optimality: A* is optimal if h(n) is admissible heuristic. Admissible heuristic means h(n)


never over estimates the cost to reach the goal. Tree-search algorithm gives optimal solution
if h(n) is admissible.

If we put extra requirement on h(n) which is consistency also called as monotonicity


then we are sure expect the optimal solution. A heuristic function h(n) is said to be consistent,
if, for every node 'n' and every successor 'ns' of 'n' generated by action 'a', the estimated cost
of reaching the goal from 'n' is not greater than the step cost of getting to 'ns'.

 h(n) ≤ cost (n, a, ns) + h (ns)


 A* using graph-search is optimal if h(n) is consistent.

Note: The sequence of nodes expanded by A* using graph-search is in, increasing order of
f(n). Therefore the first goal node selected for expansion must be an optimal solution because
all latter nodes will be either having same value of f(n) (same expense) or greater value of
f(n) (more expensive) than currently expanded node.

 A* never expands nodes with f(n) > C* (where C* is the cost of optimal solution).
 A* algorithm also do pruning of certain nodes.
 Pruning means ignoring a node completely without any examination of that node, and
thereby ignoring all the possibilities arising from these node.

3) Time and space complexity: If number of nodes reaching to goal node grows exponentially
then time taken by A* eventually increases.
 The main problem area of A* is memory, because A* keeps all generated nodes in
memory.
 A* usually runs out of space long before it runs out of time.
 A* optimality proof
 Assume A* finds the (sub optimal) goal G2 and the optimal goal is G.
 Since h is admissible
o h'(G2) = h (G) = 0
 Since G2 is not optimal
o f(G2) > f(G)
 At some point during the search, some node 'n' on the optimal path to G is not
expanded.
 We know, f(n) f(G)

MEMORY BOUNDED HEURISTIC SEARCH

Memory-bounded search strategies are necessary because AI systems often encounter


constrained memory resources in real-world circumstances. The notion of memory-bound
search, often referred to as memory-bounded heuristic search, is examined in this article
along with its importance in AI applications.

When memory resources are restricted, AI uses a method called memory-bound


search to solve issues and make judgments quickly.

Memory-bound search algorithms, on the other hand, are created with the limitation
of finite memory in mind. The goal of these algorithms is to effectively use the memory that
is available while finding optimum or nearly optimal solutions. They do this by deciding
which information to keep and retrieve strategically, as well as by using heuristic functions to
direct the search process.

Search Algorithms :

 Iterative Deepening A*
 Recursive Best First Search (RBFS)
 MA*
 AO*
Iterative deepening A*

Iterative deepening A* (IDA*) is a graph traversal and path-finding method that can
determine the shortest route in a weighted graph between a defined start node and any one of
a group of goal nodes. It is a kind of iterative deepening depth-first search that adopts the A*
search algorithm‟s idea of using a heuristic function to assess the remaining cost to reach the
goal.

A memory-limited version of A* is called IDA*. It performs all operations that A*


does and has optimal features for locating the shortest path, but it occupies less memory.

Iterative Deepening A Star uses a heuristic to choose which nodes to explore and at
which depth to stop, as opposed to Iterative Deepening DFS, which utilizes simple depth to
determine when to end the current iteration and continue with a higher depth.

 It reduces memory requirements, incurred in A*, thereby putting bound on memory


hence it is called as memory bounded algorithm.
 IDA* suffers from real value costs of the problem.
 The graph traversal algorithm.
 Find the shortest path in a weighted graph between the start and goal nodes using the
path search algorithm.
 An alternative to the iterative depth-first search algorithm.
 Uses a heuristic function, which is a technique taken from A* algorithm.
 It‟s a Depth-First Search algorithm, So it used less memory than the A* algorithm.
 IDA* is an admissible heuristic because it never overestimates the cost of reaching
the goal.
 It‟s focused on searching the most promising nodes, so, it doesn‟t go to the same
depth everywhere.

Heuristic :

f(n) = g(n) + h(n)

f(n) = Total cost evaluation function.

g(n) = The actual cost from the initial node to the current node.

h(n) = Heuristic estimated cost from the current node to the goal state. it is based on the
approximation according to the problem characteristics.
Procedure :

Step 1: Initialization - Set the root node as the current node, and find the f-score.

Sep 2: Set threshold - Set the cost limit as a threshold for a node i.e the maximum f-score
allowed for that node for further explorations.

Step 3: Node Expansion - Expand the current node to its children and find f-scores.

Step 4: Pruning - If for any node the f-score > threshold, prune that node because it‟s
considered too expensive for that node. and store it in the visited node list.

Step 5: Return Path - If the Goal node is found then return the path from the start node Goal
node.

Step 6: Update the Threshold - If the Goal node is not found then repeat from step 2 by
changing the threshold with the minimum pruned value from the visited node list. And
Continue it until you reach the goal node.

Advantages

 IDA* is guaranteed to find the optimal solution if one exists.


 IDA* avoids the exponential time complexity of traditional Depth First Search. by
using an “iterative deepening” approach, where the search depth is gradually
increased.
 IDA* uses a limited amount of memory as compared to the A* algorithm because it
uses Depth First Search.
 IDA* is an admissible heuristic, it never overestimates the cost of reaching the goal.
 It‟s efficient in handling large numbers of states and large branch factors.

Disadvantages

 Explore the visited node again and again. it doesn‟t keep track of the visited nodes.
 IDA* may be slower to get a solution than other search algorithms like A* or
Breadth-First Search because it explores and repeats the explore node again and
again.
 It takes more time and power than the A* algorithm.
Difference Between iterative depth-first search algorithms. and IDA* algorithm

Iterative depth-first search Iterative deepening A* (IDA*)


algorithms(IDDFS)
Systematic Not Systematic
Optimal Optimal but never expands the node where
f-score > Threshold
Never expands the same node twice Expands the same node many times if f-
score < Threshold
Not good for infinite Search traversal For infinite Search traversal, it is better than
IDDFS.

Recursive Best First Search (RBFS)

 It works like best first search but using only linear space.
 Its structure is similar to recursive DFS but instead of continuing indefinitely down
the current path it keeps track of the F value of the best alternative path available from
any ancestor of the current node.
 The recursion procedure is unwinded back to the alternative path if the current node
crosses limit.
 The important property of RBFS is that it remembers the f-value of the best leaf in the
forgotten subtree (previously left unexpanded). That is, it is able to take decision
regarding re-expanding the subtree.
 It is reliable, cost effective than IDA but its critical problem is excessive node
generation.

Performance measure

 Completeness: It is complete.
 Optimality: Recursive best-first search is optimal if h(n) is admissible.
 Time and space complexity: Time complexity of RBFS depends on two factors –
o Accuracy of heuristic function.
o How often (frequently) the best path changes as nodes are expanded.
 RBFS suffers from problem of expanding repeated states, as the algorithm fails to
detect them.
 Its space complexity is O(bd).
Its suffers from problem of using too little (very less) memory. Between iterations, RBFS
maintains more information in memory but it uses only O(bd) memory. If more memory is
available then also RBFS cannot utilize it.

MA*

RBFS under utilizes memory. To overcome this problem MA* is deviced.

Its more simplified version called as simplified MA* proceeds as follows -

 If expands the best leaf until memory is full.


 At this point it cannot add new node to the search tree without dropping an oldone.
 It always drops the node with highest f-value.
 If goal is not reached then it backtracks and go to the alternative path. In this way the
ancestor of a forgotten subtree knows the quality of the best path in that subtree.
 While selecting the node for expansion it may happen that two nodes are with same f-
value. Some problem arises, when the node is discarded (multiple choices can be
there as many leaves can have same f-value).
 The SMA* generates new best node and new worst node for expansion and deletion
respectively.

Performance measurement

 Completeness: SMA* is complete and guarantee solution.


 Optimality: If solution is reachable through optimal path it gives optimal solution.
Otherwise it returns best reachable solution.
 Time and space complexity: There is memory limitations on SMA*. Therefore it has
to switch back and forth continually between a set of candidate solution paths, only
small subset of which can fit in memory. This problem is called as thrashing because
of which algorithm takes more time.

Extra time is required for repeated regeneration of the same nodes, means that the problem
that would be practically solvable by A* (with unlimited memory) became intractable for
SMA*.

It means that memory restrictions can make a problem intractable from the point of view of
computation time.
AO* Algorithm

Best-first search is what the AO* algorithm does. The AO* method divides any given
difficult problem into a smaller group of problems that are then resolved using the AND-OR
graph concept. AND OR graphs are specialized graphs that are used in problems that can be
divided into smaller problems. The AND side of the graph represents a set of tasks that must
be completed to achieve the main goal, while the OR side of the graph represents different
methods for accomplishing the same main goal.

In the above figure, the buying of a car may be broken down into smaller problems or
tasks that can be accomplished to achieve the main goal in the above figure, which is an
example of a simple AND-OR graph. The other task is to either steal a car that will help us
accomplish the main goal or use your own money to purchase a car that will accomplish the
main goal. The AND symbol is used to indicate the AND part of the graphs, which refers to
the need that all subproblems containing the AND to be resolved before the preceding node
or issue may be finished.

The start state and the target state are already known in the knowledge-based search
strategy known as the AO* algorithm, and the best path is identified by heuristics. The
informed search technique considerably reduces the algorithm‟s time complexity. The AO*
algorithm is far more effective in searching AND-OR trees than the A* algorithm.

Heuristic :

f(n) = g(n) + h(n)

f(n) = Actual cost + Estimated


cost
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the current node.

h(n) = estimated cost from the current node to the goal state.

Difference Between A* and AO* Algorithm

A* Algorithm AO* Algorithm


Adaptability to Changing Not designed for handling Specifically designed to
Environments changes in the environment adapt to changes without
initiating a new search.
OR-AND Operation Primarily uses the AND Uses both OR and AND
Combination operation considering one operations exploring multiple
path at a time. paths simultaneously.
Resource Utilization Generally more resource- May explore more nodes due
efficient, explores fewer to adaptability, potentially
nodes. requiring more
computational resources.
Planning for Uncertainty Less suited for high Excels in situations with
uncertainty or frequent uncertainty, quickly adjusting
environmental changes. plans in response to new
information.
Search Restart Requirement Requires a complete restart Eliminates the need for a full
of the search after an restart, saving time and
environmental change. computational resources
when changes occur.
Scenario Suitability Well-suited for static Particularly beneficial in
environments with consistent dynamic environments where
node costs. conditions or costs may
change over time.
Robustness to Changes May struggle in Handles changes seamlessly,
environments subject to ensuring that plans remain
frequent alterations. effective even as the
environment evolves .
Real-time Applications Excels in situations with Can be employed in real-
uncertainty, quickly adjusting time applications,
plans in response to new particularly beneficial in
information. scenarios with dynamic,
changing elements.
Memory Usage It uses less memory due to May use more memory due
exploring fewer nodes. to adaptability, potentially
needing to remember
additional information about
explored paths.
Consistency of Heuristic Requires a consistent Does not strictly require a
heuristic for optimality consistent heuristic,
guarantees. allowing for more flexibility
in heuristic choice.
Heuristic Function and their Nature :

1.Accuracy of Heuristic Function

 More accurate the heuristic function more is the performance.


 The quality of heuristic function can be measured by the effective branching factor
b*.
 Consider A* that generates N nodes and 'd' is depth of a solution, then b* is the qulay
branching factor that a uniform tree of depth 'd' would have so as to contain 'n+1'
nodes.

Thus,

N+1 = 1 + b* + (b*)2 + ... + (b*)d

 If A* finds a solution at depth 5 using 52 nodes, then the effective branching factor is
1.92.
 A well designed heuristic function will have a value of b* close to 1, allowing fairly
large problems to be solved.

LOCAL SEARCH AND OPTIMIZATION PROBLEMS

The search algorithms we have seen so far, more often concentrate on path through
which the goal is reached. But if the problem does not demand the path of the solution
and it expects only the final configuration of the solution then we have different types of
problem to solve.

Following are the problems where only solution state configuration is important and
not the path which has arrived at solution.

 8-queen (where only solution state configuration is expected).


 Integrated circuit design.
 Factory-floor layout.
 Job-shop scheduling.
 Automatic programming.
 Telecommunication network optimization.
 Vehicle routing.
 Portfolio management.

If we have such type of problem then we can have another class of algorithms, the
algorithms that do not worry about the paths at all. These are local search algorithms.

Local Search Algorithms

 They operate using single state. (rather than multiple paths).


 They generally move to neighbours of the current state.
 There is no such requirement of maintaining paths in memory.
 They are not "Systematic" algorithm procedure.

The main advantages of local search algorithm are

 They use very little and constant amount of memory.


 They have ability to find resonable solution for infinite state spaces (for which
systematic algorithms are unsuitable).

Local search algorithms are useful for solving pure optimization problems. In pure
optimization problems main aim is to find the best state according to required objective
function.

Local search algorithm make use of concept called as state space landscape. This
landscape has two structures -

1) Location (defined by the state)

2) Elevation (defined by the value of the heuristic cost function or objective function).

 If elevation corresponds to the cost, then the aim is to find the lowest valley - (a
global minimum).
 If elevation corresponds to the objective function then aim is to find the highest peak -
(a global maximum).
 Local search algorithms explore the landscape.

Performance Measurement

 Local search is complete i.e. it surely finds goal if one exists.


 Local search is optimal as it always find global minimum or maximum.
Types of Algorithms :

 Hill Climbing Search


 Simulated Annealing Search
 Local Beam Search
 Stochastic Beam Search
 Genetic Algorithm

Hill Climbing Search

Hill climbing algorithm is a local search algorithm which continuously moves in the
direction of increasing elevation/value to find the peak of the mountain or best solution to the
problem. It terminates when it reaches a peak value where no neighbor has a higher value.

Hill climbing algorithm is a technique which is used for optimizing the mathematical
problems. One of the widely discussed examples of Hill climbing algorithm is Traveling-
salesman Problem in which we need to minimize the distance traveled by the salesman. It is
also called greedy local search as it only looks to its good immediate neighbor state and not
beyond that. A node of hill climbing algorithm has two components which are state and
value. Hill Climbing is mostly used when a good heuristic is available. In this algorithm, we
don't need to maintain and handle the search tree or graph as it only keeps a single current
state.

 This algorithm generally moves up in the direction of increasing value that is-uphill. It
breaks its "moving up loop" when it reaches a "peak" where no neighbour has a
higher value.
 It does not maintain a search tree. It stores current node data structure. This node
records the state and its objective function value. Algorithm only look out for
immediate neighbours of current state.
 It is similar to greedy local search in a sense that it considers a current good neighbour
state without thinking ahead.
 Greedy algorithm works very well as it is very easy to improve bad state in hill
climbing.

Algorithm :

function HILL-CLIMBING(problem) returns a state that is a local maximum

current ← MAKE-NODE(problem.INITIAL-STATE)

loop do

neighbor ← a highest-valued successor of current

if neighbor.VALUE ≤ current.VALUE then return current.STATE

current ← neighbor
Features of Hill Climbing:

 Generate and Test variant: Hill Climbing is the variant of Generate and Test method.
The Generate and Test method produce feedback which helps to decide which
direction to move in the search space.
 Greedy approach: Hill-climbing algorithm search moves in the direction which
optimizes the cost.
 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.

On Y-axis we have taken the function which can be an objective function or cost
function, and state-space on the x-axis. If the function on Y-axis is cost then, the goal of
search is to find the global minimum and local minimum. If the function of Y-axis is
Objective function, then the goal of the search is to find the global maximum and local
maximum.

The state-space diagram is a graphical representation of the set of states our search
algorithm can reach vs the value of our objective function(the function which we wish to
maximize).

X-axis: denotes the state space ie states or configuration our algorithm may reach.

Y-axis: denotes the values of objective function corresponding to a particular state.

The best solution will be a state space where the objective function has a maximum
value(global maximum).
Different regions in the state space landscape:

 Local maximum: It is a state which is better than its neighboring state however there
exists a state which is better than it(global maximum). This state is better because
here the value of the objective function is higher than its neighbors.
 Global maximum: It is the best possible state in the state space diagram. This is
because, at this stage, the objective function has the highest value.
 Plateau/flat local maximum: It is a flat region of state space where neighboring states
have the same value.
 Ridge: It is a region that is higher than its neighbors but itself has a slope. It is a
special kind of local maximum.
 Current state: The region of the state space diagram where we are currently present
during the search.
 Shoulder: It is a plateau that has an uphill edge.

Problems in different regions in Hill climbing

Hill climbing cannot reach the optimal/best state(global maximum) if it enters any of the
following regions :

 Local maximum: At a local maximum all neighboring states have a value that is
worse than the current state. Since hill-climbing uses a greedy approach, it will not
move to the worse state and terminate itself. The process will end even though a better
solution may exist.
o To overcome the local maximum problem: Utilize the backtracking technique.
Maintain a list of visited states. If the search reaches an undesirable state, it
can backtrack to the previous configuration and explore a new path.
 Plateau: On the plateau, all neighbors have the same value. Hence, it is not possible to
select the best direction.
o To overcome plateaus: Make a big jump. Randomly select a state far away
from the current state. Chances are that we will land in a non-plateau region.
 Ridge: Any point on a ridge can look like a peak because movement in all possible
directions is downward. Hence the algorithm stops when it reaches this state.
o To overcome Ridge: In this kind of obstacle, use two or more rules before
testing. It implies moving in several directions at once.

Advantages of Hill Climbing algorithm:

 Hill Climbing is a simple and intuitive algorithm that is easy to understand and
implement.
 It can be used in a wide variety of optimization problems, including those with a large
search space and complex constraints.
 Hill Climbing is often very efficient in finding local optima, making it a good choice
for problems where a good solution is needed quickly.
 The algorithm can be easily modified and extended to include additional heuristics or
constraints.

Disadvantages of Hill Climbing algorithm:

 Hill Climbing can get stuck in local optima, meaning that it may not find the global
optimum of the problem.
 The algorithm is sensitive to the choice of initial solution, and a poor initial solution
may result in a poor final solution.
 Hill Climbing does not explore the search space very thoroughly, which can limit its
ability to find better solutions.
 It may be less effective than other optimization algorithms, such as genetic algorithms
or simulated annealing, for certain types of problems.

Types of Hill Climbing Search :

 Stochastic hill Climbing


 Steepest-Ascent hill-climbing
 First Choice Hill Climbing
 Random Restart Hill Climbing

Stochastic Hill Climbing

Stochastic hill climbing does not examine for all its neighbor before moving. Rather,
this search algorithm selects one neighbor node at random and decides whether to choose it
as a current state or examine another state.

First Choice Hill Climbing

First-choice hill climbing implements stochastic hill climbing by generating


successors randomly until one is generated that is better than the current state. This is a good
strategy when a state has many (e.g., thousands) of successors

Random Restart Hill Climbing

Adopts the well known saying "If at first you don't succeed, try, try again". It
conducts a series of hill climbing searches from randomly generated initial states, stopping
when a goal is found.

The hill climbing algorithms described so far are incomplete because they often fail to
find a goal when surely goal exist. This can happen because these algorithms can get stuck on
local maxima. Random restart hill is complete with probability approaching to 1. This
algorithm do not stop until it reaches to goal.
The success of hill climbing depends very much on the shape of the state-space
landscape. If there are few local maxima and plateaux, random-restart hill climbing will find
a good solution very quickly.

Steepest Ascent Hill Climbing

This algorithm differs from the basic Hill climbing algorithm by choosing the best
successor rather than the first successor that is better. This indicates that it has elements of the
breadth first algorithm.

Steepest ascent Hill climbing algorithm

1. Evaluate the initial state.

2. If it is goal state then quit otherwise make the current state this initial state and proceed;

3. Repeat set target to be the state that any successor of the current state can better; for each
operator that can be applied to the current state apply the new operator and create a new state
evaluate this state.

4. If this state is goal state Then quit. Otherwise compare with Target. If better set Target to
this value. If Target is better than current state set current state to Target. Until a solution is
found or current state does not change.

Both the basic and this method of hill climbing may fail to find a solution by reaching
a state from which no subsequent improvement can be made and this state is not the solution.

Local maximum state is a state which is better than its neighbours but is not better
than states faraway. These are often known as foothills. Plateau states are states which have
approximately the same value and it is not clear in which direction to move in order to reach
the solution. Ridge states are special types of local maximum states. The surrounding area is
basically unfriendly and makes it difficult to escape from, in single steps, and so the path
peters out when surrounded by ridges. Escape relies on: backtracking to a previous good state
and proceed in a completely different direction-involves keeping records of the current path
from the outset; making a gigantic leap forward to a different part of the search space perhaps
by applying a sensible small step repeatedly, good for plateau; applying more than one rule at
a time before testing, good for ridges. None of these escape strategies can guarantee success.

Simulated Annealing Search

 In simulated annealing, initially the whole space is explored.


 This is a variation of hill climbing.
 This avoids the danger of being caught on a plateau or ridge and makes the procedure
less sensitive to the starting point.
 Simulated annealing is done to include a general survey of the scene, to avoid
climbing, false foot hills.
 There are two additional changes -
o Rather than creating maxima, minimisation is done.
o The term objective function is used rather than heuristic.
 This concept is taken from physical annealing where physical substances are men
melted and then gradually cooled until some solid state is reached. In physical
annealing the goal is to produce a minimal-energy state. The annealing schedule
states, that if the temperature is lowered sufficiently slowly, then the goal will be
attained. AE is called the change in the value of the objective function.
 It becomes clear that in this algorithm we have valley descending rather than hill
climbing. The probability that the metal will jump to a higher given by P=exp8-E/kT
where k is Boltzmann's constant.

Algorithm :

function SIMULATED-ANNEALING(problem, schedule) returns a solution state

inputs: problem, a problem

schedule, a mapping from time to “temperature”

current ← MAKE-NODE(problem.INITIAL-STATE)

for t = 1 to ∞ do

T ← schedule(t)

if T = 0 then return current

next ← a randomly selected successor of current

ΔE ← next.VALUE – current.VALUE

if ΔE > 0 then current ← next

else current ← next only with probability eΔE/T

Local Beam Search :

1) In the local beam search, instead of single state in the memory k states are kept in the
memory.

2) In local beam search states are generated in random fashion.

3) A successor function plays an important role by generating successor of all K states.


4) If any one successor state is goal then no further processing is required.

5) In other case i.e. if goal is not achieved, it observes the K best successors from the list of
all successor and process is repeated.

6) At first glance the random parallism is achieved in the sequence by a local beam search
with K states.

7) In a random-restart search every single search activity run independently of others.

8) To implement local search, threads are used. The K parallel search threads useful
information.

9) The algorithm work on principle of successful successors. If one state generate


efficient/goal reaching successor and other K-1 state generate poor successor, then in this
situation the successful successors leads all other states.

10) The algorithm drops/leaves the unsuccessful search and concentrate on successful search.

Limitations of local beam search

1) The local beam search has limitation of, lack of variation among the K states.

2) If the state concentrate on small area of state space then search becomes more expensive.

Stochastic Beam Search

1) Its one of the flavour of local beam search, which is very similar to that of stochastic hill
climbing.

2) It resolves the limitation of local beam search.

3) Stochastic beam search concentrate on random selection of K successor instead of


selecting k best successor from candidate successor.

4) The probability of random selection is increasing function of its success rate.

5) A stochastic beam search is very similar to natural selection, where the child (successor) of
a parent state is eugenic (good production) according to its success rate (fitness). Thus the
next generation is also very much powerful.

Genetic Algorithms

1) Evolutionary pace of learning algorithm is genetic algorithm. The higher degree of


eugency can be achieved with new paradigm of AI called a genetic algorithms.

2) A genetic algorithm is a rich flavour of stochastic beam search.


3) In the genetic algorithm two parent states are combined together by which a good
successor state is generated.

4) The analogy to natural selection is the same as in stochastic beam search, except now we
are dealing with sexual rather than asexual reproduction.

Term used in Genetic Algorithm

 Population: Population is set of states which are generated randomly.


 Individual: It is a state or individual and it is represented as string over a finite
alphabet.

Example - A string of 0s and 1s.

For example - In 8-queen all states are specified with the position of 8-queens. The memory
required is

8×log2 8 = 24 bits. Each state is represented with 8 digits.

 Fitness function: It is a evaluation function. On its basis each state is rated. A fitness
function should return higher values for better states. For the state, the probability of
being chosen for reproducing is directly proportional to the fitness score.

In 8-queen problem the fitness function has 28 value for number of non attacking pairs.

 Crossover: Selection of state is dependent on fitness function. If fitness function value


is above threshold then only state is selected otherwise discarded. For each state, pairs
are divided, that division point or meeting point is called crossover point, which is
chosen in random order from the positions in the string.
 Mutation: Mutation is one of the generic operator. Mutation works on random
selections or changes. For example mutation select and changes a single bit of pattern
switching 0 to 1 or 1 to #.
 Schema: The schema is a substring in which position of some bit can be unspecified.

Working of a Genetic Algorithm


Input: 1) State population (a set of individuals)
2) Fitness function (that rates individual).
Steps
1) Create an individual 'X' (parent) by using random selection with fitness function 'A' of 'X'.
2) Create an individual 'Y' (parent) by using random selection with fitness function'B' of 'Y'.
3) Child with good fitness is created for X + Y.
4) For small probability apply mutate operator on child.
5) Add child to new population.
6) The above process is repeated until child (an individual) is not fit as specified by fitness
function.
Algorithm :

function GENETIC-ALGORITHM(population, FITNESS-FN) returns an individual

inputs: population, a set of individuals

FITNESS-FN, a function that measures the fitness of an individual

repeat

new population ← empty set

for i = 1 to SIZE(population) do

x ← RANDOM-SELECTION(population, FITNESS-FN)

y ← RANDOM-SELECTION(population, FITNESS-FN)

child ← REPRODUCE(x , y)

if (small random probability) then child ← MUTATE(child)

add child to new population

population ← new population

until some individual is fit enough, or enough time has elapsed

return the best individual in population, according to FITNESS-FN

function REPRODUCE(x , y) returns an individual

inputs: x , y, parent individuals

n ← LENGTH(x ); c ←random number from 1 to n

return APPEND(SUBSTRING(x , 1, c), SUBSTRING(y, c + 1, n))

Optimization using Genetic Algorithm

 Genetic algorithm is biological model of intelligent evolution. It generates the


population of competing children.
 The poor candidate solution will be vanished, as genetic algorithm generates best
child.
Thus, in practice genetic algorithm is most promising survive and reproduction technique
by constructing new optimized solution. Thus it is optimization oriented technique.

Application of genetic algorithm on optimization.

 Circuit layout
 Job-shop scheduling.

CONSTRAINT SATISFACTION PROBLEMS

Whenever a problem is actually variables comply with stringent conditions of


principles, it is said to have been addressed using the solving multi - objective method.

Three factors affect restriction compliance, particularly regarding:

 It refers to a group of parameters, or X.


 D: The variables are contained within a collection several domain. Every variables
has a distinct scope.
 C: It is a set of restrictions that the collection of parameters must abide by.

In constraint satisfaction, domains are the areas wherein parameters were located after
the restrictions that are particular to the task. Those three components make up a constraint
satisfaction technique in its entirety. The pair "scope, rel" makes up the number of something
like the requirement. The scope is a tuple of variables that contribute to the restriction, as well
as rel is indeed a relationship that contains a list of possible solutions for the parameters
should assume in order to meet the restrictions of something like the issue.

Issues with Contains A certain amount Solved

For a constraint satisfaction problem (CSP), the following conditions must be met:

 States area
 fundamental idea while behind remedy.

The definition of a state in phase space involves giving values to any or all of the
parameters, like as

X1 = v1, X2 = v2, etc.

There are 3 methods to economically beneficial to something like a parameter:

 Consistent or Legal Assignment: A task is referred to as consistent or legal if it


complies with all laws and regulations.
 Complete Assignment: An assignment in which each variable has a number
associated to it and that the CSP solution is continuous. One such task is referred to as
a completed task.
 A partial assignment is one that just gives some of the variables values. Projects of
this nature are referred to as incomplete assignment.

Domain Categories within CSP

The parameters utilize one of the two types of domains listed below:

 Discrete Domain: This limitless area allows for the existence of a single state with
numerous variables. For instance, every parameter may receive a endless number of
beginning states.
 It is a finite domain with continuous phases that really can describe just one area for
just one particular variable. Another name for it is constant area.

Types of Constraints in CSP

Basically, there are three different categories of limitations in regard towards the
parameters:

 Unary restrictions are the easiest kind of restrictions because they only limit the value
of one variable.
 Binary resource limits: These restrictions connect two parameters. A value between
x1 and x3 can be found in a variable named x2.
 Global Resource limits: This kind of restriction includes a unrestricted amount of
variables.

The main kinds of restrictions are resolved using certain kinds of resolution
methodologies:

 In linear programming, when every parameter carrying an integer value only occurs in
linear equation, linear constraints are frequently utilised.
 Non-linear Constraints: With non-linear programming, when each variable (an integer
value) exists in a non-linear form, several types of restrictions were utilised.

CONSTRAINT PROPAGATION

Artificial Intelligence (AI) encompasses a variety of methods and techniques to solve


complex problems efficiently. One such technique is constraint propagation, which plays a
crucial role in areas like scheduling, planning, and resource allocation. This article explores
the concept of constraint propagation, its significance in AI, and how it is applied in various
domains.

Constraint propagation is a fundamental concept in constraint satisfaction problems


(CSPs). A CSP involves variables that must be assigned values from a given domain while
satisfying a set of constraints. Constraint propagation aims to simplify these problems by
reducing the domains of variables, thereby making the search for solutions more efficient.

Key Concepts
 Variables: Elements that need to be assigned values.
 Domains: Possible values that can be assigned to the variables.
 Constraints: Rules that define permissible combinations of values for the variables.

How Constraint Propagation Works

Constraint propagation works by iteratively narrowing down the domains of variables


based on the constraints. This process continues until no more values can be eliminated from
any domain. The primary goal is to reduce the search space and make it easier to find a
solution.

Steps in Constraint Propagation

 Initialization: Start with the initial domains of all variables.


 Propagation: Apply constraints to reduce the domains of variables.
 Iteration: Repeat the propagation step until a stable state is reached, where no further
reduction is possible.

Applications of Constraint Propagation

Constraint propagation is widely used in various AI applications. Some notable areas


include:

 Scheduling

In scheduling problems, tasks must be assigned to time slots without conflicts. Constraint
propagation helps by reducing the possible time slots for each task based on constraints like
availability and dependencies.

 Planning

AI planning involves creating a sequence of actions to achieve a goal. Constraint propagation


simplifies the planning process by reducing the possible actions at each step, ensuring that the
resulting plan satisfies all constraints.

 Resource Allocation

In resource allocation problems, resources must be assigned to tasks in a way that meets all
constraints, such as capacity limits and priority rules. Constraint propagation helps by
narrowing down the possible assignments, making the search for an optimal allocation more
efficient.

Algorithms for Constraint Propagation

Several algorithms are used for constraint propagation, each with its strengths and
weaknesses. Some common algorithms include:
 Arc Consistency

Arc consistency ensures that for every value of one variable, there is a consistent value in
another variable connected by a constraint. This algorithm is often used as a preprocessing
step to simplify CSPs before applying more complex algorithms.

 Path Consistency

Path consistency extends arc consistency by considering triples of variables. It ensures that
for every pair of variables, there is a consistent value in the third variable. This further
reduces the domains and simplifies the problem.

 k-Consistency

k-Consistency generalizes the concept of arc and path consistency to k variables. It ensures
that for every subset of k-1 variables, there is a consistent value in the kth variable. Higher
levels of consistency provide more pruning but are computationally more expensive.

BACKTRACKING SEARCH

Backtracking is a widely used technique for solving CSPs. It is a systematic search


algorithm that explores possible assignments for variables, backtracking when it encounters
constraints that cannot be satisfied. The algorithm follows these steps:

 Choose an unassigned variable.


 Select a value from its domain.
 Check if the assignment violates any constraints.
 If a constraint is violated, backtrack to the previous variable and try another value.
 Continue this process until all variables are assigned values, or a valid solution is
found.

If we apply BFS to generic CSP problems then we can notice that the branching factor at the
top level is „nd‟, because any of „d‟ values can be assigned to any of „n‟ variables. At the next
level, the branching factor is „(n-1)d‟ and so on for n levels. Therefore a tree with „n! * dn‟
leaves is generated even though there are only „dn‟ possible complete assignments

Basic Steps in Backtracking Search

 Depth-first search selects values for single variable at a given time


 Apply constraint to the variable when variable is selected
 Backtracking action – performed if a variable has no legal values left to assign
 Backtracking search is basic uninformed algorithm for CSPs

Backtracking Search Algorithm

 Consider a CSP problem


 Apply backtracking search. If backtracking search successful returns a solution else, a
failure state which return a procedure recursive-backtracking
 Procedure recursive backtracking starts with empty set and takes input as CSP
problem. If complete assignment possible or assignment done then return actual
assignment
 Variable is assigned a specific value
 The relative constraint is a set which is taken as input
 If value is complete and consistent according to constraints then assign value to
variable, add that to list
 Call the recursive backtracking until result or failure is reached
 Every time recursive-backtracking sustains result
 If result is failure than remove variable with specific value from assignment. It will
return failure status

Limitations of Backtracking

 A success function is generated with above algorithm. But backtracking is not


effective for very large problems
 The general performance is not so good. Domain specific heuristic function combined
with uninformed search algorithm can generate better searching result

Improvement in backtracking search

We can also solve CSP without knowing the domain-specific knowledge. Here we
need to design a module which resolve following properties
 Which variable is assigned in next step and what order values can be tried?
 Impact of current variable assignments on unassigned variables
 Avoidance of known failed path in the potential paths.

Improvement in Backtracking Search

You might also like