You are on page 1of 14

HEURISTIC SEARCH TECHNIQUES

Hill climbing; Branch and bound technique; Best first search and A* algorithm; AND/OR Graphs; Problem
reduction and AO* algorithm; Constraint Satisfaction problems Game playing Min/Max search procedure;
Alpha -Beta cutoffs; Additional Refinements.

A heuristic is a function that ranks alternatives in various search algorithms at each branching step basing
on an available information in order to make a decision which branch is to be followed during a search.
For example, for shortest path problems, a heuristic is a function, h(n) defined on the nodes of a search
tree, which serves as an estimate of the cost of the cheapest path from that node to the goal node. Heuristics
are used by informed search algorithms such as Greedy best-first search and A* to choose the best node
to explore.
HILL CLIMBING ALGORITHM
The Hill climbing algorithm is simply a loop that continually moves in the direction of increasing value
that is uphill. It terminates when it reaches a “peak” where no neighbor has a higher value. The
algorithm does not maintain a search tree, so the current node data structure need only record the state
and its objective function value. Hill-climbing does not look ahead beyond the immediate neighbors of
the current state.
VARIANTS OF HILL CLIMBING
Stochastic hill-climbing
• Random selection among the uphill moves.
• The selection probability can vary with the steepness of the uphill move.
First-choice hill-climbing
• Implements stochastic hill climbing by generating successors randomly until a better one is
found.
Random-restart hill-climbing
• Tries to avoid getting stuck in local maxima by overcoming local maxima-trivially complete.
What problems are faced by hill-climbing search?
• Local maxima – A local maxima is a peak that is higher than each of its neighboring states, but
lower than the local maximum. Hill climbing algorithm that reach the vicinity of a local
maximum will be drawn upwards towards the peak, but will then be stuck with nowhere else to
go.

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
• Ridges – Ridges result in a sequence of local maxima that is very difficult for greedy algorithms
to navigate.
• Plateaux: a plateau is an area of state space landscape where the evaluation function is flat. A
hill-climbing search might be unable to find its way off the plateau.

BRANCH AND BOUND TECHNIQUE


Branch and bound is a general technique for improving the searching process by systematically
enumerating all candidate solutions and disposing of obviously impossible solutions. Branch and bound
usually applies to those problems that have finite solutions, in which the solutions can be represented as
a sequence of options. Branching requires several choices to be made so that the choices branch out into
the solution space. The solution space is organized as a treelike structure. The branch-and-bound
algorithm handles this problem by bounding and pruning. Bounding refers to setting a bound on the
solution quality (e.g., the route length for TSP), and pruning means trimming off branches in the solution
tree whose solution quality is estimated to be poor. Bounding and pruning are the essential concepts of
the branch-and-bound technique, because they are used to effectively reduce the search space.

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
The figure shows an instance of TSP and a solution tree, which is constructed by making choices on the
next cities to visit.
The number under a leaf node of the solution tree represents the length of the corresponding route. For
incomplete branches, an expression in the form of a + b is shown. In this notation, a is the length of the
traversed edges, and b is a lower bound for the length of the remaining route that has not been explored.
The lower bound is derived by use of a minimum spanning tree that consists of the unvisited vertices, as
well as the root and leaf vertices of the partial route. For example, for the unfinished route A→B→E, a
minimum spanning tree is built for nodes A, C, D, and E, and its value is 12. This lower bound is a true
underestimate for the length of the remaining route. The sum of these two numbers provides the basis for
bounding.
The solution tree is traversed depth-first, with the length of the current shortest route as the upper bound
for future solutions. For example, after A→B→C→D→E→A is examined, the upper bound is 21, and
after the next route is explored, the bound drops to 15. Every time a partial route is extended by a vertex,
a lower bound for the length of the rest of the route is computed. If the sum a + b is over or equal to the
current upper bound, the solutions on that branch guarantees to be worse than the current best solution,
and the branch can be pruned.
Branch-and-bound mainly addresses optimization problems, because bounding is often based on
numerical comparisons. TSP that uses the route length as the bound is a classical application; however, it
can also be applied to some decision problems. In these cases, the bounding criteria are often restrictions
or additional descriptions of possible solutions.
BEST FIRST SEARCH AND A* ALGORITHM
Best-first search is an instance of the general TREE-SEARCH or GRAPH-SEARCH algorithm in which
a node is selected for expansion based on the evaluation function f (n). Traditionally, the node with the
lowest evaluation function is selected for expansion.

