Adversarial Search - P2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Constraint Satisfaction

Sometimes a problem is not embedded in a long set of action sequences but requires picking the
best option from available choices. A good general-purpose problem solving technique is to list
the constraints of a situation (either negative constraints, like limitations, or positive elements
that you want in the final solution). Then pick the choice that satisfies most of the constraints.
Formally speaking, 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 t 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 ; : : :} An assignment that does
not violate any constraints is called a consistent or legal assignment. A complete assignment is
one in which every variable is mentioned, and a solution to a CSP is a complete assignment that
satisfies all the constraints. Some CSPs also require a solution that maximizes an objective
function.
CSP can be given an incremental formulation as a standard search problem as follows:
1. Initial state: the empty assignment fg, in which all variables are unassigned.
2. Successor function: a value can be assigned to any unassigned variable, provided that it
does not conflict with previously assigned variables.
3. Goal test: the current assignment is complete.
4. Path cost: a constant cost for every step
Many troubles in AI can be regarded as problems of constraint satisfaction, where the goal state
pleases a specified set of constraint.

!
Caution Constraint satisfaction problems can be solved by means of any of the search
approaches.
The common form of the constraint satisfaction procedure is as follows: Until a
whole solution is located or until all paths have led to lead ends, do
1. Choose an unexpanded node of the search graph.
2. Apply the constraint inference rules to the chosen node to generate all possible new
constraints.
3. If the set of constraints encloses a contradiction, then report that this path is a dead end.
4. If the set of constraints illustrates a total solution then report success.
5. If neither a constraint nor a complete solution has been located then apply the rules to
produce new partial solutions. Insert these partial solutions into the search graph.

Example: Consider the crypt arithmetic problems.


SEND
+ MORE
—————
MONEY
—————
Allocate decimal digit to all the letters in such a manner that the answer to the problem is correct
to the same letter appears more than once, it must be allocated the same digit each time. No two
different letters may be allocated the same digit. Consider the below given crypt arithmetic
problem.
SEND
+ MORE
-----------
MONEY
-----------
Constraints:
1. No two digit can be allocated to same letter.
2. Only single digit number can be allocate to a letter.
3. No two letters can be allocated same digit.
4. Assumption can be prepared at different levels such that they do not oppose each other.
5. The problem can be divided into secured constraints. A constraint satisfaction strategy may
be used.
6. Any of search techniques may be utilized.
7. Backtracking may be performed as applicable us applied search techniques.
8. Rule of arithmetic may be followed.
Initial state of problem.
D=?
E =?
Y=?
N=?
R=?
O=?
S=?
M=?
C1 = ?
C2 = ?
C1, C2, C3 stands for the carry variables respectively.
Goal State: The digits to the letters must be allocated in such a manner so that the sum is satisfied.
Solution Process:
We are following the depth-first technique to solve the problem.
1. Initial guess m=1 since the sum of two single digits can generate at most a carry ‘1’.
2. When n=1 o=0 or 1 since the largest single digit number added to m=1 can produce the
sum of either 0 or 1 depend on the carry obtained from the carry sum. By this we say that
o=0 because m is already 1 hence we cannot assign same digit another letter (rule no.)
3. We have m=1 and o=0 to get o=0 we have s=8 or 9, again based on the carry obtained from
the earlier sum.
The similar process can be repeated further. The problem has to be composed into different
constraints. And each constraints is to be satisfied by guessing the likely digits that the letters can
be assumed that the initial supposition has been already made . Rest of the process is being
revealed in the form of a tree, by means of depth-first search for the clear understandability of
the solution process.

After Step 1 we derive are more conclusion that Y contradiction should generate a Carry. That is
D+2>9

D > 6 (Controduction)
After Step 2, we found that C1 cannot be Zero, Since Y has to a carry to satisfy goal state. From
this step onwards, no need to branch for C1 = 0.
Step – 3
We have assigned digit to every letter in accordance with the constraints and production rules.
Now by backtracking, we find the different digits assigned to different letters and hence reach
the solution state.
Solution State:
Y=2
D=7
S=9
R=8
N=6
E=5
O=0
M=1
C1 = 1
C2 = 0
C3 = 0
C3(0) C2(1) C1(1)
S(9) E(5) N(6) D(7)
+ M(1) O(0) R(8) E(5)
M(1) O(0) N(6) E(5) Y(2)

Example: Given Problem:


CROSS
+ROADS
——————
DANGER
——————
Constraints & Production Rules:
Same rules as used for the previous problem.
Initial State of Problem:
C=?
R=?
D=?
A=?
O=?
N=?
G=?
S=?
E=?
C1 = ?
C2 = ?
C3 = ?
C4 = ?
Goal State:
The Digits to the Letters should be allocated in such a way. So that, the sum is satisfied.
Solution Process:
Again, I am following depth-first search technique to solve the problem.
1. Initial Guess, D=1. Since the sum of two single digits can, at most, generate a carry ‘1’.
2. Now, we begin guessing the digits and try to solve the problem. The supposing and the
consequent effect of it is exposed in the form of a tree below.

After the Step 1, w see that the initial guess is not correct. Because all the guesses following that
have been checked, which has lead to the contradiction. Thus we move to second step with the
change in the initial guess.
Step – 2

At Step (2) we have allocated a single digit to every letter in accordance with the constraints and
production rules.
Now by backtracking, we discover the different digits allocated to dissimilar letters and therefore
reach the solution state.
Solution State:
C=9
N=8
G=7
A=5
O=2
E=4

D=1
R=6
S =3
C1 = 0
C2 = 0
C3 = 0
C4 = 0
C4(0) C3 C2(0) C1(0)
C9 R(6) O(2) S(3) S(3)
+ R6 O(2) A(5) D(1) S(3) D(1)
A(5) N(8) G(7) E(4) R(6)
Example: The map coloring problem.

The task of coloring each region red, green or blue in such a way that no
neighboring regions have the same color.

We are given the task of coloring each region red, green, or blue in such a way that the
neighboring regions must not have the same color.

To formulate this as CSP, we define the variable to be the regions: WA, NT, Q, NSW,
V, SA, and
T. The domain of each variable is the set {red, green, blue}. The constraints require
neighboring regions to have distinct colors: for example, the allowable combinations
for WA and NT are the pairs
{(red,green),(red,blue),(green,red),(green,blue),(blue,red),(blue,green)}. (The
constraint can also be represented as the inequality WA ≠ NT). There are many
possible solutions, such as {WA = red, NT = green, Q = red, NSW = green, V = red,
SA = blue, T = red}.Map of Australia showing each of its states and territories

Constraint Graph: A CSP is usually represented as an undirected graph, called


constraint graph where the nodes are the variables and the edges are the
binaryconstraints.
The map-coloring problem represented as a constraint graph.

CSP can be viewed as a standard search problem as follows:

1. Initial state : the empty assignment {},in which all variables are
unassigned.
2. Successor function: a value can be assigned to any unassigned variable,
provided that it does not conflict with previously assigned variables.
3. Goal test: the current assignment is complete.
4. Path cost: a constant cost(E.g.,1) for every step.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy