Ai M3 Bit
Ai M3 Bit
Minimax algorithm computes the minimax The problem with minimax search is that the
decision from the current state. The recursion number of game states it has to examine is
proceeds all the way down to the leaves of the exponential in the depth of the tree. To avoid
tree, and then the minimax values are backed this, it is possible to compute the correct
up through the tree as the recursion unwinds. minimax decision without looking at every node
Minimax algorithm performs a complete depth- in the game tree by pruning. In alpha beta
first exploration of the game tree pruning algorithm it prunes away branches that
ALGORITHM cannot possibly influence the final decision.
function MINIMAX-DECISION(state) Alpha–beta pruning can be applied to trees of
returns an action any depth, and it is often possible to prune
return arg maxa ε ACTIONS (8) MIN- entire subtrees rather than just leaves, If Player
VALUE(RESULT(state, a)) has a better choice m either at the parent node
function MAX-VALUE(state) returns a utility of n or at any choice point further up, then n
value will never be reached in actual play. So once we
if TERMINAL-TEST(state) then return have found out enough about n (by examining
UTILITY(state) some of its descendants) to reach this
v <-- ∞ conclusion, we can prune it.
for each a in ACTIONS(state) do α = the value of the best choice we have found
V <-- MAX(v, MIN-VALUE(RESULT(s, a))) so far at any choice point along path for MAX.
return v β = the value of the best choice we have found
function MIN-VALUE(state) returns a utility so far at any choice point along path for MIN.
value Alpha–beta search updates the values of α and
if TERMINAL-TEST(state) then return β as it goes along and prunes the remaining
UTILITY(state) branches at a node (i.e., terminates the
V <-- ∞ recursive call) as soon as the value of the
for each a in ACTIONS(state) do current node is known to be worse than the
V <-- MIN(V, MAX-VALUE(RESULT(s, u))) current α or β value for MAX or MIN,
return v respectively. The outcome is that we can
Game tree identify the minimax decision without ever
The initial state, ACTIONS function, and RESULT evaluating two of the leaf nodes.
function define the game tree for the game a Least Constraining Value
tree where the nodes are game states and the Once a variable has been selected, the
edges are moves. From the initial state, MAX algorithm must decide on the order in which to
has nine possible moves. examine its values. Least-constraining-value
Play alternates between MAX’s placing an X and prefers the value that rules out the fewest
MIN’s placing an O until we reach leaf nodes choices for the neighboring variables in the
corresponding to terminal states such that one constraint graph. Interleaving search and
player has three in a row or all the squares are inference But inference can be even more
filled. The number on each leaf node indicates powerful in the course of a search: every time
the utility value of the terminal state from the we make a choice of a value for a variable, we
point of view of MAX; high values are assumed have a brand-new opportunity to infer new
to be good for MAX and bad for MIN. search domain reductions on neighbouring variables.
tree is a tree that is superimposed on the full
game tree, and examines enough nodes to
allow a player to determine what move to
make.
CONSTRAINT PROPAGATION: INFERENCE IN ADVERSARIAL SEARCH
CSPS: CSPs an algorithm can search or do a In which we examine the problems that arise
specific type of inference called constraint when we try to plan ahead in a world where
propagation using the constraints to reduce the other agents are planning against us.
number of legal values for a variable, which in > GAMES
turn can reduce the legal values for another Games are competitive environments, in which
variable, and so on. Constraint propagation the agent’s goals are in conflict. Games are easy
may be intertwined with search, or it may be to formalize. Games can be a good model of
done as a pre-processing step, before search real-world competitive or cooperative
starts. Sometimes this preprocessing can solve activities. E.g., Military confrontations,
whole problem, so no search is required at all. negotiation, auctions, etc
Local consistency > OPTIMAL DECISIONS IN GAMES
If we treat each variable as a node in a graph Minimax Value and Minimax Decision
and each binary constraint as an arc, then the The minimax value of a node is of being useful
process of enforcing local consistency in each in the corresponding state, assuming that both
part of the graph causes inconsistent values to players play optimally from there to the end of
be eliminated throughout the graph the game. The minimax value of a terminal
> Node consistency:Avariable with the values in state is just its utility(the state of being useful).
the variable’s domain satisfy the variable’s MAX prefers to move to a state of maximum
unary constraints. Eg: variant of the Australia value, whereas MIN prefers a state of minimum
map-coloring problem with South Australians value. The terminal nodes on the bottom level
dislike green, the variable SA starts with get their utility values from the game’s UTILITY
domain {red, green, blue}, and we can make it function. Minimax decision will be optimal
node consistent by eliminating green, leaving choice for MAX at root that leads to the state
SA with the reduced domain {red, blue}. with the highest minimax value
A network is node-consistent if every variable CONSTRAINT SATISFACTION PROBLEM
in the network is node-consistent. It is always A constraint satisfaction problem consists of
possible to eliminate all the unary constraints in three components, X, D, and C:
a CSP by running node consistency. • X is a set of variables, {X1,...,Xn}.
> Arc consistency : A variable in a CSP is arc- • D is a set of domains, {D1,...,Dn}, one for each
consistent if every value in its domain satisfies variable. • C is a set of constraints that specify
the variable’s binary constraints. Xi is arc- allowable combinations of values.
consistent with respect to another variable Xj. If Each domain Di consists of a set of allowable
for every value in the current domain Di there values, {v1,...,vk} for variable Xi. Each constraint
is some value in the domain Dj that satisfies the Ci consists of a pair scope, rel , where scope is a
binary constraint on the arc (Xi, Xj). A network tuple of variables that participate in the
is arc-consistent if every variable is arc constraint and rel is a relation that defines the
consistent with every other variable. values that those variables can take on.
> Path consistency: tightens the binary A relation can be represented as an explicit list
constraints by using implicit constraints that are of all tuples of values that satisfy the constraint.
inferred by looking at triples of variables. A An abstract relation that supports two
two-variable set {Xi, Xj} is path-consistent with operations:
respect to a third variable Xm if, • testing if a tuple is a member of the relation
• for every assignment {Xi = a, Xj = b} consistent and • enumerating the members of relation.
with the constraints on {Xi, Xj}, For example, if X1 and X2 both have the
• there is an assignment to Xm that satisfies the domain {A,B}, then the constraint saying the
constraints on {Xi, Xm} and {Xm, Xj}. two variables must have different values can be
This is called path consistency because one can written as:
think of it as looking at a path from Xi to Xj with {(X1,X2),[(A,B),(B,A)]} or as {(X1,X2),X1=! X2}
Xm in the middle.
Map coloring Types of constraints
We are given the task of coloring each region 1. Unary constraint- which restricts the value of
either red, green, or blue in such a way that no a single variable
neighboring regions have the same color. ◦ Eg, map-coloring problem it could be the case
that South Australians won’t tolerate the color
green; we can express that with the unary
constraint
2. binary constraint- relates two variables
◦ A binary CSP is one with only binary
constraints; it can be represented as a
constraint graph
3. We can also describe higher-order
constraints, such as asserting that the value of
X = {WA, NT, Q, NSW ,V, SA, T} Y is between X and Z, with the ternary
The domain of each variable is the set Di = {red, constraint Between(X, Y, Z).
green, blue}. The constraints require 4. global constraint- A constraint involving an
neighboring regions to have distinct colors. arbitrary number of variables
Since there are nine places where regions ◦ Eg, In Sudoku problems all variables in a row
border, there are nine constraints: or column must satisfy an Alldiffff , which says
that all of the variables involved in the
constraint must have different values.
Global constraints
is one involving an arbitrary number of
Here we are using abbreviations: SA=! WA is a variables but not necessarily all variables. Eg, in
shortcut for {(SA,WA) =! WA} where SA=! WA sudoku the Alldiffff constraint says that all the
can be fully enumerated in turn as variables involved must have distinct values.
{(red,green),(red,blue),(green,red),(green One simple form of inconsistency detection for
blue),(blue,red),(blue,green)}. Alldiffff constraints works as follows: if m
There are many possible solutions to this variables are involved in the constraint, and if
problem, such as {WA=red,NT=green,
they have n possible distinct values altogether,
Q=red,NSW=green, V=red, SA=blue, T= red} and m>n, then constraint cannot be satisfied.
Simple algorithm for global constraint
If m variables are involved in the constraint,
and if they have n possible distinct values
altogether, and m>n, then the constraint
cannot be satisfied.
1. First, remove any variable in the constraint
that has a singleton domain, and delete that
variable’s value from the domains of the
remaining variables. 2. Repeat as long as there
are singleton variables. If at any point an empty
domain is produced or there are more variables
than domain values left, then an inconsistency
has been detected.
BOUNDS PROPAGATION
For large resource-limited problems it is usually
not possible to represent the domain of each
variable as a large set of integers and gradually
reduce that set by consistency-checking
methods. E.g., logistical problems involving
moving thousands of people in 100 of vehicles
Backtracking Search for CSP The structure of CSP problem
Backtracking search algorithms that work on
partial assignments. A standard depth-limited
search can be applied. A state would be a
partial assignment, and an action would be
adding var = value to the assignment. But for a
CSP with n variables of domain size d, 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. We
generate a tree with n! · dn leaves, even though The structure of the problem as represented by
there are only dn possible complete the constraint graph can be used to find
assignments! Inference can be interwoven with solution quickly. e.g. The problem can be
search. decomposed into 2 independent subproblems:
Commutativity- crucial property common to Coloring T and coloring the mainland.
all CSPs : CSPs are all commutative. A problem > Tree: A constraint graph is a tree when any
is commutative if the order of application of two variables are connected by only one path.
any given set of actions has no effect on the > Directed arc consistency (DAC): A CSP is
outcome. CSPs are commutative because when defined to be directed arc-consistent under an
assigning values to variables, we reach the ordering of variables X1, X2, … , Xn if and only if
same partial assignment regardless of order. every Xi is arc-consistent with each Xj for j>i.
We need only consider a single variable at each By using DAC, any tree-structured CSP can be
node in the search tree. solved in time linear in the no. of variables.
ALGORITHM How to solve a tree-structure CSP:
>Pick any variable to be the root of the tree;
>Choose an ordering of the variable such that
each variable appears after its parent in the
tree. (topological sort) >Any tree with n nodes
has n-1 arcs, so we can make this graph
directed arc-consistent in O(n) steps, each of
which must compare up to d possible domain
values for 2 variables, for a total time of
O(nd2). > Once we have a directed arc-
consistent graph, we can just march down the
list of variables and choose any remaining
value.> Since each link from a parent to its child
is arc consistent, we won’t have to backtrack,
and can move linearly through the variables.
MAC (Maintaining Arc Consistency) algorithm There are 2 primary ways to reduce more
More powerful than forward checking, detect general constraint graphs to trees:
this inconsistency. After a variable Xi is assigned 1. Based on removing nodes; e.g. We can
a value, the INFERENCE procedure calls AC-3, delete SA from the graph by fixing a value for
but instead of a queue of all arcs in the CSP, we SA and deleting from the domains of other
start with only the arcs(Xj, Xi) for all Xj that are variables any values that are inconsistent with
unassigned variables that are neighbors of Xi. the value chosen for SA.
From there, AC-3 does constraint propagation 2. Based on collapsing nodes together : Tree
in the usual way, and if any variable has its decomposition: construct a tree decomposition
domain reduced to the empty set, the call to of constraint graph into a set of connected sub
AC-3 fails and we know to backtrack prblm, each sub prblm is solved independently,
immediately. and resulting solutions are then combined.