Unit 2 From Constraint Propagtion
Unit 2 From Constraint Propagtion
Constraint propagation
Constraint propagation is the process of communicating the domain reduction of a decision variable
to all of the constraints that are stated over this variable. This process can result in more domain
reductions. These domain reductions, in turn, are communicated to the appropriate constraints. This
process continues until no more variable domains can be reduced or when a domain becomes empty
and a failure occurs. An empty domain during the initial constraint propagation means that the model
has no solution.
For example, consider the decision variables y with an initial domain [0..10], z with an initial domain
[0..10] and t with an initial domain [0..1], and the constraints
y + 5*z <= 4
t != z
t != y
The domain reduction of the constraint y + 5*z <= 4 reduces the domain of y to [0..4] and z to
[0]. The variable z is thus fixed to a single value. Constraint propagation invokes domain
reduction of every constraint involving z. Domain reduction is invoked again for the constraint y
+ 5*z <= 4, but the variable domains cannot be reduced further. Domain reduction of the
constraint t != z is invoked again, and because z is fixed to 0, the constraint removes the value 0
from the domain of t. The variable t is now fixed to the value 1, and constraint propagation
invokes domain reduction of every constraint involving t, namely t != z and t != y. The
constraint that can reduce domains further is t != y. Domain reduction removes the value 1 from
the domain of y.
y = [0 2..4],
z = [0] and
t = [1].
2. Backtracking Search
Backtracking algorithm
Backtrack(s)
return false
if is a new solution
backtrack(expand s)
Step 3: If the current point is not an endpoint, backtrack and explore other points, then repeat
the preceding steps.
State-Space Tree
A space state tree is a tree that represents all of the possible states of the problem, from the root
as an initial state to the leaf as a terminal state
You need to arrange the three letters x, y, and z so that z cannot be next to x.
According to the backtracking, you will first construct a state-space tree. Look for all possible
solutions and compare them to the given constraint. You must only keep solutions that meet the
following constraint:
The following are possible solutions to the problems: (x,y,z), (x,z,y), (y,x,z), (y,z,x), (z,x,y)
(z,y,x).Nonetheless, valid solutions to this problem are those that satisfy the constraint that keeps
only (x,y,z) and (z,y,x) in the final solution set.
6. {
8. {
15. }
16. }
1. Backtracking Algorithm(s)
5.{
6.s=1;
7. While (s!= 0) do
8.{
9.If ( there remains are untried z [1] £ X ( z [1], z [2], ….., z [s-1]) and Bk (z[1], ….., z[s]) is true) then
10. {
13. S = s + 1
14. }
16.}
17.}
x() returns the set of all possible values assigned to the solution vector's first component, z1. The
component z1 will accept values that satisfy the bounding function B1 (z1).As you progress
through this tutorial, you will see some of the applications of the backtracking.
Game playing
making and game theory. It provides an optimal move for the player assuming that
o Min-Max algorithm is mostly used for game playing in AI. Such as Chess, Checkers, tic-
tac-toe, go, and various tow-players game. This Algorithm computes the minimax
o In this algorithm two players play the game, one is called MAX and other is called MIN.
o Both the players fight it as the opponent player gets the minimum benefit while they get
o Both Players of the game are opponent of each other, where MAX will select the
o The minimax algorithm performs a depth-first search algorithm for the exploration of the
o The minimax algorithm proceeds all the way down to the terminal node of the tree, then
Step-1: In the first step, the algorithm generates the entire game-tree and apply the utility
function to get the utility values for the terminal states. In the below tree diagram, let's take A is
the initial state of the tree. Suppose maximizer takes first turn which has worst-case initial value
=- infinity, and minimizer will take next turn which has worst-case initial value = +infinity.
.
Step 2: Now, first we find the utilities value for the Maximizer, its initial value is -∞, so we will
compare each value in terminal state with initial value of Maximizer and determines the higher
nodes values. It will find the maximum among the all
o Complete- Min-Max algorithm is Complete. It will definitely find a solution (if exist), in
o Time complexity- As it performs DFS for the game-tree, so the time complexity of Min-
Max algorithm is O(bm), where b is branching factor of the game-tree, and m is the
which is O(bm).
1. Limited scope: The techniques and algorithms developed for game playing may not be
well-suited for other types of applications and may need to be adapted or modified for
different domains.
2. Computational cost: Game playing can be computationally expensive, especially for
complex games such as chess or Go, and may require powerful computers to achieve
real-time performance.
Alpha-Beta Pruning
A technique by which without checking each node of the game tree we can compute the correct
minimax decision, and this technique is called pruning. This involves two threshold parameter
Alpha and beta for future expansion, so it is called alpha-beta pruning. It is also called as Alpha-
Beta Algorithm.
o Alpha-beta pruning can be applied at any depth of a tree, and sometimes it not only prune
a. Alpha: The best (highest-value) choice we have found so far at any point along
o The Alpha-beta pruning to a standard minimax algorithm returns the same move as the
standard algorithm does, but it removes all the nodes which are not really affecting the
final decision but making algorithm slow. Hence by pruning these nodes, it makes the
algorithm fast.
α>=β
o While backtracking the tree, the node values will be passed to upper nodes instead of
o We will only pass the alpha, beta values to the child nodes.
4.
6. maxEva= -infinity
7. for each child of node do
11. if beta<=alpha
12. break
14.
21. if beta<=alpha
22. break
o Worst ordering: In some cases, alpha-beta pruning algorithm does not prune any of the
leaves of the tree, and works exactly as minimax algorithm. In this case, it also consumes
more time because of alpha-beta factors, such a move of pruning is called worst ordering.
In this case, the best move occurs on the right side of the tree. The time complexity for
o Ideal ordering: The ideal ordering for alpha-beta pruning occurs when lots of pruning
happens in the tree, and best moves occur at the left side of the tree. We apply DFS hence
it first search left of the tree and go deep twice as minimax algorithm in the same amount
This is a standard backgammon position. The object of the game is to get all of one’s pieces
off the board as quickly as possible. White moves in a clockwise direction toward 25, while
Black moves in a counterclockwise direction toward 0. Unless there are many opponent
pieces, a piece can advance to any position; if there is only one opponent, it is caught and
must start over. White has rolled a 6–5 and must pick between four valid moves: (5–10,5–11),
(5–11,19–24), (5–10,10–16), and (5–11,11–16), where the notation (5–11,11–16) denotes
moving one piece from position 5 to 11 and then another from 11 to 16.
White knows his or her own legal moves, but he or she has no idea how Black will roll, and
thus has no idea what Black’s legal moves will be. That means White won’t be able to build a
normal game tree-like in chess or tic-tac-toe. In backgammon, in addition to M A X and M I N
nodes, a game tree must include chance nodes. The figure below depicts chance nodes as
circles. The possible dice rolls are indicated by the branches leading from each chance node;
each branch is labelled with the roll and its probability. There are 36 different ways to roll two
dice, each equally likely, yet there are only 21 distinct rolls because a 6–5 is the same as a 5–
6. P (1–1) = 1/36 because each of the six doubles (1–1 through 6–6) has a probability of 1/36.
Each of the other 15 rolls has a 1/18 chance of happening.
The following phase is to learn how to make good decisions. Obviously, we want to choose
the move that will put us in the best position. Positions, on the other hand, do not have
specific minimum and maximum values. Instead, we can only compute a position’s
anticipated value, which is the average of all potential outcomes of the chance nodes.
As a result, we can generalize the deterministic minimax value to an expected-minimax value
for games with chance nodes. Terminal nodes, MAX and MIN nodes (for which the dice roll
is known), and MAX and MIN nodes (for which the dice roll is unknown) all function as
before. We compute the expected value for chance nodes, which is the sum of all outcomes,
weighted by the probability of each chance action.
where r is a possible dice roll (or other random events) and RESULT(s,r) denotes the same
state as s, but with the addition that the dice roll’s result is r.