UNIT I(f)
UNIT I(f)
Constraint Satisfaction
1. Constraint satisfaction problem has various states and goal test, a tranditional problem has been
converted into standard structured and very simple "representation".
2. The general-purpose routines can be used to access a special representation which has more
benefit than problem-specific heuristics. These routines combined with special structure can find
solution of large problems.
3. The structure of the problem is represented in different form such as, standard representation of
the goal test.
i) Problem decomposition.
ii) To understand structure of problem and the diffculty of solving it and their connection.
i) As the representation of states have standard pattern [that is a set of variables with assigned
values], we can design successor function and goal test in generic way that will apply to all CSPs.
ii) We can develop effective generic heuristic that require no additional domain specific expertise.
iii) The structure of the constraint graph can be used to simplify the solution process in some cases
giving exponential reduction in complexity.
1. A constraint satisfaction problem is defined by a set of variables X1, X2,...., Xn and a set of
constraints C1, C2, ..., Cm.
3. Each constraint C1 involves some subset of the variables and specifies the allowable combinations
of values for that subset.
4. A state of the problem is defined by an assignment of values to some or all of the variables {Xi = Vi,
Xj = Vj,.... }
5. An assignment that does not violate any constraints is called a consistent or legal assignment.
6. A complete assignment is one in which every variable is mantained and a solution to a CSP is, a
complete assignment that satisfies all the constraints.
Constraints are -
1) We have three colours for colouring avertex.
2) No two adjacent vertices have same colour. Given three colours-(Red, Green, Blue). Allowable
combination for A, B vertices would be,
{(R, G), (R, B), (G, R), (G, B), (B, R), (B, G)}
Examples of CSP
1. The problem is to colour the regions of a given map such that no 2 adjacent regions have the same
colour. [Refer Fig. 6.1.2]
2. The regions in the map are the variables and the set of possible colours for the regions is the
domain.
3. The constraint is that "no two adjacent regions should have the same colour."
Example: N ≠ NW
Note
3. The topology of a constraint graph can sometimes be used to identify solutions easily.
Example Map
2. Other Examples of CSP
1. N-queens puzzle.
2. Jobshop scheduling.
3. Scene labelling.
6. Sudoku
7. Boolean satisfiability.
1. Assignment problems.
2. Transporation scheduling.
3. Hardware configuration.
4. Spreadsheets.
5. Factory scheduling.
6. Floor planning.
• It is fairly easy to see that a CSP can be given an incremental formulation as a standard serach
problem as follows:
i) Initial state -
A value can be assigned to any unassigned variable, provided that it does not conflict with previously
assigned variables.
1. Every solution must be a complete assignment and therefore appears at depth n if there are n
variables.
5. We can also use a complete-state formulation, in which every state is a complete assignment that
might or might not satisfy the constraints.
Variations in CSPs
1. The simplest kind of CSP involves variables that are discrete and have finite domains. Graph-
coloring problems are of this kind. The 8-queens problem described can also be viewed as finite-
domain CSP, where the variables Q1,..., Q8 are the positions of each queen in colums 1,..., 8 and each
variable has the domain (1, 2, 3, 4, 5, 6, 7, 8). If the maximum domain size of any variable is a CSP in
d, then the number of possible complete assignments are O(dn) that is exponential in the number of
variables.
2. Finite-domain CSPs include Boolean CSPs, whose variables can be either true or false. Boolean
CSPs include, as special cases, some NP-complete problems, such as 3SAT.
3. In most practical applications, however, general-purpose CSP algorithms can solve problems of
orders of magnitude larger than those solvable via the general-purpose search algorithms that we
saw.
4. Discrete variables can also have infinite domains-for example, the set of integers or the set of
strings.
5. Constraints satisfaction problems with continuous domains are very common in the real world and
are widely studied in the field of operations research.
For example, the scheduling of experiments on the Hubble Space 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
constraints must be linear inequalities.
Constraints in CSPs
1. Properties of Constraints
Constraints are used to guide reasoning of everyday common sense. The constraints have following
properties.
1. Constraints may specify partial infomation; constraint need not uniquely specify the values of its
variables.
2. Constraints are non-directional, typically a constraint on (say) two variables V1, V2 can be used to
infer a constraint on V1 given a constraint on V2 and viceversa.
3. Constraints are declarative; they specify what relationship must hold without specifying a
computational procedure to enforce that relationhip.
4. Constraints are additive; the order of imposition of constraints does not matter, all that matters at
the end is that the conjunction of constraints is in effect.
5. Constraints are really independent; typically constraints in the constraint store (i.e. collection of
constraints) share variables.
1. Unary constraint - Which restricts the value of a single variable. Every unary be eliminated simply
by prepressing the domain of the corresponding variable to remove any value that violates the
constraint.
For example- Constraint can be that, Vertex A can not be coloured with bluecolour.
2. Binary constraint - Relates two variables. A binary CSP is one with only binary constraints; it can be
represented as a constraint graph.
For example - In graph colouring problem two adjacent vertices can not have same colour.
3. Higher-order constraints -
Involves three or more variables. A familiar example is provided by cryptarithmetic puzzles. It insist
that each letter in a cryptarithmetic puzzle represent a different digit. Higher-order constraints can
be represented in a constraint hypergraph. Such as shown below:-
Example 1 -
Example 2 - Explain the constraint satisfaction procedure to solve the cryptarithmetic problem.
ii) Repeat until inconsistency or all objects are assigned valid values: Select an object and strengthen
as much as possible, the set of constraints that apply to object. If set of constraints are different from
previous set, then open all objects that share any of these constraints. Remove selected object.
4. Make a guess in order to proceed. Repeat until a solution is found or all possible solutions
exhausted;
i) Select an object with a no assigned value and try to strengthen its constraints.
ii) Recursively invoke constraint satisfaction with the current set of constraints plus the selected
strengthening constraint.
The CSP can be represented in terms of the constraint graph. A constrain graph has,
1. Nodes as variables (For example In graph-colouring problem the vertex is variable which needs to
be coloured. This vertex will be a node in constraint graph.)
2. Arcs as a constraints (For example - In graph-colouring problem the arc will denote that no two
adjacent vertices will have same colour.)
1. The organization of constraint graph is very much useful for simplification of CSP's solutions.
• This problem, first posed in a German chess magazine almost 150 years ago, requires that 8 queens
be placed on an 8 x 8 chessboard in such a way that no two queens attack each other, i.e. no two
queens occupy the same row, column, or diagonal.
• This problem can be formally represented as a CSP in several different ways, and as we shall see,
the choice of formal representation has a significant impact on the computational complexity of the
problem.
• Suppose, for example, that we choose to represent the problem by numbering the queens 1
through 8 and then defining a set Z of 64 variables, one for each square of the chessboard, where
each variable has domain D = {0, 1, 2, ..., 8} and a variable z having a value of i means that queen i
occupies the corresponding square if 1 ≤ i ≤ 8 or that the square is unoccupied if i = 0. This
formulation of the problem yields a search space of cardinality 964 ≈ 1.18 x 1061, making it
impractical from a computational perspective.
• Consider instead a representation with a set Z of 8 variables Q1, Q2, …Q8 representing the 8 rows of
the board, with the domain of each variable Q; being the set Di {1, 2, ..., 8); in this case the value of
the variable Q; represents the column in the ith row in which a queen is placed. The constraints can
then be specified as logical expressions of the form
i = j⇒ Qi = Qj
(i.e., no two queens are in the same diagonal). Note that we have implicitly incorporated one of the
problem constraints (that no two queens occupy the same row) as well as our reasoning about the
consequences of this constraint (it implies that each row must have precisely one queen in it) into
our representation. Note too that the cardinality of the search space is now reduced to 88 = 1.68 x
107 states.
• This example clearly illustrates the need to carefully select a representation for a CSP from among
the many formally valid possibilities, bearing in mind the computational complexity which each one
entails.
• To find all solutions to the N-queens problem, the CP solver systematically tries all possible
assignments of values to the variables, to see which ones give feasible solutions to the problem. In
the 4-queens problem, the solver starts at the leftmost column and successively places one queen in
each column, at a location that is not attacked by any previously placed queens.
• Propagation - Each time the solver assigns a value to a variable, the constraints add restrictions on
the possible values of the unassigned variables. These restrictions propagate to future variable
assignments. For example, in the 4-queens problem, each time the solver places a queen, it can't
place any other queens on the row and diagonals the current queen is on. Propagation can speed up
the search significantly by reducing the set of variable values the solver must explore.
• Backtracking occurs when either the solver can't assign a value to the next variable, due to the
constraints, or it finds a solution. In either case, the solver backtracks to a previous stage and
changes the value of the variable at that stage to a value that hasn't already been tried. In the 4-
queens example, this means moving a queen to a new square on the current column.
• The solver starts by arbitrarily placing a queen in the upper left corner. That's a hypothesis of sorts;
perhaps it will turn out that no solution exists with a queen in the upper left corner.
• Given this hypothesis, what constraints can we propagate? One constraint is that there can be only
one queen in a column (the gray Xs below), and another constraint prohibits two queens on the
same diagonal (the red Xs below).
• Our constraints propagated, we can test out another hypothesis, and place a second queen on one
of the available remaining squares. Our solver might decide to place in it the first available square in
the second column:
• After propagating the diagonal constraint, we can see that it leaves no available squares in either
the third column or last row:
• With no solutions possible at this stage, we need to backtrack. One option is for the solver to
choose the other available square in the second column. However, constraint propagation then
forces a queen into the second row of the third column, leaving no valid spots for the fourth queen:
• And so the solver must backtrack again, this time all the way back to the placement of the first
queen. We have now shown that no solution to the our queens problem will occupy a corner square.
• Since there can be no queen in the corner, the solver moves the first queen down by one, and
propagates, leaving only one spot for the second queen:
• Propagating again reveals only one spot left for the third queen:
• This is the first solution! If instructed the solver to stop after finding the first solution, it would end
here. Otherwise, it would backtrack again and place the first queen in the third row of the first
column.
Scene Labeling
• This is a subproblem of the vision problem, which seeks to deduce facts about the physical world
from visual representations of it. In the scene labeling problem we are given a 2-D line drawing of a
3-D scene and must label the components of the drawing in such a way as to make explicit the 3-D
structure the drawing represents.
• This problem has been studied extensively since the early 1970s; we will consider a simplified
version which was studied by David Waltz as part of his Ph.D. thesis at M.I.T. during this period. The
assumptions we make to achieve this simplification are:
1. Every vertex is trihedral (formed by the junction of three planar surfaces; implicitly, we assume
that all surfaces are planar).
2. Surfaces do not contain 0-width cracks (lines formed by the junction of coplanar surfaces).
3. No shadows (lines which represent projections of edges onto surfaces along the direction of light
sources) are allowed.
4. The scene is viewed from a general viewing position (roughly, for some sufficiently small ε > 0 we
can move our viewing point in an arbitrary direction by a distance of ε without any topologically
significant change in the resulting 2-D representation).
• It actually turns out, as was revealed by later work on the problem, that assumption 3 is not really
a simplification, since the information which can be deduced from the presence and positions of
shadows in some sense outweighs the potential for confusion with actual edges they bring with
them, but we will follow Waltz' path here and let the assumption stand.
• Although a detailed analysis of the problem is beyond the scope of this lecture, one of the
fundamental results of this analysis is that a relatively simple taxonomy of 4 classes of vertices and 4
classes of lines suffices to cover all physical possibilities, modulo the assumptions we have made.
While we will not give formal definitions of the classes here, they may be intuitively described as
follows:
2. T-Junction Vertices: Vertices at which one line segment ends in the middle of another.
3. Fork Vertices: Vertices at which three lines meet, with no angles greater than or equal to 180°
between any pair of them.
4. Arrow Vertices: Vertices at which three lines meet, with an angle greater than 180° between one
pair of them.
1. Convex Lines: Lines formed by the junction of two visible surfaces for which a line segment
connecting the two surfaces would be inside the solids they bound.
2. Concave Lines: Lines formed by the junction of two visible surfaces for which a line segment
connecting the two surfaces would be outside the solids they bound.
3. Right / Up Arrow Lines: Lines formed by the junction of one visible and one obscured surface,
with the visible surface lying below/to the right of the line.
4. Left / Down Arrow Lines: Lines formed by the junction of one visible and one obscured
surface,with the visible surface lying above/to the left of the line.
• Depending on the viewing location, these 4 classes of vertices and 4 classes of lines can be
combined to give the eighteen types of vertices shown in the following Fig. 6.2.1.
• Representative examples of each of these classes may be seen in the following drawing:
• As we shall see, the classification of vertices and lines in this way allows us to pose the scene
labeling problem as a CSP, with vertices as variables to be labeled with values from the list of classes
above; since each class of vertex can only have certain classes of lines meet to form it, the
restrictions imposed by the classification of the two vertices at the endpoints of each line must be
compatible, 90 which then provides us with the constraints.
2. Number the vertices (optionally, start with a boundary vertex) in some order.
3. Visit a vertex v (in the order of its numbering) and attempt to label it:
(b) Eliminate any labels that are not consistent with local constraints.
ii. If any label of A was eliminated, continue propagating the constraints until no more labels are
eliminated.
• If we are left with multiple labels on some lines, the scene can be interpreted in more than one
way. An exhaustive search through the remaining possible combinations will identify the valid
interpretations. This takes considerably less effort than an exhaustive search the entire search space.
On the other hand, if some lines do not have any labels left, the scene violates or more of the
assumptions made earlier.
• For instance, vertex J in the above figure violates the assumption that all vertices are trihedral. The
algorithm will end with the lines at vertex J having no labels.
Example
• As an example of the algorithm for scene-labeling, consider the scene shown in the following Fig.
6.2.4.
• Vertex 1 is an example of arrow vertices and as such, has three possible labels: (A1, A2, A3). Thus,
line (1, 2) has three possible labels : (+, -, ). These constrain the number of possible interpretations
that vertex 2 (an L-vertex) can have. Specifically, vertex 2 can have only the following four labels (L1,
L4, L5, L6). Call this constraint (i). Vertex 3 can also have three possible labels (A1, A2, A3}. These
allow line (2, 3) to have the the following labels: (+, -,. These act as an additional constraint on vertex
2 and together with comstraint (i), enable us to eliminate L4 as viable option. Propagating this back
to vertex 1, we can then eliminate A2 as one of the labels on vertex 1. This process can be repeated
till all possible constraints have been satisfied. We will be left with three interpretations of the scene.
• These are shown in the following Fig. 6.2.5.
• Fig. 6.2.6, below, illustrates schematically a room interior (from Ballard & Brown, 1982). The set of
objects are denoted by regional boundaries and the set of possible labels is {Door (D), Wall (W),
Ceiling (C), Floor (F), Bin
Unary Constraints
• A Floor is chequered
N-ary constraints
• Inititially we start with the complete set of possible labels for all the regions (2D), or surfaces (3D),
in the image. Applying the unary constraints leads to a reduction in the number of possible
labellings, but there is still ambiguity in at least 4 cases. These can be resolved by the N-ary
constraints.
• In the above example of a discrete labelling regions can only be labelled in a definite manner,
either a region is or is not a door. Scene labellings as a whole may be consistent or inconsistent. If a
scene cannot be consistently labelled then we might define that scene as impossible, as for example
in the case of impossible objects which are represented as line drawings in the AI textbooks. That is
all very well, but in an imperfect world it is somewhat unrealistic to ask for certainty in a labelled
scene. This leads to the idea of a probabilistic labelling, in which scene elements may be labelled
with probability in a continuum (0.0 to 1.0); for example the set of probabilities for a given region in
Fig. 6.2.6, might be { Door= 0.1, Bin= 0.3, Floor = 0.1, Wall = 0.2, Ceiling = 0.3}. An algorithm for
labelling the scene consistently should update these probabilities to obtain an optimum global
labelling satisfying as far as possible the unary characteristics of the regions, and the N-ary
characteristics of their relationships. We shall consider this further with the specific examples.xs of
subsequent sections.
• Each of the n object models may be represented by a set of m(i) primitives, where the parameter, i,
denotes the model number (1<<j<=n). These primitives might be surfaces within a B-Rep model,
space curves within a wire frame or B-Rep model, volumetric components in a CSG structure and so
on.
• Similarly, the segmented scene consists of a set of m(s) primitives, arising from segmentation of 3D
range data or 2D intensity data for example, such that
• The problem is to find the optimum injection mapping, Mp:Os →O;, from the set of scene features
defined by equation (6.2.3) to the set of model features define by equation (6.2.2) so that the
defined metric for the mapping Mp is a maximum,
• While selecting unassigned variable for computation if we look at some of the constraints earlier in
the search (or even before search begins), we can drastically reduce search space. Following are
techniques which are helpful for earlier constraints checks.
1. Forward checking is one of the potential technique which uses constraints more effectively during
search.
2. It removes values in neighbouring unassigned variables domain that conflict with assigned
variable.
6. Generic method, do
i) Assigns variable X.
Constraint Propagation
1. A combined approach of heuristic plus forward checking gives more reliable, accurate and efficient
results than a singular approch.
2. The forward checking propagates information from assigned to unassigned variables but can not
avoid or detect all failure.
4. The idea of arc consistency provides a fast method of constraint propagation that is substantially
stronger than forward checking. Here "arc" refers to a directed arc in the constraint graph.
2. X→Y is consistent if (for every value of X there is some allowed value Y. For (a) example [V2 → V1, is
consistent iff V1 = Red, V2 = Blue] (i.e. for every value of x in X there is some allowed value y in Y). This
is directed property example - [V1 = V2]
V1 = V2 is consistent iff
3. As directed arcs between variables represent the domains of specified variables, they are
consistent with each other.
1. Arc consistency is not capable of detecing all inconsistencies. Partial assignments [V1 = Red, V2 =
Red] are inconsistent.
3. A CSP is K-consistency if for any set of K-1 variables and for any consistent assignment to those
variable a consistent value can always be assigned to any Kth variable.
Note
1. Consistency means that each individual variable by itself is consistent; this is also called as node
consistency.
3. Consistency means that any pair of adjacent-variables can always be extended toa third
neighboring variable; this is also called as path consistency.
i) It is K-consistent.
ii) It is also (K-1) consistent, (K-2) consistent all the way down to 1 consistent. 5. This is an idealist
solution which requires O (nd) time instead of O (n2 d3).
Arc consistency
• There have been many advances in how constraint solvers search for solutions. We look first at a
pre-processing step which can greatly improve efficiency by pruning the search space, namely arc-
consistency. Following this, we'll look at two search methods, backtracking and forward checking
which keep assigning values to variables until a solution is found. Finally, we'll look at some heuristics
for improving the efficiency of the solver, namely how to order the choosing of the variables, and
how to order the assigning of the values to variables.
• The pre-processing routine for binary constraints known as arc-consistency involves calling a pair
(xi, xj) an arc and noting that this is an ordered pair, i.e., it is not the same as (xj, xi). Each arc is
associated with a single constraint Cij, which constrains variables xi and xj. We say that the arc (xi, xj) is
consistent if, for all values a in Di, there is a value b in Dj such that the assignment xi = a and xj = b
satisfies constraint Cij. Note that (xi, xj) being consistent doesn't necessarily mean that (xj, xi) is also
consistent. To use this in a pre-processing way, we take every pair of variables and make it arc-
consistent. That is, we take each pair (xi, xj) and remove variables from Di which make it inconsistent,
until it becomes consistent. This effectively removes values from the domain of variables, hence
prunes the search space and makes it likely that the solver will succeed (or fail to find a solution)
more quickly.
• To demonstrate the worth of performing an arc-consistency check before starting asearch for a
solution, we'll use an example from Barbara Smith's tutorial. Suppose that we have four tasks to
complete, A, B, C and D, and we're trying to schedule them. They are subject to the constraints that:
• We will model this problem with a variable for each of the task start times, namely startA, startB,
startC and startD. We'll also have a variable for the overall start time: start, and a variable for the
overall finishing time: finish. We will say that the domain for variable start is {0}, but the domains for
all the other variables is {0,1,...,11), because the summation of the duration of the tasks is 3 + 2 + 4 +
2 = 11. We can now translate our English specification of the constraints into our formal model. We
start with an intermediate translation thus:
• start ≤ startA
• startA +3 ≤ startB
• startA + 3 ≤ startC
• startB + 2 ≤ startD
• startC + 2 ≤ startD
• startD + 2 ≤ finish
• Then, by thinking about the values that each pair of variables can take simultaneously, we can write
the constraints as follows:
• Now, we will check whether each arc is arc-consistent, and if not, we will remove values from the
domains of variables until we get consistency. We look first at the arc (start, startA) which is
associated with the constraint {(0,0), (0,1), (0,2), ..., (0,11)} above. We need to check whether there is
any value, P, in Dstart that does not have a corresponding value, Q, such that (P,Q) satisfies the
constraint, i.e., appears in the set of assignable pairs. As Dstart is just {0}, we are fine. We next look at
the arc (startA, start), and check whether there is any value in DstartA, P, which doesn't have a
corresponding Q such that (P,Q) is in CstartA, start Again, we are OK, because all the values in
DstartA appear in CstartA,start
• If we now look at the arc (startA, startB), then the constraint in question is: {(0,3), (0,4), (0,11),
(1,4), (1,5), ..., (8,11)). We see that their is no pair of the form (9,Q) in the constraint, similarly no pair
of the form (10,Q) or (11,Q). Hence, this arc is not arc-consistent, and we have to remove the values
9, 10 and 11 from the domain of startA in order to make the arc consistent. This makes sense,
because we know that, if task B is going to start after task A, which has duration 3 hours, and they
are all going to have started by the eleventh hour, then task A cannot start after the eighth hour.
Hence, we can - and do - remove the values 9, 10 and 11 from the domain of startA.
• This method of removing values from domains is highly effective. As reported in Barbara Smith's
tutorial, the domains become quite small, as reflected in the following scheduling network shown in
Fig. 6.4.1
• We see that the largest domain size has only 5 values in it, which means that STOD quite a lot of
the search space has been pruned. In practice, to remove as many variables as possible in a CSP
which is dependent on precedence constraints, we have to work backwards, i.e., look at the start
time of the task, T, which must occur last, then make each arc of the form (startT, Y) consistent for
every variable Y. Following this, move on to the task which must occur second to last, etc. In CSPs
which only involve precedence constraints, arc-consistency is guaranteed to remove all values which
cannot appear in a solution to the CSP. In general, however, we cannot make such a guarantee, but
arc-consistency usually has some effect on the initial specification of a problem.
• The above discussed arc consistency for CSP is not directional at all as each arc is assumed in both
directions in the AC-x algorithms. Although, the node and arc consistency algorithms seem easy they
are still stronger than necessary for some problems, for example, for enabling backtrack-free search
in CSPs which constraints form trees. Therefore yet simpler concept was proposed to achieve some
form of consistency, namely, Directional Arc Consistency (DAC) that is defined under total ordering of
the variables.
• Definition: A CSP is directional arc consistent under an ordering of variables (0.0) if and only if
every arc (Vi, Vj) in its constraint graph such that such that i < j according to the ordering is arc
consistent.
• Notice the difference between AC and DAC, in AC we check every arc (V;, V) 92639 while in DAC
only the arcs (Vi, Vj) where i < j are considered. Consequently, the arc consistency is stronger than
directional arc consistency, i.e., arc consistent CSP Jon is also directional arc consistent but not vice
versa (directional arc consistent CSP is not necessarily arc consistent as well).
procedure
DAC-1(G)
for
j = nodes (G) | to 1 by -1
do
for each
do
REVISE (Vi,Vj)
end for
end for
end
DAC-1
• In principle, more values can be removed through constraint propagation in more tightly constraint
problems. The directional arc-consistency is sufficient for backtrack-free solving of CSPs which
constraints form trees. In this case, it is possible to order the nodes (variables) starting from the tree
root and concluding at tree leaves. If the graph (tree) is made directional arc-consistent using this
order of then it is possible to find the solution by assigning values to variables in the same Jean order.
The directional arc-consistency guarantees that for each value of the root (parent) we will find
consistent values in daughter. nodes and so on till the values of the leaves. Consequently, no
backtracking is necessary to find a complete consistent assignment.
• If we apply BFS to generic CSP problems then we can notice that 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. Therfore a tree with 'n! * d' leaves is generated
even though there are only 'dn' possbile complete assignments.
2. Apply backtracking search. If backtracking search successful returns a solution else, a failure state
which return a procedure recursive-backtracking.
3. Procedure recursive-backtracking starts with empty set and takes input as CSP problem.
6. If value is complete and consistent according to constraints then assign value to variable, add that
to list.
9. If result is failure then remove variable with specific value from assignment. It will return failure
status.
Limitations of Backtracking
1. A success function is generated with above algorithm. But backtracking is not effective for very
large problems.
2. The general performance is not so good. Domain specific heuristic function combined with
uninformed search algorithm can generate better searching result.
We can also solve CSP without knowing the domain-specific knowledge. Here we need to design a
module which resolve following queries:
1. Which variable is assigned in next step and what order values can be tried?
Improvements of Backtracking
• Backtracking suffers from thrashing that is there is partial solutions that cannot be extended to a
full solution and may be reprocessed several times (always leading to a dead end in the search space)
To improve (practical) performance by preprocessing the search space underneath the currently
selected variable improving (in a dynamic way) can be carried out. The search strategy can use either
of the two schemes (related to the two phases of backtracking search), namely look-ahead and look-
back strategy.
• Look-ahead strategy is invoked when next variable or next value is selected. For example: Which
variable should be instantiated next? prefer variables that impose tighter constraints on the rest of
the search space. Which value should be chosen for the next variable? maximize the number of
options for future assignments
• Look-back strategy is invoked when the backtracking step is performed after reaching a dead end.
• For example: How deep should we backtrack? Also avoid irrelevant backtrack points (by analyzing
reasons for the dead end and jumping back to the source of failure). How can we learn from dead
ends? Record reasons for dead ends as new constraints so that the same inconsistencies can be
avoided at later stages of the search.
Review Questions
1. Define constraint satisfaction problem and solve the following cryptarithmetic problem: FORTY +
TEN + TEN SIXTY. (Refer section 6.1)
2. Define constraint satisfaction problem and solve the following cryptarithmetic problem: TWO +
TWO = FOUR. (Refer section 6.1)
3. Write a backtracking search function for constraint satisfaction problem and write a map coloring
representation as a constraint graph for the following figure. (Refer section 6.1)
4. Describe how to propagate information through constraints with example. (Refer section 6.3)
5. Explain the approaches for solving tree structured constraint satisfaction problem with suitable
example. (Refer section 6.1)
6. Write the rule for generating propagating constraints for solving the given cryptarithmetic
problem: SEND + MORE = MONEY. (Refer section 6.1)
7. Using CSP, explore the search space to solve the following cryptarithmatic problem.
TAKE
+A
+CAKE
9. Solve the following crypt-arithmetic problem using constraint satisfaction method, LOGIC LOGIC
PROLOG
You can assign unique single digit number from 0 to 9 to an alphabet. (Refer section 6.1)
AU: May-10
Ans.: CSP are problems whose state and goal test conform to a standard structured and very simple
representation. CSP's are defined using set of variables and set of constraints on those variables. The
variables have some allowed values from specified domain. For example Graph colouring problem.
(Given graph and set of colours, colour each vertex such that no two adjacent vertices have same
colour)
AU: Dec.-14
Ans.: CSP are problems whose state and goal test conform to a standard structured and very simple
representation. CSP's are defined using set of variables and set of constraints on those variables. The
variables have some allowed values from specified domain. For example Graph colouring problem.
(Given graph and set of colours, colour each vertex such that no two adjacent vertices have same
colour)