Professional Documents
Culture Documents
● Constraint satisfaction is a technique where a problem is solved when its values satisfy certain constraints or rules
of the problem.
Such type of technique leads to a deeper understanding of the problem structure as well as its
complexity.
● Constraint satisfaction problems (or CSPs) consist of variables with constraints on them.
● CSPs are mathematical questions defined as a set of objects whose state must satisfy a number of constraints or
limitations.
Department of CSE, GST ECS302: AI 2
Continued...
• A constraint satisfaction problem consists of three components, X,D, and C:
X is a set of variables, {X1, . . . ,Xn}.
D is a set of domains, {D1, . . . ,Dn}, one for each variable.
C is a set of constraints that specify allowable combinations of values.
• Each domain Di consists of a set of allowable values, {v1, . . . , vk} for variable Xi.
Relation: It is an explicit list of all tuples of values that satisfy the constraint, or
as an abstract relation that supports two operations:
testing if a tuple is a member of the relation and enumerating the members of the
relation.
Ex: if X1 and X2 both have the domain {A,B}, then the constraint saying the two variables must have different
values can be written as (X1,X2), [(A,B), (B,A)] or as (X1,X2),X1 ≠ X2.
• Each state in a CSP is defined by an assignment of values to some or all of the variables,
{Xi =vi, Xj = vj , . . .}.
• We are given the task of coloring each region of Australia map either red, green, or blue in such a way that
no neighbouring regions have the same colour.
• Since there are nine places where regions border, there are nine constraints:
C = {SA ≠ WA, SA ≠ NT, SA ≠ Q, SA ≠ NSW, SA ≠ V, WA ≠ NT, NT ≠ Q, Q ≠ NSW, NSW ≠ V } .
• SA ≠ WA is a shortcut for <(SA,WA), SA ≠ WA>,
where SA ≠ WA can be fully enumerated in turn as
{(red , green), (red , blue), (green, red ), (green, blue), (blue, red ), (blue, green)} .
• Constraints can assert that one task must occur before another—
for example, a wheel must be installed before the hubcap is put on—and that
only so many tasks can go on at once.
• Constraints can also specify that a task takes a certain amount of time to complete.
install axles (front and back), affix all four wheels (right and left, front and back),
tighten nuts for each wheel, affix hubcaps, and inspect the final assembly.
• X = {AxleF, AxleB, WheelRF, WheelLF, WheelRB, WheelLB, NutsRF, NutsLF, NutsRB, NutsLB,
CapRF, CapLF, CapRB, CapLB, Inspect} .
• The value of each variable is the time that the task starts.
• In our example, the axles have to be in place before the wheels are put on, and it takes 10 minutes to install an
axle, so we write
• Next we say that, for each wheel, we must affix the wheel (which takes 1 minute),
then tighten the nuts (2 minutes), and finally attach the hubcap (1 minute, but not represented yet):
• Suppose we have four workers to install wheels, but they have to share one tool that helps put the axle in place.
• We need a disjunctive constraint to say that AxleF and AxleB must not overlap in time; either one comes first or
the other does:
(AxleF + 10 ≤ AxleB) or (AxleB + 10 ≤ AxleF ).
• We also need to assert that the inspection comes last and takes 3 minutes.
• For every variable except Inspect, we add a constraint of the form X +dX ≤ Inspect .
• Finally, suppose there is a requirement to get the whole assembly done in 30 minutes.
Binary constraint:
It relates two variables.
Ex: SA ≠ NSW is a binary constraint.
A binary CSP is one with only binary constraints. It can be represented as a Constraint graph.
Global constraint:
It is a constraint involving an arbitrary number of variables.
(it need not involve all the variables in a problem)
Ex: Alldiff , which says that all of the variables involved in the constraint must have different values.
Cryptarithmetic Problem:
● Cryptarithmetic Problem is a type of constraint satisfaction problem where the game is about digits
and its unique replacement either with alphabets or other symbols.
● Cryptarithmetic problem is a mathematical puzzle, in which the digits (0-9) get substituted by some possible
alphabets or symbols.
● The task in cryptarithmetic problem is to substitute each digit with an alphabet to get the result arithmetically
correct.
● This problem has one most important constraint that is, we cannot assign a different digit to the same character.
All digits should contain a unique alphabet.
● There should be only one carry forward, while performing the addition operation on a problem.
● The problem can be solved from both sides, i.e., left hand side (L.H.S), or righthand side (R.H.S).
Sudoku:
● Consider a Sudoku game with some numbers filled initially in some squares.
● You are expected to fill the empty squares with numbers ranging from 1 to 9 in such a way that no row, column or
a block has a number repeating itself.
● The remaining squares that are to be filled are known as variables, and the range of numbers (1-9) that can fill
them is known as a domain.
● Variables take on values from the domain. The conditions governing how a variable will choose its domain are
known as constraints.
Variables:
X = {A1, A2, …, I8, I9}.
We’ll just have a variable for each cell in the sudoku puzzle for a total of 81 variables.
The variable A1 is just a variable that represents the cell in the Ath row and the 1st column.
Domains:
D = {1, 2, 3, 4, 5, 6, 7, 8, 9}.
For the domain of each variable, we’ll just start with all of the numbers from 1 to 9.
Constraints:
We’ll have three types of constraints here:
a constraint that says all of the variables in each column has to differ,
all of the variables in each row has to differ, and
all of the variables in each square has to differ.
● At a very high level, the algorithm assigns a value to each variable one-by-one
until either reaching a valid assignment or an invalid assignment that violates some constraint,
at which point, it backtracks to a place in the search where there are no violations yet.
It keeps only a single representation of a state and alters that representation rather than creating new ones.
Steps:
● Which variable should be assigned next (SELECT -UNASSIGNED -VARIABLE ), and in what order should its values be
tried (ORDER -DOMAIN -VALUES )?
● What inferences should be performed at each step in the search (INFERENCE)?
● When the search arrives at an assignment that violates a constraint, can the search avoid repeating this failure?
Ex: Map colouring
• Graph coloring is the procedure of assignment of colors to each vertex of a graph G such that no adjacent vertices
get same color.
• The objective is to minimize the number of colors while coloring a graph.
• The smallest number of colors required to color a graph G is called its chromatic number of that graph.
Department of CSE, GST ECS302: AI 24
Continued...
6.3.1 Variable and Value Ordering:
● The simplest strategy for SELECT-UNASSIGNED-VARIABLE is to choose the next unassigned variable in order,
{X1,X2, . . .}.
● This static variable ordering seldom results in the most efficient search.
In fact, after SA is assigned, the choices for Q, NSW, and V are all forced.
● Choosing the variable with the fewest “legal” values—is called the minimum- remaining-values (MRV) heuristic.
• Whenever a variable X is assigned, the forward-checking process establishes arc consistency for it:
• Although forward checking detects many inconsistencies, it does not detect all of them.
• The problem is that it makes the current variable arc-consistent, but doesn’t look ahead and make all the other
variables arc-consistent.
Ex: Consider the third row of Figure 6.7.
It shows that when WA is red and Q is green, both NT and SA are forced to be blue.
Forward checking does not look far enough ahead to notice that this is an inconsistency:
NT and SA are adjacent and so cannot have the same value.
• The BACKTRACKING-SEARCH algorithm in Figure 6.5 has a very simple policy for what to do when a branch of the
search fails:
back up to the preceding variable and try a different value for it.
This is called chronological backtracking because the most recent decision point is revisited.
A more intelligent approach to backtracking is to backtrack to a variable that might fix the problem—
a variable that was responsible for making one of the possible values of SA impossible.
• To do this, we will keep track of a set of assignments that are in conflict with some value for SA.
• The set (in this case { Q=red, NSW=green, V=blue }), is called the conflict set for SA.
• The backjumping method backtracks to the most recent assignment in the conflict set;
in this case, backjumping would jump over Tasmania and try a new value for V .
● In choosing a new value for a variable, the most obvious heuristic is to select the value
that results in the minimum number of conflicts with other variables the min-conflicts heuristic.
• Independence can be ascertained simply by finding connected components of the constraint graph.
• A constraint graph is a tree when any two variables are connected by only one path.
• To solve a tree-structured CSP, first pick any variable to be the root of the tree, and choose an ordering of the
variables such that each variable appears after its parent in the tree.
• Such an ordering is called a topological sort.
• Any tree with n nodes has n−1 arcs, so we can make this graph directed arc-consistent in O(n) steps.
• Since each link from a parent to its child is arc consistent, we know that for any value we choose for the parent,
there will be a valid value left to choose for the child.
• That means we won’t have to backtrack; we can move linearly through the variables.
Department of CSE, GST ECS302: AI 33
Continued...
Reducing Constraint graphs: There are two ways.
(1) The first approach is based on removing nodes.
• It involves assigning values to some variables so that the remaining variables form a tree.
• From the constraint graph for Australia (6.12(a)),
if we could delete South Australia, the graph would become a tree (6.12(b)).
• We can do this by fixing a value for SA and deleting from the domains of the other variables
any values that are inconsistent with the value chosen for SA.
• Now, any solution for the CSP after SA and its constraints are removed will be consistent with the value chosen for
SA.
6.13 Tree decomposition of the map colouring problem into five sub-problems.
Department of CSE, GST ECS302: AI 35
Continued...
• Tree decomposition must satisfy the following three requirements:
Every variable in the original problem appears in at least one of the sub-problems.
If two variables are connected by a constraint in the original problem, they must appear together (along with the
constraint) in at least one of the sub-problems.
If a variable appears in two sub-problems in the tree, it must appear in every sub-problem along the path
connecting those sub-problems.
• The first two conditions ensure that all the variables and constraints are represented in the decomposition.
• The third condition reflects the constraint that any given variable must have the same value in every sub-problem
in which it appears.
****