Function BEST-FIRST-SEARCH (problem, EVAL-FN) returns a solution sequence


Inputs: problem, a problem
EVAL-FN, an evaluation function
QUEUEING-FN<- a function that orders nodes by EVAL-FN
return TREE-SEARCH (problem, QUEUEING-FN)

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
EVALUATION FUNCTIONS IN BEST FIRST SEARCH
1. GREEDY BEST FIRST SEARCH
Greedy best-first-search tries to expand the node that is closest to the goal, on the grounds that that is
likely to lead to a solution quickly. For example, it evaluates nodes by using just the heuristic function:
f(n) = h(n), were h(n) is the estimated cost of the cheapest path from the state at node n to a goal state
ALGORITHM

Function GREEDY-BEST-FIRST SEARCH (problem) returns a solution or failure


Return BEST-FIRST-SEARCH (problem, h)
2. A* SEARCH

A* search is the most widely-known form of best-first search. It evaluates the nodes by combining
g(n), the cost to reach the node, and h(n), the cost to get from the node to the goal:

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

Where f(n) = estimated cost of the cheapest solution through n.

g(n) is the path cost from the start node to node n.

h(n) = estimated cost of the cheapest path from node n to the goal state (heuristic
function)

A* search is both complete and optimal.

ALGORITHM

Function A* SEARCH (problem) returns a solution or failure

Return BEST-FIRST-SEARCH (problem, g+h)

AND/OR GRAPH
The AND/OR graph is a graph or tree which represents a problem-solving process, the nodes of the graph
represent states or goals and their successors are labeled as either AND/ OR branches. The AND
successors are sub goals that must all be achieved to satisfy the parent goal, while OR branches indicate
alternative sub goals, any one of which could satisfy the parent goal. A solution graph is a subgraph of
the AND/OR graph which represents a derivation for a solution of the problem. Therefore, solving a

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
problem can be viewed as searching for a solution graph in an AND/OR graph. A “cost” is associated
with every solution graph.
NOTE: An OR node represents a choice between possible decompositions.
An AND node represents a given decomposition.
The decomposition, or reduction, generates arcs that we call and arcs, the 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. Just as
in an OR graph, several arcs may emerge from a single node, indicating a variety of ways in which the
original problem might be solved. This is why the structure is called not simply an AND-graph but rather
an AND-OR graph (which also happens to be an AND-OR tree)
ILLUSTRATION:
STEP 1:

A is the only node; it is at the end of the current best path. It is expanded, yielding nodes B, C, D. The arc
to D is labeled as the most promising one emerging from A, since it costs 6compared to B and C, which
costs 9.
STEP 2:

Node B is chosen for expansion. This process produces one new arc, the AND arc to E and F, with a
combined cost estimate of 10.so we update the f’ value of D to 10.Going back one more level, we see that
this makes the AND arc B-C better than the arc to D, so it is labeled as the current best path.

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
STEP 3:

We traverse the arc from A and discover the unexpanded nodes B and C. If we going to find a solution
along this path, we will have to expand both B and C eventually, so let’s choose to explore B first. This
generates two new arcs, the ones to G and to H. Propagating their f’ values backward, we update f’ of B
to 6(since that is the best, we think we can do, which we can achieve by going through G). This requires
updating the cost of the AND arc B-C to 12(6+4+2). After doing that, the arc to D is again the better path
from A, so we record that as the current best path and either node E or node F will choose for expansion
at step 4.
STEP4:

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
ILLUSTRATION:

Find path a-z

a -z via f a -z via g

a-f f -z a-g g-z

for path a-z find


path a-z via f
or path a-z via g
Decomposition: for path a-z via f find
path a-f
and path f-z
analogously for g
• And/or Graph: or-nodes as ellipses,
• and-nodes as boxes
ILLUSTRATION: consider a game with only win/loss 2 players A and B playing alternatively
solution: Have a win for A
Interpretation: game is won if solution tree exists, if a tree begins with an or node: there is a choice for A
leading to an and node: such that all possible choices for B lead to or node: and so on until Goal: successful
solution (win) is found
It means: A has won (solution tree) if it is either in a winning position or it can always choose a move
leading to a losing position of B; i.e. a position such that all moves that B can choose lead to a winning

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
position of a (i.e. again to a solution tree). Note: A does not have to have a solution tree. Either B could
have a solution tree (in which a loses) or neither of them have, so none of the players can force a win.
AO* ALGORITHM
1. Initialize the graph to the starting node.
2. Loop until the starting node is labeled SOLVED or until its cost goes above FUTILITY:
a) Traverse the graph, starting at the initial node and following the current best path and accumulate the
set of nodes that are on that path and have not yet been expanded or labelled as solved.
b) Pick one of these unexpanded nodes and expand it. If there are no successors, assign FUTILITY as the
value of this node. Otherwise, add its successors to the graph and for each of them compute f’. If f’ of any
node is 0, mark that node as SOLVED.
c) Change the f’ estimate of the newly expanded node to reflect the new information provided by its
successors. Propagate this change backward through the graph till the initial node. If any node contains a
successor arc whose descendants are all solved, label the node itself as SOLVED.

A CONSTRAINT SATISFACTION PROBLEM

A Constraint Satisfaction problem (or CSP) is defined by a set of variables X1, X2…..., Xn, and a set
of constraints, C1, C2,..,Cm. Each variable Xi has a nonempty domain Di of possible values. Each
constraint Ci involves some subset of the variables and specifies the allowable combinations of values for
that subset. A state of the problem is defined by an assignment of values to some or all of the variables,
{Xi = vi, Xj=vj…} A solution to a CSP is a complete assignment that satisfies all the constraints.

A Constraint Graph is a graph where the nodes of the graph correspond to variables of the problem and
the arcs corresponds to constraints. It is helpful to visualize the Constraint Satisfaction Problem as a
Constraint Graph.

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
Constraint graph – Example:

The map coloring problem represented as a constraint graph

A cryptarithmetic problem is provided by cryptarithmetic puzzles. It is usual to insist that each letter
in a cryptarithmetic puzzle represent a different digit. For the case (in the Figure given below), this
would be represented as the six-variable constraint Alldiff (F; T; U;W;R;O). Alternatively, it can be
represented by a collection of binary constraints such as

The addition constraints on the four columns of the puzzle also involve several variables and can be
written as
O + O = R + 10 . X1
X1 +W +W = U + 10 . X2
X2 + T + T = O + 10 . X3
X3 = F
whereX1, X2, and X3 are auxiliary variables representing the digit (0 or 1) carried over into the next
column. Higher-order constraints can be represented in a constraint hypergraph, such as the one
shown in Figure (b). The sharp-eyed reader will have noticed that the

Alldiff constraint can be broken down into binary constraints— ,


and so on.

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
(a) A cryptarithmetic problem. Each letter stands for a distinct digit; the aim is
to find a substitution of digits for letters such that the resulting sum is arithmetically correct,
with the added restriction that no leading zeroes are allowed. (b) The constraint hypergraph
for the cryptarithmetic problem, showing the Alldiff constraint as well as the column addition
constraints. Each constraint is a square box connected to the variables it constrains.

GAME PLAYING
Game playing is considered as a search problem therefore a search technique is required to select the next
state. The pruning technique allows us to ignore positions of the search tree that make no difference to the
final choice and heuristic evaluation function allow us to find the utility (win, loss, draw) of a state without
doing a complete search.
We will consider games with two players, whom we will call MAX and MIN. MAX moves first, and then
they take turns moving until the game is over. At the end of the game, points are awarded to the winning
player and penalties are given to the loser. A game can be formally defined as a search problem with the
following components:

