UNIT 2 AI
UNIT 2 AI
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
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.
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
Uninformed search
Informed 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.
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.
Breadth-first search
Depth-first search
Depth Limited Search
Uniform cost search
Iterative deepening depth-first search
Bidirectional Search
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 :
loop do
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.
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:
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 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 :
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:
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.
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 :
else
cutoff occurred?←false
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:
Disadvantages:
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 :
frontier ← a priority queue ordered by PATH-COST, with node as the only element
loop do
frontier ← INSERT(child,frontier )
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.
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 :
for depth = 0 to ∞ do
Performance Measures :
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 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.
Performance Measures :
Advantages:
Disadvantages:
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.
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.
4) A heuristic function h(n) consider a node as input but it rely only on the state at that
node.
Procedure :
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.
2. Start with the initial node 'n' and put it on the ordered list OPEN.
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.
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)
Working of A*
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:
6) Lastly, add 'n' to the OPEN list and return to the beginning of the main loop.
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-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.
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.
Heuristic :
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
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
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*
Performance measurement
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 :
h(n) = estimated cost from the current node to the goal state.
Thus,
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.
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.
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 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 -
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
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 :
current ← MAKE-NODE(problem.INITIAL-STATE)
loop do
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Algorithm :
current ← MAKE-NODE(problem.INITIAL-STATE)
for t = 1 to ∞ do
T ← schedule(t)
ΔE ← next.VALUE – current.VALUE
1) In the local beam search, instead of single state in the memory k states are kept in the
memory.
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.
8) To implement local search, threads are used. The K parallel search threads useful
information.
10) The algorithm drops/leaves the unsuccessful search and concentrate on successful 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.
1) Its one of the flavour of local beam search, which is very similar to that of stochastic hill
climbing.
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
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.
For example - In 8-queen all states are specified with the position of 8-queens. The memory
required is
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.
repeat
for i = 1 to SIZE(population) do
x ← RANDOM-SELECTION(population, FITNESS-FN)
y ← RANDOM-SELECTION(population, FITNESS-FN)
child ← REPRODUCE(x , y)
Circuit layout
Job-shop scheduling.
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.
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
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.
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
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.
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
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.
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
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
Limitations of Backtracking
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.