CS8691 Notes 001 2 Edubuzz360
CS8691 Notes 001 2 Edubuzz360
com
-------------------------------------------------------------------------------------------------------
2017 Regulations
UNIT-II
-----------------------------------------------------------------------------------------
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Goal formulation,based on the current situation and the agent’s performance measure,is the first
step in problem solving.
The agent’s task is to find out which sequence of actions will get to a goal state.
Problem formulation is the process of deciding what actions and states to consider given a goal.
Formulate problem:
states: various cities
actions: drive between cities
Find solution:
sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
Problem formulation
A problem is defined by four items:
initial state e.g., “at Arad"
successor function S(x) = set of action-state pairs
e.g., S(Arad) = {[Arad -> Zerind;Zerind],….}
goal test, can be
explicit, e.g., x = at Bucharest"
implicit, e.g., NoDirt(x)
path cost (additive)
e.g., sum of distances, number of actions executed, etc.
c(x; a; y) is the step cost, assumed to be >= 0
A solution is a sequence of actions leading from the initial state to a goal state.
Search
An agent with several immediate options of unknown value can decide what to do by examining
different possible sequences of actions that leads to the states of known value,and then choosing the
best sequence. The process of looking for sequences actions from the current state to reach the goal
state is called search.
The search algorithm takes a problem as input and returns a solution in the form of action
sequence. Once a solution is found,the execution phase consists of carrying out the recommended
action..
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 1.18 shows a simple “formulate,search,execute” design for the agent. Once solution has been
executed,the agent will formulate a new goal.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
State Space : The set of all states reachable from the initial state. The state space forms a
graph in which the nodes are states and the arcs between nodes are actions.
A path in the state space is a sequence of states connected by a sequence of actions.
Thr goal test determines whether the given state is a goal state.
A path cost function assigns numeric cost to each action. For the Romania problem the cost
of path might be its length in kilometers.
The step cost of taking action a to go from state x to state y is denoted by c(x,a,y). The step
cost for Romania are shown in figure 1.18. It is assumed that the step costs are non negative.
A solution to the problem is a path from the initial state to a goal state.
An optimal solution has the lowest path cost among all solutions.
o States: The agent is in one of two locations.,each of which might or might not contain dirt.
Thus there are 2 x 22 = 8 possible world states.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
The 8-puzzle
An 8-puzzle consists of a 3x3 board with eight numbered tiles and a blank space. A tile adjacent to
the balank space can slide into the space. The object is to reach the goal state ,as shown in figure 2.4
Example: The 8-puzzle
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
8-queens problem
The goal of 8-queens problem is to place 8 queens on the chessboard such that no queen
attacks any other.(A queen attacks any piece in the same row,column or diagonal).
Figure 2.5 shows an attempted solution that fails: the queen in the right most column is
attacked by the queen at the top left.
An Incremental formulation involves operators that augments the state description,starting
with an empty state.for 8-queens problem,this means each action adds a queen to the state.
A complete-state formulation starts with all 8 queens on the board and move them around.
In either case the path cost is of no interest because only the final state counts.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
ROUTE-FINDING PROBLEM
Route-finding problem is defined in terms of specified locations and transitions along links
between them. Route-finding algorithms are used in a variety of applications,such as routing in
computer networks,military operations planning,and air line travel planning systems.
TOURING PROBLEMS
Touring problems are closely related to route-finding problems,but with an important difference.
Consider for example,the problem,”Visit every city at least once” as shown in Romania map.
As with route-finding the actions correspond to trips between adjacent cities. The state space,
however,is quite different.
The initial state would be “In Bucharest; visited{Bucharest}”.
A typical intermediate state would be “In Vaslui;visited {Bucharest,Urziceni,Vaslui}”.
The goal test would check whether the agent is in Bucharest and all 20 cities have been visited.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
VLSI layout
A VLSI layout problem requires positioning millions of components and connections on a chip
to minimize area ,minimize circuit delays,minimize stray capacitances,and maximize
manufacturing yield. The layout problem is split into two parts : cell layout and channel
routing.
ROBOT navigation
ROBOT navigation is a generalization of the route-finding problem. Rather than a discrete set
of routes,a robot can move in a continuous space with an infinite set of possible actions and
states. For a circular Robot moving on a flat surface,the space is essentially two-dimensional.
When the robot has arms and legs or wheels that also must be controlled,the search space
becomes multi-dimensional. Advanced techniques are required to make the search space finite.
INTERNET SEARCHING
In recent years there has been increased demand for software robots that perform Internet
searching.,looking for answers to questions,for related information,or for shopping deals. The
searching techniques consider internet as a graph of nodes(pages) connected by links.
SEARCH TREE
Having formulated some problems,we now need to solve them. This is done by a search through
the state space. A search tree is generated by the initial state and the successor function that
together define the state space. In general,we may have a search graph rather than a search
tree,when the same state can be reached from multiple paths.
Figure 1.23 shows some of the expansions in the search tree for finding a route from Arad to
Bucharest.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 1.23 Partial search trees for finding a route from Arad to Bucharest. Nodes that have
been expanded are shaded.; nodes that have been generated but not yet expanded are outlined in
bold;nodes that have not yet been generated are shown in faint dashed line
The root of the search tree is a search node corresponding to the initial state,In(Arad). The first
step is to test whether this is a goal state. The current state is expanded by applying the successor
function to the current state,thereby generating a new set of states. In this case,we get three new
states: In(Sibiu),In(Timisoara),and In(Zerind). Now we must choose which of these three
possibilities to consider further. This is the essense of search- following up one option now and
putting the others aside for latter,in case the first choice does not lead to a solution.
Search strategy . The general tree-search algorithm is described informally in Figure 1.24
.
Tree Search
The choice of which state to expand is determined by the search strategy. There are an infinite
number paths in this state space ,so the search tree has an infinite number of nodes.
A node is a data structure with five components :
o STATE : a state in the state space to which the node corresponds;
o PARENT-NODE : the node in the search tree that generated this node;
o ACTION : the action that was applied to the parent to generate the node;
o PATH-COST :the cost,denoted by g(n),of the path from initial state to the node,as
indicated by the parent pointers; and
o DEPTH : the number of steps along the path from the initial state.
It is important to remember the distinction between nodes and states. A node is a book keeping
data structure used to represent the search tree. A state corresponds to configuration of the world.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 1.25 Nodes are data structures from which the search tree is
constructed. Each has a parent,a state, Arrows point from child to parent.
Fringe
Fringe is a collection of nodes that have been generated but not yet been expanded. Each element
of the fringe is a leaf node,that is,a node with no successors in the tree. The fringe of each tree
consists of those nodes with bold outlines.
The collection of these nodes is implemented as a queue.
The general tree search algorithm is shown in Figure 2.9
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Uninformed Search Strategies have no additional information about states beyond that provided
in the problem definition.
Strategies that know whether one non goal state is “more promising” than another are called
Informed search or heuristic search strategies.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 1.27 Breadth-first search on a simple binary tree. At each stage ,the node to be expanded next
is indicated by a marker.
Properties of breadth-first-search
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
solution is at depth d. In the worst case,we would expand all but the last node at level
d,generating bd+1 - b nodes at level d+1.
Then the total number of nodes generated is
b + b2 + b3 + …+ bd + ( bd+1 + b) = O(bd+1).
Every node that is generated must remain in memory,because it is either part of the fringe or is an
ancestor of a fringe node. The space compleity is,therefore ,the same as the time complexity
2.5.1.3 DEPTH-FIRST-SEARCH
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Depth-first-search always expands the deepest node in the current fringe of the search tree. The
progress of the search is illustrated in figure 1.31. The search proceeds immediately to the
deepest level of the search tree,where the nodes have no successors. As those nodes are
expanded,they are dropped from the fringe,so then the search “backs up” to the next shallowest
node that still has unexplored successors.
Figure 1.31 Depth-first-search on a binary tree. Nodes that have been expanded and have no
descendants in the fringe can be removed from the memory;these are shown in black. Nodes at
depth 3 are assumed to have no successors and M is the only goal node.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Depth-first-search has very modest memory requirements.It needs to store only a single path
from the root to a leaf node,along with the remaining unexpanded sibling nodes for each node on
the path. Once the node has been expanded,it can be removed from the memory,as soon as its
descendants have been fully explored(Refer Figure 2.12).
For a state space with a branching factor b and maximum depth m,depth-first-search requires
storage of only bm + 1 nodes.
Using the same assumptions as Figure 2.11,and assuming that nodes at the same depth as the goal
node have no successors,we find the depth-first-search would require 118 kilobytes instead of 10
petabytes,a factor of 10 billion times less space.
Drawback of Depth-first-search
The drawback of depth-first-search is that it can make a wrong choice and get stuck going down
very long(or even infinite) path when a different choice would lead to solution near the root of the
search tree. For example ,depth-first-search will explore the entire left subtree even if node C is a
goal node.
BACKTRACKING SEARCH
A variant of depth-first search called backtracking search uses less memory and only one successor
is generated at a time rather than all successors.; Only O(m) memory is needed rather than O(bm)
2.3.4.4 DEPTH-LIMITED-SEARCH
The problem of unbounded trees can be alleviated by supplying depth-first-search with a pre-
determined depth limit l.That is,nodes at depth l are treated as if they have no successors. This
approach is called depth-limited-search. The depth limit soves the infinite path problem.
Depth limited search will be nonoptimal if we choose l > d. Its time complexity is O(bl) and its
space compleiy is O(bl). Depth-first-search can be viewed as a special case of depth-limited search
with l = oo
Sometimes,depth limits can be based on knowledge of the problem. For,example,on the map of
Romania there are 20 cities. Therefore,we know that if there is a solution.,it must be of length 19 at
the longest,So l = 10 is a possible choice. However,it oocan be shown that any city can be reached
from any other city in at most 9 steps. This number known as the diameter of the state space,gives
us a better depth limit.
Depth-limited-search can be implemented as a simple modification to the general tree-search
algorithm or to the recursive depth-first-search algorithm. The pseudocode for recursive depth-
limited-search is shown in Figure 1.32.
It can be noted that the above algorithm can terminate with two kinds of failure : the standard
failure value indicates no solution; the cutoff value indicates no solution within the depth limit.
Depth-limited search = depth-first search with depth limit l,
returns cut off if any path is cut off by depth limit
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 1.33 The iterative deepening search algorithm ,which repeatedly applies depth-limited-
search with increasing limits. It terminates when a solution is found or if the depth limited search
resturns failure,meaning that no solution exists.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
S S
S
Limit = 0 A D
Limit = 1
S S S
A D A D
B D A E
Limit = 2
Figure 1.35
Figure 1.36
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 1.38 Evaluation of search strategies,b is the branching factor; d is the depth of the
shallowest solution; m is the maximum depth of the search tree; l is the depth limit. Superscript
caveats are as follows: a complete if b is finite; b complete if step costs >= E for positive E; c
optimal if step costs are all identical; d if both directions use breadth-first search.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Repeated states can be the source of great inefficiency: identical sub trees will be explored many
times!
A A
B B B
C C C C C
Figure 1.39
Figure 1.40
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 1.41 The General graph search algorithm. The set closed can be implemented with a hash
table to allow efficient checking for repeated states.
o No sensor
o Initial State(1,2,3,4,5,6,7,8)
o After action [Right] the state (2,4,6,8)
o After action [Suck] the state (4, 8)
o After action [Left] the state (3,7)
o After action [Suck] the state (8)
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure
Time and space complexity are always considered with respect to some measure of the problem
difficulty. In theoretical computer science ,the typical measure is the size of the state space.
In AI,where the graph is represented implicitly by the initial state and successor function,the
complexity is expressed in terms of three quantities:
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Search-cost - typically depends upon the time complexity but can also include the term for
memory usage.
Total–cost – It combines the search-cost and the path cost of the solution found.
-----------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
-----------------------------------------------------------------------------------------------------------------------------
h(n) = extimated cost of the cheapest path from node n to a goal node.
For example,in Romania,one might estimate the cost of the cheapest path from Arad to Bucharest
via a straight-line distance from Arad to Bucharest(Figure 2.1).
Heuristic function are the most common form in which additional knowledge is imparted to the
search algorithm.
Greedy Best-first search
Greedy best-first search tries to expand the node that is closest to the goal,on the grounds that
this is likely to a solution quickly.
It evaluates the nodes by using the heuristic function f(n) = h(n).
Taking the example of Route-finding problems in Romania , the goal is to reach Bucharest starting
from the city Arad. We need to know the straight-line distances to Bucharest from various cities as
shown in Figure 2.1. For example, the initial state is In(Arad) ,and the straight line distance
heuristic hSLD(In(Arad)) is found to be 366.
Using the straight-line distance heuristic hSLD ,the goal state can be reached faster.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 2.2 stages in greedy best-first search for Bucharest using straight-line distance heuristic
hSLD. Nodes are labeled with their h-values.
Figure 2.2 shows the progress of greedy best-first search using hSLD to find a path from Arad to
Bucharest. The first node to be expanded from Arad will be Sibiu,because it is closer to Bucharest
than either Zerind or Timisoara. The next node to be expanded will be Fagaras,because it is closest.
Fagaras in turn generates Bucharest,which is the goal.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
A* Search
A* Search is the most widely used form of best-first search. The evaluation function f(n) is
obtained by combining
(1) g(n) = the cost to reach the node,and
(2) h(n) = the cost to get from the node to the goal :
f(n) = g(n) + h(n).
A* Search is both optimal and complete. A* is optimal if h(n) is an admissible heuristic. The obvious
example of admissible heuristic is the straight-line distance hSLD. It cannot be an overestimate.
A* Search is optimal if h(n) is an admissible heuristic – that is,provided that h(n) never
overestimates the cost to reach the goal.
An obvious example of an admissible heuristic is the straight-line distance hSLD that we used in
getting to Bucharest. The progress of an A* tree search for Bucharest is shown in Figure 2.2.
The values of ‘g ‘ are computed from the step costs shown in the Romania map( figure 2.1). Also
the values of hSLD are given in Figure 2.1.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 2.3 Stages in A* Search for Bucharest. Nodes are labeled with f = g + h . The h-values are
the straight-line distances to Bucharest taken from figure 2.1
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
function RFBS( problem, node, f_limit) return a solution or failure and a new f-
cost limit
if GOAL-TEST[problem](STATE[node]) then return node
successors EXPAND(node, problem)
if successors is empty then return failure, ∞
for each s in successors do
f [s] max(g(s) + h(s), f [node])
repeat
best the lowest f-value node in successors
if f [best] > f_limit then return failure, f [best]
alternative the second lowest f-value among successors
result, f [best] RBFS(problem, best, min(f_limit, alternative))
if result failure then return result
Figure 2.4 The algorithm for recursive best-first search
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 2.5 Stages in an RBFS search for the shortest route to Bucharest. The f-limit value for each
recursive call is shown on top of each current node. (a) The path via Rimnicu Vilcea is followed
until the current best leaf (Pitesti) has a value that is worse than the best alternative path (Fagaras).
(b) The recursion unwinds and the best leaf value of the forgotten subtree (417) is backed up to
Rimnicu Vilcea;then Fagaras is expanded,revealing a best leaf value of 450.
(c) The recursion unwinds and the best leaf value of the forgotten subtree (450) is backed upto
Fagaras; then Rimni Vicea is expanded. This time because the best alternative path(through
Timisoara) costs atleast 447,the expansion continues to Bucharest
RBFS Evaluation :
RBFS is a bit more efficient than IDA*
– Still excessive node generation (mind changes)
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
The 8-puzzle
The 8-puzzle is an example of Heuristic search problem. The object of the puzzle is to slide the tiles
horizontally or vertically into the empty space until the configuration matches the goal
configuration(Figure 2.6)
The average cost for a randomly generated 8-puzzle instance is about 22 steps. The branching factor
is about 3.(When the empty tile is in the middle,there are four possible moves;when it is in the
corner there are two;and when it is along an edge there are three). This means that an exhaustive
search to depth 22 would look at about 322 approximately = 3.1 X 1010 states.
By keeping track of repeated states,we could cut this down by a factor of about 170,000,because
there are only 9!/2 = 181,440 distinct states that are reachable. This is a manageable number ,but the
corresponding number for the 15-puzzle is roughly 1013.
If we want to find the shortest solutions by using A*,we need a heuristic function that never
overestimates the number of steps to the goal.
The two commonly used heuristic functions for the 15-puzzle are :
(1) h1 = the number of misplaced tiles.
For figure 2.6 ,all of the eight tiles are out of position,so the start state would have h1 = 8. h1 is an
admissible heuristic.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
(2) h2 = the sum of the distances of the tiles from their goal positions. This is called the city
block distance or Manhattan distance.
h2 is admissible ,because all any move can do is move one tile one step closer to the goal.
Tiles 1 to 8 in start state give a Manhattan distance of
h2 = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18.
Figure 2.7 Comparison of search costs and effective branching factors for the ITERATIVE-
DEEPENING-SEARCH and A* Algorithms with h1,and h2. Data are average over 100 instances of
the 8-puzzle,for various solution lengths.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
o If the rules are relaxed so that a tile can move to any adjacent square, then h2(n) gives the
shortest solution
o In such cases, we can use local search algorithms. They operate using a single current
state(rather than multiple paths) and generally move only to neighbors of that state.
o The important applications of these class of problems are (a) integrated-circuit
design,(b)Factory-floor layout,(c) job-shop scheduling,(d)automatic
programming,(e)telecommunications network optimization,(f)Vehicle routing,and (g)
portfolio management.
OPTIMIZATION PROBLEMS
Inaddition to finding goals,local search algorithms are useful for solving pure optimization
problems,in which the aim is to find the best state according to an objective function.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 2.8 A one dimensional state space landscape in which elevation corresponds to the
objective function. The aim is to find the global maximum. Hill climbing search modifies the
current state to try to improve it ,as shown by the arrow. The various topographic features are
defined in the text
Hill-climbing search
The hill-climbing search algorithm as shown in figure 2.9, 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.
current MAKE-NODE(INITIAL-STATE[problem])
loop do
neighbor a highest valued successor of current
if VALUE [neighbor] ≤ VALUE[current] then return STATE[current]
current neighbor
Figure 2.9 The hill-climbing search algorithm (steepest ascent version),which is the most basic
local search technique. At each step the current node is replaced by the best neighbor;the neighbor
with the highest VALUE. If the heuristic cost estimate h is used,we could find the neighbor with the
lowest h.
Hill-climbing is sometimes called greedy local search because it grabs a good neighbor state
without thinking ahead about where to go next. Greedy algorithms often perform quite well.
Problems with hill-climbing
Hill-climbing often gets stuck for the following reasons :
o Local maxima : a local maximum is a peak that is higher than each of its neighboring
states,but lower than the global maximum. Hill-climbing algorithms that reach the vicinity
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
of a local maximum will be drawn upwards towards the peak,but will then be stuck with
nowhere else to go
o Ridges : A ridge is shown in Figure 2.10. Ridges results in a sequence of local maxima that
is very difficult for greedy algorithms to navigate.
o Plateaux : A plateau is an area of the state space landscape where the evaluation function is
flat. It can be a flat local maximum,from which no uphill exit exists,or a shoulder,from
which it is possible to make progress.
Figure 2.10 Illustration of why ridges cause difficulties for hill-climbing. The grid of states(dark
circles) is superimposed on a ridge rising from left to right,creating a sequence of local maxima that
are not directly connected to each other. From each local maximum,all th available options point
downhill.
Hill-climbing variations
Stochastic hill-climbing
o Random selection among the uphill moves.
o The selection probability can vary with the steepness of the uphill move.
First-choice hill-climbing
o cfr. stochastic hill climbing by generating successors randomly until a better one is
found.
Random-restart hill-climbing
o Tries to avoid getting stuck in local maxima.
Simulated annealing search
A hill-climbing algorithm that never makes “downhill” moves towards states with lower value(or
higher cost) is guaranteed to be incomplete,because it can stuck on a local maximum.In contrast,a
purely random walk –that is,moving to a successor choosen uniformly at random from the set of
successors – is complete,but extremely inefficient.
Simulated annealing is an algorithm that combines hill-climbing with a random walk in someway
that yields both efficiency and completeness.
Figure 2.11 shows simulated annealing algorithm. It is quite similar to hill climbing. Instead of
picking the best move,however,it picks the random move. If the move improves the situation,it is
always accepted. Otherwise,the algorithm accepts the move with some probability less than 1. The
probability decreases exponentially with the “badness” of the move – the amount E by which the
evaluation is worsened.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Simulated annealing was first used extensively to solve VLSI layout problems in the early 1980s. It
has been applied widely to factory scheduling and other large-scale optimization tasks.
Figure 2.11 The simulated annealing search algorithm,a version of stochastic hill climbing where
some downhill moves are allowed.
Genetic algorithms
A Genetic algorithm(or GA) is a variant of stochastic beam search in which successor states are
generated by combining two parent states,rather than by modifying a single state.
Like beam search,Gas begin with a set of k randomly generated states,called the population. Each
state,or individual,is represented as a string over a finite alphabet – most commonly,a string of 0s
and 1s. For example,an 8 8-quuens state must specify the positions of 8 queens,each in acolumn of
8 squares,and so requires 8 x log2 8 = 24 bits.
Figure 2.12 The genetic algorithm. The initial population in (a) is ranked by the fitness function in
(b),resulting in pairs for mating in (c). They produce offspring in (d),which are subjected to
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
mutation in (e).
Figure 2.12 shows a population of four 8-digit strings representing 8-queen states. The production
of the next generation of states is shown in Figure 2.12(b) to (e).
In (b) each state is rated by the evaluation function or the fitness function.
In (c),a random choice of two pairs is selected for reproduction,in accordance with the probabilities
in (b).
Figure 2.13 describes the algorithm that implements all these steps.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
It is helpful to visualize a CSP as a constraint graph,as shown in Figure 2.15(b). The nodes of the
graph corresponds to variables of the problem and the arcs correspond to constraints.
Figure 2.15 (a) Principle states and territories of Australia. Coloring this map can be viewed as
aconstraint satisfaction problem. The goal is to assign colors to each region so that no neighboring
regions have the same color.
Figure 2.15 (b) The map coloring problem represented as a constraint graph.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
CSP,where the variables Q1,Q2,…..Q8 are the positions each queen in columns 1,….8 and each
variable has the domain {1,2,3,4,5,6,7,8}. If the maximum domain size of any variable in a CSP is
d,then the number of possible complete assignments is O(dn) – that is,exponential in the number of
variables. Finite domain CSPs include Boolean CSPs,whose variables can be either true or false.
Infinite domains
Discrete variables can also have infinite domains – for example,the set of integers or the set of
strings. With infinite domains,it is no longer possible to describe constraints by enumerating all
allowed combination of values. Instead a constraint language of algebric inequalities such as
Startjob1 + 5 <= Startjob3.
(ii) CSPs with continuous domains
CSPs with continuous domains are very common in real world. For example ,in operation research
field,the scheduling of experiments on the Hubble Telescope requires very precise timing of
observations; the start and finish of each observation and maneuver are continuous-valued variables
that must obey a variety of astronomical,precedence and power constraints. The best known
category of continuous-domain CSPs is that of linear programming problems,where the
constraints must be linear inequalities forming a convex region. Linear programming problems can
be solved in time polynomial in the number of variables.
Varieties of constraints :
(i) unary constraints involve a single variable.
Example : SA # green
(ii) Binary constraints involve paris of variables.
Example : SA # WA
(iii) Higher order constraints involve 3 or more variables.
Example : cryptarithmetic puzzles.
Figure 2.16 (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 zeros are allowed. (b) The constraint
hypergraph for the cryptarithmetic problem,showint the Alldiff constraint as well as the
column addition constraints. Each constraint is a square box connected to the variables it
contains.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 2.17 A simple backtracking algorithm for constraint satisfaction problem. The algorithm is
modeled on the recursive depth-first search
Figure 2.17(b) Part of search tree generated by simple backtracking for the map coloring problem.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Constraint propagation
Although forward checking detects many inconsistencies, it does not detect all of them.
Constraint propagation is the general term for propagating the implications of a constraint on one variable
onto other variables.
Arc Consistency
k-Consistency
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Independent Subproblems
Tree-Structured CSPs
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
2.4.1 Games
Mathematical Game Theory,a branch of economics,views any multiagent environment as a game
provided that the impact of each agent on the other is “significant”,regardless of whether the agents
are cooperative or competitive. In,AI,”games” are deterministic,turn-taking,two-player,zero-sum
games of perfect information. This means deterministic,fully observable environments in which
there are two agents whose actions must alternate and in which the utility values at the end of the
game are always equal and opposite. For example,if one player wins the game of chess(+1),the
other player necessarily loses(-1). It is this opposition between the agents’ utility functions that
makes the situation adversarial.
Game Tree
The initial state and legal moves for each side define the game tree for the game. Figure 2.18
shows the part of the game tree for tic-tac-toe (noughts and crosses). From the initial state,MAX has
nine possible moves. Play alternates between MAX’s placing an X and MIN’s placing a 0 until we
reach leaf nodes corresponding to the terminal states such that one player has three in a row or all
the squares are filled. He number on each leaf node indicates the utility value of the terminal state
from the point of view of MAX;high values are assumed to be good for MAX and bad for MIN. It is
the MAX’s job to use the search tree(particularly the utility of terminal states) to determine the best
move.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 2.18 A partial search tree . The top node is the initial state,and MAX move first,placing an X in an
empty square.
2.4.2 Optimal Decisions in Games
In normal search problem,the optimal solution would be a sequence of move leading to a goal
state – a terminal state that is a win. In a game,on the other hand,MIN has something to say about
it,MAX therefore must find a contingent strategy,which specifies MAX’s move in the initial
state,then MAX’s moves in the states resulting from every possible response by MIN,then MAX’s
moves in the states resulting from every possible response by MIN those moves,and so on. An
optimal strategy leads to outcomes at least as good as any other strategy when one is playing an
infallible opponent.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 2.19 A two-ply game tree. The nodes are “MAX nodes”,in which it is AMX’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.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
complexity of the minimax algorithm is O(bm). The space complexity is O(bm) for an
algorithm that generates successors at once.
o α : the value of the best(i.e.,highest-value) choice we have found so far at any choice point
along the path of MAX.
o β: 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. The complete algorithm is
given in Figure 2.21.
The effectiveness of alpha-beta pruning is highly dependent on the order in which the successors
are examined. It might be worthwhile to try to examine first the successors that are likely to be the
best. In such case,it turns out that alpha-beta needs to examine only O(bd/2) nodes to pick the best
move,instead of O(bd) for minimax. This means that the effective branching factor becomes sqrt(b)
instead of b – for chess,6 instead of 35. Put anotherway alpha-beta cab look ahead roughly twice as
far as minimax in the same amount of time.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
Figure 2.21 The alpha beta search algorithm. These routines are the same as the
minimax routines in figure 2.20,except for the two lines in each of MIN-VALUE and
MAX-VALUE that maintain α and β
Evaluation functions
An evaluation function returns an estimate of the expected utility of the game from a given position,just as
the heuristic function return an estimate of the distance to the goal.
Games of imperfect information
o Minimax and alpha-beta pruning require too much leaf-node evaluations.
May be impractical within a reasonable amount of time.
o SHANNON (1950):
o Cut off search earlier (replace TERMINAL-TEST by CUTOFF-TEST)
o Apply heuristic evaluation function EVAL (replacing utility function of alpha-beta)
Cutting off search
Change:
– if TERMINAL-TEST(state) then return UTILITY(state)
into
– if CUTOFF-TEST(state,depth) then return EVAL(state)
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
• e.g., w1 = 9 with
f1(s) = (number of white queens) – (number of black queens), etc.
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
In real life,there are many unpredictable external events that put us into unforeseen situations.
Many games mirror this unpredictability by including a random element,such as throwing a dice.
Backgammon is a typical game that combines luck and skill. Dice are rolled at the beginning of
player’s turn to determine the legal moves. The backgammon position of Figure 2.23,for
example,white has rolled a 6-5,and has four possible moves.
Figure 2.23 A typical backgammon position. The goal of the game is to move all
one’s pieces off the board. White moves clockwise toward 25,and black moves
counterclockwise toward 0. A piece can move to any position unless there are
multiple opponent pieces there; if there is one opponent ,it is captured and must
start over. In the position shown,white has rolled 6-5 and must choose among four
legal moves (5-10,5-11),(5-11,19-24),(5-10,10-16),and (5-11,11-16)
------------------------------------------------------------------------------------------------------------------------
https://play.google.com/store/apps/details?id=com.sss.edubuzz360
www.edubuzz360.com
These equations can be backed-up recursively all the way to the root of the game
tree.
------------------------------------------------------------------------------------------------------
https://play.google.com/store/apps/details?id=com.sss.edubuzz360