• The initial state, which includes the board position and identifies the player to move.
• A successor function, which returns a list of (move, state) pairs, each indicating a legal move and
the resulting state.

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
• A terminal test, which describes when the game is over. States where the game has ended are
called terminal states.
• A utility function (also called an objective function or payoff function), which give a numeric
value for the terminal states. In chess, the outcome is a win, loss, or draw, with values +1, -1, or
0. he payoffs in backgammon range from +192 to -192.
TYPES OF GAMES
Deterministic
• Chess
• Checkers
• Tic tac toe
Chance
• Bridge
• Poker
• Monopoly
THE MINIMAX ALGORITHM
An algorithm which determines the optimal strategy for Max and thus to decide what the best move is
called as Minimax algorithm.
• Generate the whole game tree, all the way down to the terminal state.
• Apply the utility function to each terminal state to get its value.
• Use utility functions to each terminal state to get its value.
• Minmax decision maximizes the utility under the assumption that the opponent will play perfectly
to minimize the max player score.
The minimax algorithm computes the minimax decision from the current state. It uses a simple recursive
computation of the minimax values of each successor state, directly implementing the defining equations.
The recursion proceeds all the way down to the leaves of the tree, and then the minimax values are backed
up through the tree as the recursion unwinds. For example, in Figure X, the algorithm first recourses down
to the three bottom left nodes, and uses the utility function on them to discover that their values are 3,12,
and 8 respectively. Then it takes the minimum of these values,3, and returns it as the backed-up value of
node B. A similar process gives the backed-up values of 2 for C and 2 for D. Finally, we take the maximum
of 3,2, and 2 to get the backed-up value of 3 at the root node.

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
The minimax algorithm performs a complete depth-first exploration of the game tree. If the maximum
depth of the tree is m, and there are b legal moves at each point, then the time complexity of the minimax
algorithm is O(bm). The space complexity is O(bm) for an algorithm that generates successors at once.

Figure X A two-ply game tree. The nodes are “MAX nodes”, in which it is MAX’s turn to
move, and the nodes are “MIN nodes”. The terminal nodes show the utility values for MAX;
the other nodes are labeled with their minimax values. MAX’s best move at the root is a1, because it
leads to the successor with the highest minimax value, and MIN’s best reply is b1, because it leads
to the successor with the lowest minimax value.

function MINMAX-DECISION (state) returns an action


inputs: state, current state in game
v<-MAX – VALUE (state)
Return the action in SUCCESSORS (state) with value v
function MAX- (state) returns a utility value
if TERMINAL-TEST (state)then return UTILITY (state)
𝒗 ← −∞
For a, s in SUCCESSORS (state)do
V<-MAX (v, MIN-VALUE(s))
return v
Function MIN-VALUE (state) returns a utility value
If terminal-test(state)then return UTILITY (state)

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
𝒗←∞
For a, s in SUCCESSORS (state)do
𝑣 ← 𝑀𝐼𝑁(𝑣, 𝑀𝐴𝑋 − 𝑉𝐴𝐿𝑈𝐸(𝑠))
Return v
When we have an imperfect decisions of minimax algorithm, the search tree is carried out till the end of
the tree, this can be avoided in two ways:
• The utility function is replaced by an evaluation function
• The terminal test is replaced by a cut-off test
ALPHA-BETA PRUNING
The problem with minimax search is that the number of game states it has to examine is exponential in
the number of moves. Unfortunately, we can’t eliminate the exponent, but we can effectively cut it in half.
By performing pruning, we can eliminate large part of the tree from consideration. We can apply the
technique known as alpha beta pruning, when applied to a minimax tree, it returns the same move as
minimax would, but prunes away branches that cannot possibly influence the final decision.
Alpha Beta pruning gets its name from the following two parameters that describe bounds on the backed-
up values that appear anywhere along the path:

• α: the value of the best (i.e., highest-value) choice we have found so far at any choice point along
the path of MAX.
• β: the value of best (i.e., lowest-value) choice we have found so far at any choice point along the
path of MIN.
Alpha Beta search updates the values of α and β as it goes along and prunes the remaining branches at
anode (i.e., terminates the recursive call) as soon as the value of the current node is known to be worse
than the current α and β value for MAX and MIN, respectively.

DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems
DMISJBU- Lilongwe Campus. Ms. Tawonga Mkandawire (BE(CS)) Artificial Intelligence &Expert Systems

You might also like