Unit 2 AI
Unit 2 AI
Unit 2 AI
Heuristics
A heuristic is a method that improves the efficiency of the search
process. Heuristics may not find the best solution every time but
guarantee that they find a good solution in a reasonable time. These are
particularly useful in solving tough and complex problems.
Heuristic search
To find a solution in proper time rather than a complete solution in
unlimited time we use heuristics. ‘A heuristic function is a function that
maps from problem state descriptions to measures of desirability,
usually represented as numbers’. Heuristic search methods use
knowledge about the problem domain and choose promising operators
first. These heuristic search methods use heuristic functions to evaluate
the next state towards the goal state.
There are better methods for the solution of such problems: one is
called branch and bound. First, generate all the complete paths and find
the distance of the first complete path. If the next path is shorter, then
save it and proceed this way avoiding the path when its length exceeds
the saved shortest path length, although it is better than the previous
method.
Generate-And-Test Algorithm
Generate-and-test search algorithm is a very simple algorithm that
guarantees to find a solution if done systematically and there exists a
solution.
Algorithm: Generate-And-Test
1.Generate a possible solution.
2.Test to see if this is the expected solution.
3.If the solution has been found quit else go to step 1.
Hill Climbing
Hill Climbing is heuristic search used for mathematical optimization
problems in the field of Artificial Intelligence . Given a large set of inputs
and a good heuristic function, it tries to find a sufficiently good solution
to the problem. This solution may not be the global optimal maximum.
2. Uses the Greedy approach : At any point in state space, the search
moves in that direction only which optimizes the cost of function with
the hope of finding the optimal solution at the end.
3. Ridge : Any point on a ridge can look like peak because movement in
all possible directions is downward. Hence the algorithm stops when it
reaches this state.
To overcome Ridge : In this kind of obstacle, use two or more rules
before testing. It implies moving in several directions at once.
Best First Search (Informed Search)
The idea of Best First Search is to use an evaluation function to decide
which adjacent is most promising and then explore. Best First Search
falls under the category of Heuristic Search or Informed Search.
In the best first search algorithm, we expand the node which is closest to
the goal node and the closest cost is estimated by heuristic function, i.e.
f(n)= g(n).
Where, h(n)= estimated cost from node n to the goal.
OR-graph
It is sometimes important to search graphs so that duplicate paths
will not be pursued.An algorithm to do this will operate by searching
a directed graph in which each node represents a point in problem
space.
– OPEN – nodes that have been generated and have had the
heuristic function applied to them but which have not yet been
examined. OPEN is actually a priority queue in which the elements with
the highest priority are those with the most promising value of the
heuristic function.
A* Algorithm
• BFS is a simplification of A* Algorithm
• Presented by Hart et al
• Algorithm uses:
– f’: Heuristic function that estimates the merits of each node we
generate. This is sum of two components, g and h’ and f’ represents an
estimate of the cost of getting from the initial state to a goal state along
with the path that generated the current node.
– g : The function g is a measure of the cost of getting from initial
state to the current node.
– h’ : The function h’ is an estimate of the additional cost of getting
from the current node to a goal state.
– OPEN
– CLOSED
Algorithm :
1. Start with OPEN containing only initial node. Set that node’s g value
to 0, its h’ value to whatever it is, and its f’ value to h’+0 or h’. Set
CLOSED to empty list.
2. Until a goal node is found, repeat the following procedure:
If there are no nodes on OPEN, report failure.
Otherwise pick the node on OPEN with the lowest f’ value. Call it
BESTNODE. Remove it from OPEN. Place it in CLOSED. See if the
BESTNODE is a goal state. If so exit and report a solution.
Otherwise, generate the successors of BESTNODE but do not set the
BESTNODE to point to them yet.
For each of the SUCCESSOR, do the following:
a. Set SUCCESSOR to point back to BESTNODE. These backwards
links will make it possible to recover the path once a solution is
found.
b. Compute g(SUCCESSOR) = g(BESTNODE) + the cost of
getting from BESTNODE to SUCCESSOR
c. See if SUCCESSOR is the same as any node on OPEN. If so
call the node OLD.
d. If SUCCESSOR was not on OPEN, see if it is on CLOSED. If so,
call the node on CLOSED OLD and add OLD to the list of
BESTNODE’s successors.
e. If SUCCESSOR was not already on either OPEN or CLOSED,
then put it on OPEN and add it to the list of BESTNODE’s
successors. Compute
f’(SUCCESSOR) = g(SUCCESSOR) + h’(SUCCESSOR)
PROBLEM REDUCTION
When a problem can be divided into a set of sub problems, where each
sub problem can be solved separately and a combination of these will be
a solution, AND-OR graphs or AND - OR trees are used for representing
the solution.
AND-OR graphs
AND-OR graph (or tree) is useful for representing the solution of
problems that can be solved by decomposing them into a set of smaller
problems, all of which must then be solved.One AND arc may point to
any number of successor nodes, all of which must be solved in order for
the arc to point to a solution.
In order to find solution in an AND-OR graph, we need an algorithm
similar to bfs but with the ability to handle the AND arcs appropriately.
Notice that it may be necessary to get to more than one solution state
since each arm of an AND arc must lead to its own solution node.
AO* Algorithm
The algorithm for performing a heuristic search of an AND - OR graph is
given below. Unlike A* algorithm which used two lists OPEN and CLOSED,
the AO* algorithm uses a single structure G.
G represents the part of the search graph generated so far. Each node in
G points down to its immediate successors and up to its immediate
predecessors, and also has with it the value of h' cost of a path from
itself to a set of solution nodes. The cost of getting from the start nodes
to the current node "g" is not stored as in the A* algorithm.
AO* ALGORITHM:
1. Let G consists only to the node representing the initial state call this
node INIT. Compute h' (INIT).
2. Until INIT is labeled SOLVED or hi (INIT) becomes greater than
FUTILITY, repeat the following procedure :
(I) Trace the marked arcs from INIT and select an unbounded node
NODE.
(II) Generate the successors of NODE . if there are no successors then
assign FUTILITY as h' (NODE). This means that NODE is not solvable. If
there are successors then for each one called SUCCESSOR, that is not
also an ancestor of NODE do the following :
(a) add SUCCESSOR to graph G
(b) if successor is not a terminal node, mark it solved and assign
zero to its h ' value.
(c) If successor is not a terminal node, compute it h' value.
(III) propagate the newly discovered information up the graph by doing
the following . let S be a set of nodes that have been marked SOLVED.
Initialize S to NODE. Until S is empty repeat the following procedure:
(a) select a node from S call if CURRENT and remove it from S.
(b) compute h' of each of the arcs emerging from CURRENT ,
Assign minimum h' to CURRENT.
(c) Mark the minimum cost path a s the best out of CURRENT.
(d) Mark CURRENT SOLVED if all of the nodes connected to it
through the new marked are have been labeled SOLVED.
(e) If CURRENT has been marked SOLVED or its h ' has just
changed, its new status must be propagate backwards up the
graph .hence all the ancestors of CURRENT are added to S.
CONSTRAINT SATISFACTION:-
Many problems in AI can be considered as problems of constraint
satisfaction, in which the goal state satisfies a given set of constraint.
constraint satisfaction problems can be solved by using any of the search
strategies. The general form of the constraint satisfaction procedure is
as follows:
Until a complete solution is found or until all paths have led to lead ends,
do
1. select an unexpanded node of the search graph.
2. Apply the constraint inference rules to the selected node to generate
all possible new constraints.
3. If the set of constraints contains a contradiction, then report that this
path is a dead end.
4. If the set of constraints describes a complete solution then report
success.
5. If neither a constraint nor a complete solution has been found then
apply the rules to generate new partial solutions. Insert these partial
solutions into the search graph.
Goal State: the digits to the letters must be assigned in such a manner so
that the sum is satisfied.