1
00:00:53,930 --> 00:00:59,590
Today we start with the lecture ten of the
course Artificial Intelligence. In the last
2
00:00:59,590 --> 00:01:06,260
class we introduced what you mean by constraint
satisfaction problems and we looked at how
3
00:01:06,260 --> 00:01:13,260
we cast such problems as search problems and
solve them by depth first search with backtracking.
4
00:01:13,910 --> 00:01:20,910
Today we will explore some more efficient
techniques for solving constraint satisfaction
5
00:01:21,030 --> 00:01:24,830
problems.
6
00:01:24,830 --> 00:01:29,330
The instructional objectives of today’s
class are as follows:
7
00:01:29,330 --> 00:01:35,630
In this class the student will be introduced
to more efficient search for constraint satisfaction
8
00:01:35,630 --> 00:01:41,009
problem. We will talk about the following
strategies:
9
00:01:41,009 --> 00:01:48,009
Forward checking and then we will look at
constraint propagation algorithms like the
10
00:01:48,460 --> 00:01:55,460
AC-3 algorithm. Then we will briefly talk
about intelligent backtracking or backjumping.
11
00:01:59,110 --> 00:02:06,100
On taking these topics the student should
be able to apply these techniques to constraint
12
00:02:06,100 --> 00:02:12,709
satisfaction problems.
13
00:02:12,709 --> 00:02:19,709
Before we start let us recapitulate the formulation
we did for constraint satisfaction problems.
14
00:02:25,110 --> 00:02:32,110
If you remember, the sort of constraint satisfaction
problems we had a number of variables and
15
00:02:38,640 --> 00:02:45,640
each variable has a domain. So v1 is a variable
and v1 has a domain it can take a set of values.
16
00:02:50,120 --> 00:02:57,120
v2 is another variable it can take some set
of values. So we have different variables
17
00:03:00,820 --> 00:03:07,820
along with their domains. Our objective is
to assign variables to values and the value
18
00:03:11,780 --> 00:03:18,780
for a particular variable must come from its
domain and the constraints must be satisfied.
19
00:03:22,299 --> 00:03:29,299
We especially looked at a most common type
of constraint called binary constraints. Binary
20
00:03:34,970 --> 00:03:41,970
constraints involve a pair of variables. Suppose
we can have a constraint saying that v1 and
21
00:03:42,549 --> 00:03:49,549
v2 cannot have the same value this is one
type of constraint. We can say that the constraint
22
00:03:50,090 --> 00:03:56,269
between the variables v2 and v3 is that the
value of v3 must be greater than the value
23
00:03:56,269 --> 00:04:03,269
of v2. So we have a set of variables, each
variable has a domain. The variables must
24
00:04:05,049 --> 00:04:09,900
be assigned values from the domains such that
the constraints are satisfied.
25
00:04:09,900 --> 00:04:16,900
This is a general class of constraint satisfaction
problems. These constraint satisfaction problems
26
00:04:19,609 --> 00:04:26,030
can be cast as state space search problems
and we can do the search in the following
27
00:04:26,030 --> 00:04:33,030
manner: We pick up a variable, so this is
the start, when none of the variables are
28
00:04:33,090 --> 00:04:39,370
assigned any values so v1 is not assigned
a value, v2 is not assigned a value, v3 is
29
00:04:39,370 --> 00:04:43,520
not assigned a value and so on. So this is
the empty state where none of the variables
30
00:04:43,520 --> 00:04:50,520
are assigned any values. In the next step
we look at the assignment of different values
31
00:04:53,680 --> 00:05:00,680
to variable v1. Suppose variable v1 can take
the values 1, 2, 4, 7 we have 4 branches corresponding
32
00:05:02,900 --> 00:05:09,400
to all the possible values that v1 can take.
33
00:05:09,400 --> 00:05:16,400
In the next state we have to pick up another
variable. Let us say we pick up v2 and we
34
00:05:16,479 --> 00:05:22,599
have to look at all possible assignments of
values to v2 that are consistent with the
35
00:05:22,599 --> 00:05:29,599
assignment that we have so far. For example,
if v1 has the domain 1, 2, 4, 7 and v2 has
36
00:05:34,699 --> 00:05:41,699
the domain 2, 3, 4 then if v1 is already one
v2 can be either 2 or 3 or 4. If v1 is 2 then
37
00:05:54,960 --> 00:06:01,960
v2 can be either 3 or 4. We cannot have v2
is equal to 2 because any further assignment
38
00:06:02,560 --> 00:06:07,930
after we have v1 is equal to 2, v2 is equal
to 2 will not undo this constraint. So if
39
00:06:07,930 --> 00:06:14,930
we have an assignment which is inconsistent
we should not proceed further in that direction.
40
00:06:15,729 --> 00:06:22,729
Next, suppose we have another variable v3
which has a domain 1 and 5 and we have the
41
00:06:32,229 --> 00:06:39,229
constraint that the value of v3 must be greater
than the value of v2 then in this case v3
42
00:06:40,379 --> 00:06:46,379
can only take the value of 5, in this case
v3 again can only take the value of 5 and
43
00:06:46,379 --> 00:06:53,379
so on. So, in this way we can construct the
search tree corresponding to the constraint
44
00:06:55,270 --> 00:07:02,270
satisfaction problem and we note that a solution
to the constraint satisfaction problem is
45
00:07:06,150 --> 00:07:13,150
a leaf in the search tree which corresponds
to all variables being assigned to specific
46
00:07:14,610 --> 00:07:17,830
values that do not violate any constraints.
47
00:07:17,830 --> 00:07:24,830
Therefore, if there are n variables all the
leaves at level n are the different solutions
48
00:07:27,550 --> 00:07:34,550
to the search problem. And the strategy which
is appropriate for solving such search problems
49
00:07:35,219 --> 00:07:41,930
is depth first search. Whenever we find that
a constraint is violated we do backtracking.
50
00:07:41,930 --> 00:07:48,930
This backtracking is called chronological
backtracking because we backtrack to the previous
51
00:07:50,379 --> 00:07:57,379
choice point. So, depth first search with
chronological back tracking is a very appropriate
52
00:07:58,060 --> 00:08:04,330
method for solving constraint satisfaction
search problems.
53
00:08:04,330 --> 00:08:11,330
We also discussed that we can try to make
this search efficient by looking at a proper
54
00:08:17,400 --> 00:08:24,400
order in which we choose the next variable
that we select next for assignment. So if
55
00:08:30,949 --> 00:08:37,949
you take a proper order of the variables we
might end up in reaching the first solution
56
00:08:39,659 --> 00:08:46,659
much faster. And then once we pick a variable
to assign values too we will be considering
57
00:08:47,190 --> 00:08:53,060
in what order should we assign values to these
variables.
58
00:08:53,060 --> 00:08:58,910
Then we will look at other questions like,
can we detect inevitable failure earlier?
59
00:08:58,910 --> 00:09:03,620
So, in the general search problem we said
that whenever we see that a constraint is
60
00:09:03,620 --> 00:09:10,620
violated we terminate the search at that point
and then backtrack to the previous choice
61
00:09:11,070 --> 00:09:18,070
point. But it may be the case that future
problems can be detected even earlier on.
62
00:09:19,470 --> 00:09:26,470
Let us see some techniques to handle that
and then there is a question whether we can
63
00:09:27,000 --> 00:09:33,690
take advantage of the problem structure to
further prune the search specific to a particular
64
00:09:33,690 --> 00:09:40,690
problem. One heuristic to choose the next
variable is the minimum remaining value heuristic.
65
00:09:49,850 --> 00:09:56,350
In the minimum remaining value heuristic the
variable with the fewest remaining values
66
00:09:56,350 --> 00:09:57,920
is chosen next.
67
00:09:57,920 --> 00:10:01,440
What do you mean by variable with the fewest
remaining values?
68
00:10:01,440 --> 00:10:08,440
Every variable has a domain. So when we have
a partial search tree some of the variables
69
00:10:14,860 --> 00:10:21,860
have been already assigned values and as a
result of assigning values to v2 and v3 the
70
00:10:23,670 --> 00:10:29,940
domain of v1 has become restricted, the domain
of v4 has become restricted, domain of v5
71
00:10:29,940 --> 00:10:36,940
has become restricted. So we find out the
size of the domains of the remaining variables
72
00:10:37,680 --> 00:10:44,680
and we pick the variable for which the remaining
domain is smallest in size. The intuition
73
00:10:50,050 --> 00:10:57,050
behind this is, since in the constraint satisfaction
solutions or constraint satisfaction problems
74
00:11:00,190 --> 00:11:06,740
all variables have to be assigned values,
the variable which is most constrained will
75
00:11:06,740 --> 00:11:13,740
have the fewest remaining values. So we need
less of backtracking in order to consider
76
00:11:15,310 --> 00:11:22,310
the effect of that on the search. Once you
have chosen a variable we have to choose the
77
00:11:25,910 --> 00:11:30,009
order of value assignment.
78
00:11:30,009 --> 00:11:36,870
And here the heuristic is, choose the least
constraining value. All variables have to
79
00:11:36,870 --> 00:11:42,360
be assigned value and the solution but each
variable has to be assigned only one value.
80
00:11:42,360 --> 00:11:49,070
So our intuition is to choose a value which
is most likely to take you to a solution.
81
00:11:49,070 --> 00:11:56,070
And consider that value which constraints
the domains of the remaining variables the
82
00:11:57,050 --> 00:12:04,050
least. That is the value that rules out the
fewest values in the remaining variables.
83
00:12:11,820 --> 00:12:18,820
Apart from the depth first search formulation
we are considering we can propagate constraints
84
00:12:19,920 --> 00:12:24,170
earlier on.
85
00:12:24,170 --> 00:12:31,089
Instead of considering variables one at a
time we look at the constraints early on to
86
00:12:31,089 --> 00:12:38,089
reduce the search space. And there are several
ideas which people have formulated which gave
87
00:12:38,320 --> 00:12:44,190
rise to different algorithms for constraint
satisfaction search and the simplest of these
88
00:12:44,190 --> 00:12:47,139
ideas is forward checking.
89
00:12:47,139 --> 00:12:52,110
What is forward checking?
We keep track of the remaining legal values
90
00:12:52,110 --> 00:12:59,110
for the unassigned variables. So, when we
assign values to a variable we suitably constrain
91
00:12:59,279 --> 00:13:06,279
the domains of the remaining variables. And
then if we detect that there is a variable
92
00:13:08,949 --> 00:13:15,949
which does not have any legal values left
then we can immediately terminate that path
93
00:13:19,649 --> 00:13:26,649
because finally we have to assign values to
every variable along a correct solution path.
94
00:13:26,810 --> 00:13:32,250
So, if you find that there is a variable which
does not have any legal values left we will
95
00:13:32,250 --> 00:13:38,110
not be able to assign values to the variables
so that search path is bound to fail. If we
96
00:13:38,110 --> 00:13:45,110
can detect this early on we can terminate
search at that point of the search tree. This
97
00:13:45,779 --> 00:13:52,779
is an example of a graph coloring problem
where we have five nodes and there are three
98
00:13:53,610 --> 00:14:00,610
colors red green and blue and these are the
links in the graph.
99
00:14:01,069 --> 00:14:08,069
Corresponding to this problem suppose we show
how a constraint satisfaction search proceeds.
100
00:14:11,069 --> 00:14:18,069
Initially suppose we pick the node MH we can
paint is red green or blue we paint MH is
101
00:14:18,440 --> 00:14:25,440
equal to red then if we pick KN next KN is
a neighbor of MH so KN can be either green
102
00:14:27,350 --> 00:14:34,350
or blue. If we pick KN is equal to green and
then we pick KE next KE is a neighbor of both
103
00:14:36,129 --> 00:14:43,129
MH and KN so KE is a neighbor of KN so it
has to have a different color than KN so it
104
00:14:46,709 --> 00:14:52,100
can be either red or blue. So this way we
can construct the search tree and we can do
105
00:14:52,100 --> 00:14:54,209
a depth first search.
106
00:14:54,209 --> 00:15:01,209
Now, if we do forward checking let us see
how we will proceed. Initially we have five
107
00:15:02,399 --> 00:15:09,399
variables MH KN KE AP and TN. Each of these
variables can take each of the three values
108
00:15:09,660 --> 00:15:16,660
red green and blue. When we set MH is equal
to red KN and AP are neighbors of MH so they
109
00:15:18,959 --> 00:15:25,959
can be either G or B, the others can be RGB.
If we pick now KN is equal to green then AP
110
00:15:27,410 --> 00:15:34,389
which is a neighbor cannot be green so it
can only be blue, KE and TN can be either
111
00:15:34,389 --> 00:15:41,389
RB or RB they are also neighbors of KN. Then
we pick KE is equal to red as a result AP
112
00:15:41,670 --> 00:15:48,670
and TN can be only blue. Now if you take AP
blue we find that the domain of TN is empty
113
00:15:54,420 --> 00:16:01,420
because TN is a neighbor of AP. So we detect
here that there is a problem with the assignment
114
00:16:02,050 --> 00:16:09,050
and we backtrack. This is what forward checking
does.
115
00:16:10,149 --> 00:16:17,149
Let us look back at the figure. At the 4th
step we found that KE and TN have only blue
116
00:16:18,670 --> 00:16:25,670
left in their domains. Now KE has a legal
value left, TN has a legal value left but
117
00:16:26,199 --> 00:16:32,250
we also know that there is a constraint between
KE and TN. KE and TN cannot be of the same
118
00:16:32,250 --> 00:16:39,250
color. We are talking about AP and TN. They
cannot be of the same color because they are
119
00:16:42,850 --> 00:16:48,680
neighbors. So in this step you see that AP
and TN have only one legal value left. Even
120
00:16:48,680 --> 00:16:55,110
though they are individually legal together
AP is equal to blue and TN is equal to blue
121
00:16:55,110 --> 00:17:02,110
cannot happen. So a smart algorithm might
detect this early on and terminate search.
122
00:17:04,730 --> 00:17:07,199
This is a limitation of forward checking.
123
00:17:07,199 --> 00:17:14,199
Forward checking checks that every remaining
variable has at least one legal value but
124
00:17:14,390 --> 00:17:19,770
it does not explore further whether these
values can be assigned to this variable subject
125
00:17:19,770 --> 00:17:26,770
to the constraints between these variables.
Forward checking detects some of the inconsistencies
126
00:17:27,459 --> 00:17:34,459
but it does not detect all inconsistencies.
For example, in the previous example it does
127
00:17:35,200 --> 00:17:41,790
not detect that AP and TN cannot be blue simultaneously.
128
00:17:41,790 --> 00:17:48,790
Now let us look at another constrained graph
on which we will run the next algorithm. Again
129
00:17:54,490 --> 00:18:01,490
this is a graph coloring problem. We have
6 nodes which we have numbered 1, 2, 3, 4,
130
00:18:02,340 --> 00:18:09,340
5 and 6 and this is the connectivity information
between the nodes. Each of the nodes can be
131
00:18:10,160 --> 00:18:17,160
colored red, green or blue but two neighboring
nodes cannot be assigned the same color. Now,
132
00:18:20,830 --> 00:18:27,800
if we do forward checking let us see what
happens.
133
00:18:27,800 --> 00:18:34,800
Suppose we first pick up 1 and we assign 1
to red. Now, if I assign 1 to red 2 and 3
134
00:18:38,260 --> 00:18:45,260
cannot be red so we reduce the domains of
2 and 3 we have blue or green. So, for each
135
00:18:46,400 --> 00:18:53,400
variable which is in constraint with 1 we
eliminate the conflicting values from the
136
00:18:53,640 --> 00:19:00,640
domain. Next is, suppose we assign green to
4 then 2, 3 and 6 cannot be green so we remove
137
00:19:12,580 --> 00:19:17,530
green from the domains of 2, 3 and 6.
138
00:19:17,530 --> 00:19:24,530
Now 2 can be only blue, 3 can be blue, 6 can
be red or blue. Next we assign blue to 5 and
139
00:19:36,210 --> 00:19:42,910
as a result it affects the domains of 3 and
6. So we remove blue from the domains of 3
140
00:19:42,910 --> 00:19:45,290
and the domains of 6.
141
00:19:45,290 --> 00:19:52,060
Now as a result we see that the domain of
3 becomes empty. So this is impossible so
142
00:19:52,060 --> 00:19:59,060
we have to back track at this point. Let us
now find out the weakness of forward checking.
143
00:20:03,810 --> 00:20:10,810
When we assigned for green we saw that 2 and
3 have only one legal value left which is
144
00:20:12,370 --> 00:20:19,120
blue but these two legal values cannot be
assigned together so we should have detected
145
00:20:19,120 --> 00:20:26,120
this problem early on, forward checking does
not detect this.
146
00:20:29,060 --> 00:20:36,060
So this is not detected by forward checking.
We should have backtracked at this step.
147
00:20:37,360 --> 00:20:44,360
Now let us see what further improvements we
can do. There are several things that we could
148
00:20:47,030 --> 00:20:54,030
do. One is we could try to propagate the implications
of the constraint on one variable on to the
149
00:20:55,450 --> 00:21:02,450
other variables. We propagate not just values
but constraints between these variables. This
150
00:21:03,330 --> 00:21:10,330
is the idea of constraint propagation we will
explore next.
151
00:21:11,380 --> 00:21:18,250
Secondly what we will see after that is, we
can backtrack intelligently which we call
152
00:21:18,250 --> 00:21:25,250
conflict directed backtracking. So we will
save possible conflicts for a variable value
153
00:21:26,040 --> 00:21:32,570
when we assign that variable value and we
will back jump to that assignment which gave
154
00:21:32,570 --> 00:21:35,040
rise to this conflict.
155
00:21:35,040 --> 00:21:41,530
In chronological backtracking on normal depth
first search we backtrack to just the previous
156
00:21:41,530 --> 00:21:43,760
choice of point.
157
00:21:43,760 --> 00:21:50,760
In backjumping when we detect a constraint
violation we backtrack to that assignment
158
00:21:51,500 --> 00:21:58,500
which led to the conflict which could have
taken several decisions earlier. So first,
159
00:22:00,350 --> 00:22:06,080
let us explore constraint propagation.
160
00:22:06,080 --> 00:22:13,080
Arc consistency is a fast method for constraint
propagation. This is how arc consistency works:
161
00:22:15,370 --> 00:22:22,370
Given the current domains of v1 and v2 the
arc from v1 to v2 is consistent if, for every
162
00:22:27,060 --> 00:22:34,060
value x of v1 there is some value y of v2
that is consistent with x. In forward checking
163
00:22:38,080 --> 00:22:44,380
check if the domain of in the remaining legal
the legal domain of v1 is empty or not. Here
164
00:22:44,380 --> 00:22:48,700
we are not only checking whether the domain
has a value but we are just checking whether
165
00:22:48,700 --> 00:22:55,700
for every value left in the domain there is
some value y in the domain of another variable
166
00:22:58,030 --> 00:23:03,130
so that these two assignments of values are
together consistent. This is what constraint
167
00:23:03,130 --> 00:23:06,530
propagation does.
168
00:23:06,530 --> 00:23:13,530
There are several constraint propagation algorithms.
We will look at AC-3 and some algorithms like
169
00:23:15,500 --> 00:23:21,780
that. Let us see an example of the same graph
that we discussed earlier.
170
00:23:21,780 --> 00:23:28,780
We assign green to 4. After we assigned green
to 4 we check all the arcs from 4, 2, 3 and
171
00:23:32,120 --> 00:23:39,120
6. First we check 2. So when we check 4 is
equal to 2 we eliminate green from the domain
172
00:23:39,120 --> 00:23:46,120
of 2. But we have to check back later with
the variables with which 2 has some constraint.
173
00:23:52,340 --> 00:23:59,340
Next we check the constraint 4 to 3 and eliminate
green from the domain of 3. After that we
174
00:24:00,950 --> 00:24:07,950
check the constraint 4 to 6 and eliminate
green from the domain of 6. After we have
175
00:24:10,790 --> 00:24:17,790
finished checking the neighbors of 4 we go
back to those variables whose domains have
176
00:24:18,600 --> 00:24:25,600
been changed to check if their current remaining
values are consistent with the values of their
177
00:24:27,470 --> 00:24:28,040
neighbors.
178
00:24:28,040 --> 00:24:34,540
We now go back to 2 and check the neighbors
of 2. First we check 2 with 1 there is no
179
00:24:34,540 --> 00:24:41,540
violation, there is no problem. Then we check
2 with 3 and then we notice that if 2 is blue
180
00:24:42,790 --> 00:24:47,250
3 cannot be blue so we eliminate blue from
3.
181
00:24:47,250 --> 00:24:52,580
If we do that the domain of 3 becomes empty
which cannot happen so we backtrack at this
182
00:24:52,580 --> 00:24:59,580
point. This is the arc consistency algorithm
and we can backtrack when we detect that there
183
00:25:02,070 --> 00:25:08,950
are variables which do not have domains which
are consistent together because of the constraints
184
00:25:08,950 --> 00:25:15,950
between those variables. This is the idea
of arc consistency.
185
00:25:16,230 --> 00:25:23,230
Whenever the domain of a variable is revised
the other arcs may need further revisions
186
00:25:26,290 --> 00:25:33,290
until no more inconsistencies remain. One
implementation of the arc consistency algorithm
187
00:25:36,500 --> 00:25:43,500
is the AC-3 algorithm. The AC-3 algorithm
uses a queue to keep track of the arcs that
188
00:25:44,610 --> 00:25:51,610
need to be checked for consistency because
when we assign 4 to green it is not enough
189
00:25:55,130 --> 00:26:02,130
that we check the domains of 2, 3 and 6 which
is neighbors of 4 but if these domains did
190
00:26:03,650 --> 00:26:10,650
change we have to check 2 with its neighbors
and do this recursively until there is no
191
00:26:11,720 --> 00:26:18,720
further constraint propagation. So AC-3 does
this constraint propagation so whenever the
192
00:26:23,350 --> 00:26:30,350
domain of a variable is reduced according
to this algorithm you propagate the constraints
193
00:26:32,020 --> 00:26:39,020
to the neighbors of that variable. This is
done recursively in the AC-3 algorithm. Now
194
00:26:39,420 --> 00:26:44,910
let us look at an implementation of the AC-3
algorithm.
195
00:26:44,910 --> 00:26:51,910
We have a data structure of a queue. Initially
the queue contains all the arcs of the graph.
196
00:26:56,730 --> 00:27:03,730
So we have all the Vi Vj that are the edges
of the graph such that i0 is equal to j. Then
197
00:27:08,650 --> 00:27:15,650
while q is not empty we select one of the
arcs from this queue that is Vk, Vm and we
198
00:27:16,530 --> 00:27:23,530
delete Vk, Vm from queue. Then we check if
revise Vk, Vm is true. That is, when we delete
199
00:27:30,690 --> 00:27:37,690
this arc we see if the domains get reduced.
When we consider this constraint between Vk,
200
00:27:39,290 --> 00:27:46,290
Vm we check if the domains of these variables
get reduced. So as a result of assignment
201
00:27:50,410 --> 00:27:57,410
of Vm if the domain of Vk gets changed then
we find all the arcs in the graph of the form
202
00:28:02,100 --> 00:28:08,530
Vi, Vk. That is, if Vi is a neighbor of Vk
then we have to check those constraints. So
203
00:28:08,530 --> 00:28:15,530
we append to the queue all the arcs Vi, Vk.
If as a result of an assignment to Vm the
204
00:28:20,270 --> 00:28:27,270
domain of Vk gets changed.
205
00:28:28,580 --> 00:28:35,580
Now let us see what is the complexity of this
algorithm AC-3?
206
00:28:36,980 --> 00:28:43,980
Now, if we have a binary constraint satisfaction
problem then the constraints are only between
207
00:28:47,070 --> 00:28:54,070
pair of variables. So there are utmost n square
arcs in the constrained graph.
208
00:29:00,830 --> 00:29:07,830
In the algorithm every arc can be inserted
utmost d times if the domain of Vi has d values.
209
00:29:13,680 --> 00:29:20,680
So, when we are putting an arc involving a
variable into the queue we are only doing
210
00:29:23,120 --> 00:29:30,120
it when the domain of the variable is reduced.
Suppose initially the domain of a variable
211
00:29:35,430 --> 00:29:42,430
Vk has b values we consider this arc for revision
only when this domain is getting reduced.
212
00:29:44,320 --> 00:29:51,320
Corresponding to every Vk the arc can be put
into the queue utmost d times. Now, checking
213
00:29:59,610 --> 00:30:06,610
the consistency of an arc can be done in order
d square times because we check it against
214
00:30:07,610 --> 00:30:14,610
all the arcs in the graph. So the worst case
time complexity of this algorithm is n square
215
00:30:16,510 --> 00:30:23,510
times d times d square which is O(n square
d cube). So O(n square d cube) is the worst
216
00:30:26,270 --> 00:30:33,270
case complexity of the AC-3 algorithm. This
is what constraint propagation is about.
217
00:30:42,600 --> 00:30:49,600
In constraint propagation as a result of reduction
in the domain of a variable we look at the
218
00:30:55,460 --> 00:31:02,460
implications in terms of the constraints of
the variables with other variables. And there
219
00:31:03,210 --> 00:31:09,460
are a set of algorithms which do constraint
propagation. One of the well known algorithms
220
00:31:09,460 --> 00:31:16,460
is AC-3 which we discussed. Next we will consider
another technique which we mentioned as intelligent
221
00:31:19,340 --> 00:31:21,380
backtracking.
222
00:31:21,380 --> 00:31:26,380
We have already seen backtracking which has
a very important role in solving the constraint
223
00:31:26,380 --> 00:31:32,640
satisfaction problems. So what you have in
plain depth first search is chronological
224
00:31:32,640 --> 00:31:39,640
backtracking. When the branch of a search
fails we need to backtrack to the most recent
225
00:31:40,690 --> 00:31:47,690
choice point. This is called depth first search.
In
depth first search we backtrack to the previous
226
00:31:54,280 --> 00:32:01,280
choice point but intelligent backtracking
involves backtracking to the point because
227
00:32:02,630 --> 00:32:09,630
of which the conflict has arisen.
228
00:32:09,980 --> 00:32:16,980
Suppose we have a search tree like this and
we have a constraint violation here, in chronological
229
00:32:31,160 --> 00:32:38,160
backtracking what we would do is, if there
is a violation here we will go back here and
230
00:32:38,590 --> 00:32:43,620
then go back here which has a choice point.
So we will go back to this node which is the
231
00:32:43,620 --> 00:32:50,260
next choice point. But in chronological backtracking
if we find that this violation is because
232
00:32:50,260 --> 00:32:57,260
of an assignment here we will backtrack directly
to this place. This is called backjumping
233
00:33:01,060 --> 00:33:08,060
or conflict directed backjumping.
234
00:33:09,490 --> 00:33:16,490
In chronological backtracking consistency
check is performed in the order in which the
235
00:33:17,030 --> 00:33:24,030
variables were instantiated. If consistency
check fails we try the next value of the current
236
00:33:24,240 --> 00:33:30,610
variable. If the current variable has no more
values we backtrack to the most recent variable
237
00:33:30,610 --> 00:33:37,610
that has a choice left. This is what is done
is normal depth first search. Backjumping
238
00:33:40,500 --> 00:33:47,500
is also a type of backtracking but it is more
efficient when there is no consistent instantiation
239
00:33:48,750 --> 00:33:52,520
to be found for the current variable.
240
00:33:52,520 --> 00:33:59,520
And in this case we go to the deepest variable
which was constraint checked against the current
241
00:34:00,180 --> 00:34:07,180
variable. So, when we find that the current
variable is inconsistent and has no possible
242
00:34:08,389 --> 00:34:13,690
instantiation left instead of backtracking
only to the previous choice point we find
243
00:34:13,690 --> 00:34:20,690
out what is the last variable which constrain
the current variable. The current variable
244
00:34:24,659 --> 00:34:31,659
has no legal values left. In order that the
current variable does get some legal value
245
00:34:31,839 --> 00:34:38,310
some constraint which participated with the
current variable has to be changed. So we
246
00:34:38,310 --> 00:34:45,310
find the deepest node in the path from the
current variable to the root where a variable
247
00:34:46,790 --> 00:34:51,839
was assigned a value and that constrains the
domain of the current variable, we have to
248
00:34:51,839 --> 00:34:57,280
find that and that is what intelligent backtracking
does.
249
00:34:57,280 --> 00:35:04,079
Backjumping reverts to the deepest variable
which was checked against the current variable
250
00:35:04,079 --> 00:35:11,079
in which introduce the constraints. Now let
us look at this example. So here we have the
251
00:35:15,779 --> 00:35:22,779
6 queens problem and we have put queen 1 in
row 2, queen 2 in row 5, queen 3 in row 3
252
00:35:29,390 --> 00:35:36,390
and queen 4 in row 6. After that we have put
queen 5 in row 4. Now we see that, after we
253
00:35:58,960 --> 00:36:05,960
have placed these 4 queens the last queen
cannot be placed in any of the rows. When
254
00:36:10,960 --> 00:36:17,960
we cannot put queen 5 we really do not need
to look at any further assignment to the value
255
00:36:28,509 --> 00:36:35,509
of queen 5.
256
00:36:35,619 --> 00:36:42,619
We have looked at some efficient constraint
satisfaction problems. We have revised forward
257
00:36:52,970 --> 00:36:59,970
checking then we have looked at constraint
propagation for which we looked at arc consistency
258
00:37:02,980 --> 00:37:09,980
algorithms and then we looked at backjumping.
259
00:37:15,519 --> 00:37:22,519
What is the idea behind these algorithms?
In forward checking when we assign values
260
00:37:23,029 --> 00:37:30,029
to some of the variables we look forward and
then we update the domains of the remaining
261
00:37:35,150 --> 00:37:42,150
variables. And in forward checking we just
checked whether the domain of any of the remaining
262
00:37:45,779 --> 00:37:46,569
variables become empty.
263
00:37:46,569 --> 00:37:53,569
If they do become empty then we terminate
search at that point. In constraint propagation,
264
00:37:58,420 --> 00:38:05,420
in the general constraint satisfaction class
of problems what we do is that, we not only
265
00:38:06,509 --> 00:38:13,509
propagate the constraints to restrict the
domains of the unassigned variables but we
266
00:38:19,589 --> 00:38:26,589
also do a consistency check on those variables
which have constraints between them. That
267
00:38:28,369 --> 00:38:35,369
is we check whether every variable whose domain
gets affected, whether it has a legal value
268
00:38:39,509 --> 00:38:46,509
for a legal value of its neighbor with which
it has some constraints. AC-3 is a constraint
269
00:38:48,740 --> 00:38:55,740
propagation algorithm which does this recursively.
Whenever it reduces a domain of a variable
270
00:38:57,730 --> 00:39:04,460
it takes up those variables and looks at its
constraints with its neighbors.
271
00:39:04,460 --> 00:39:08,039
If there are constraints with its neighbors
which reduce the domains of the neighbors
272
00:39:08,039 --> 00:39:15,039
then again it checks those with their neighbors
and so on. So AC-3 is quite an efficient algorithm
273
00:39:21,839 --> 00:39:28,839
and is able to detect constraints earlier.
As you make your constraint checking algorithms
274
00:39:34,660 --> 00:39:41,660
very intelligent you are reducing your reducing
the number of nodes in the constraint satisfaction
275
00:39:46,190 --> 00:39:53,190
tree that you are going to search but you
are spending more time at every step. So you
276
00:39:53,700 --> 00:40:00,700
have to select a right trade off about whether
these intelligent processing does give you
277
00:40:04,710 --> 00:40:05,160
benefit.
278
00:40:05,160 --> 00:40:12,160
Does this take up time? Whether the benefit
that you get in terms of reduced search space
279
00:40:12,319 --> 00:40:19,319
if they warrant that sort of benefit?
Finally we looked at backjumping. What backjumping
280
00:40:20,500 --> 00:40:27,500
does is that, when in your search tree some
constraint or some conflict is discovered
281
00:40:33,259 --> 00:40:40,259
that is the domain of this variable has become
empty. In backjumping we find the earliest
282
00:40:44,779 --> 00:40:51,140
variable which had been checked with this
variable in which we introduced “ ”. Now
283
00:40:51,140 --> 00:40:57,990
we must undo those effects in order to get
out of this situation. So instead of going
284
00:40:57,990 --> 00:41:04,990
to the most recent choice point we jump to
a conflict point.
285
00:41:09,619 --> 00:41:16,619
Now we look at the questions for this lecture:
The first question: Apply the different constraint
286
00:41:20,339 --> 00:41:27,339
satisfaction algorithms we discussed in today’s
class on the 5 queens problem. In each case
287
00:41:30,839 --> 00:41:37,839
you should find out the number of nodes that
are expanded. So first you will try ordinary
288
00:41:38,490 --> 00:41:45,490
depth first search. Second; you will try variable
ordering heuristic along with ordinary depth
289
00:41:49,640 --> 00:41:56,640
first search. In the third instance you try
forward checking. The 4th instance you work
290
00:42:00,349 --> 00:42:07,349
out AC-3 and finally you work with backjumping.
291
00:42:18,999 --> 00:42:25,999
Let us look back briefly at the questions
we have set for lecture nine. If you remember
292
00:42:27,420 --> 00:42:33,559
the first question asked you to do the class
room scheduling, to look at the class room
293
00:42:33,559 --> 00:42:38,880
scheduling problem and formulate it as a constraint
satisfaction problem. So let us briefly look
294
00:42:38,880 --> 00:42:45,880
at the class room scheduling problem. We have
a number of class rooms. Suppose cl1, cl2,
295
00:42:55,230 --> 00:43:00,690
cl3 are the class rooms and we have some times
slots
296
00:43:00,690 --> 00:43:07,690
Let T1, T2, T3, T4 be the time slots and we
have some teachers. So let P1, P2, P3, P4
297
00:43:15,059 --> 00:43:22,059
etc be the teachers. Now for each teacher
we have a set of classes which the teacher
298
00:43:25,839 --> 00:43:32,839
should be able to teach. So let us say P1
should be able to teach cl1 and cl2, P2 should
299
00:43:36,920 --> 00:43:43,920
be able to teach let us say cl2 and cl3, P3
should be able to teach cl4, P4 should be
300
00:43:45,680 --> 00:43:52,680
able to teach cl5 and cl1. So we have a set
of teachers and each teacher should be able
301
00:43:55,269 --> 00:44:02,269
to teach a set of classes. We have to assign
302
00:44:11,380 --> 00:44:16,549
courses so we have a set of courses.
303
00:44:16,549 --> 00:44:23,549
Now this is a problem which involves a large
number of variables of different types. Now
304
00:44:25,410 --> 00:44:32,410
let us look at the basic types of constraints
which are involved. Now, if a teacher has
305
00:44:37,140 --> 00:44:44,140
to teach both the courses namely course 1
and course 2 then it means that course 1 and
306
00:44:50,890 --> 00:44:57,890
course 2 must be in different time slots.
If a teacher is teaching c1 and c5 it means
307
00:44:58,779 --> 00:45:05,779
c1 and c5 must be in different time slots.
Now each class room at a slot can have only
308
00:45:12,380 --> 00:45:19,380
one class. This is something you have to follow.
And if a teacher is teaching two classes those
309
00:45:20,769 --> 00:45:26,859
two classes cannot be of the same time slot.
Now what we have to do is, we have to assign
310
00:45:26,859 --> 00:45:33,859
classes to class rooms and time slots.
311
00:45:36,279 --> 00:45:43,279
So we can start with picking class c1 and
assigning it to class room 1 time slot T1.
312
00:45:48,009 --> 00:45:55,009
Now, if c2 and c5 cannot have the same time
slot c2 domain will not have this time slot
313
00:46:02,220 --> 00:46:09,220
T1 and c5’s domain will also not have T1.
So when we consider the next instantiation,
314
00:46:15,720 --> 00:46:22,720
when we look at c2 we have to look at the
choices for c2 in time slots other than T1.
315
00:46:25,779 --> 00:46:32,779
When we look at c3, if after c1 we look at
c3, c3 can be in time slot T1 but in time
316
00:46:36,240 --> 00:46:43,240
slot T1 it cannot be in a class room cl1.
So any two courses
cannot share the same room and slot. So both
317
00:46:58,990 --> 00:47:05,990
rooms and slots cannot be the same for two
courses. And two courses that can be taught
318
00:47:09,259 --> 00:47:16,259
by the same professor
cannot share a time slot. So, based on these
constraints we have to do the assignment of
319
00:47:35,589 --> 00:47:40,430
values. You can work out these for a small
set of values.
320
00:47:40,430 --> 00:47:47,430
The second problem we said was a crypt arithmetic
problem. Specifically we were asked to work
321
00:47:54,430 --> 00:48:01,430
out the values of the different letters for
this crypt arithmetic problem.
322
00:48:02,839 --> 00:48:09,839
I will discuss briefly how you go about the
solution to this problem. Sometimes for these
323
00:48:14,299 --> 00:48:20,539
problems if we are working out manually you
can use certain heuristics from your knowledge.
324
00:48:20,539 --> 00:48:27,539
The value of M in this case cannot be more
than 1. So even if S and M have the highest
325
00:48:33,329 --> 00:48:40,079
values this can be utmost 1. This is not 0
because if this value is 0 we would not be
326
00:48:40,079 --> 00:48:47,079
putting this here so this is very easy to
see that M is equal to 1. So what we can do
327
00:48:48,599 --> 00:48:55,599
is, we can simplify this problem by putting
1 in this position. Now we have some other
328
00:49:13,109 --> 00:49:13,819
variables left.
329
00:49:13,819 --> 00:49:20,819
What are the variables we have?
The variables are D, E, Y, N, R, O and S so
330
00:49:29,029 --> 00:49:36,029
we have seven variables in this problem. Let
us say we first pick up D.
331
00:49:36,460 --> 00:49:43,460
Now what are the values that D can take?
D can be 1 or 2 or 3 or 4 or 5 or 6 or 7 or
332
00:49:45,049 --> 00:49:52,049
8 or 9 or 0 so we try the different values
of D. There are many possible values of D
333
00:49:56,200 --> 00:50:03,200
so we try all possible values of D. Now let
us say first we try D is equal to 1. Now if
334
00:50:05,690 --> 00:50:12,690
D is equal to 1 we have to try the different
values of E. We first try the value E is equal
335
00:50:20,150 --> 00:50:27,150
to 1. Now if E is equal to 1 then Y has to
be is equal to 2 if D is 1 and E is 1 and
336
00:50:35,489 --> 00:50:42,489
Y is 2. So Y is fixed and here we have E is
1, this E is 1, these are the values we have
337
00:50:46,489 --> 00:50:52,359
assigned and Y has become 2.
338
00:50:52,359 --> 00:50:59,359
Now we have to choose N and R so that we have
1 here. Suppose so we choose the different
339
00:51:01,069 --> 00:51:08,069
possible values of N, suppose you first choose
N is equal to 1, if N is equal to 1 then R
340
00:51:08,619 --> 00:51:15,619
has to be 0 to satisfy this constraint so
we have this assignment. And then E is 1 along
341
00:51:20,119 --> 00:51:26,789
this path and we do not know the value of
O and N is 1 so E is 1, O is not known, N
342
00:51:26,789 --> 00:51:33,789
is 1 so it must be is equal to 0. So here
we have o is equal to 0 and we have this is
343
00:51:35,589 --> 00:51:42,589
1 so S must be is equal to 9. Therefore a
solution to this problem is S is equal to
344
00:51:46,349 --> 00:51:53,349
9, E is equal to 1, N is equal to 1 and D
is equal to 1, M is 1, O is 0, R is 0, E is
345
00:52:03,670 --> 00:52:10,670
1 and M is 1, O is 0, N is 1, E is 1 and Y
is 2 and you can verify whether this is correct.
346
00:52:17,589 --> 00:52:22,079
It is 1 plus 1 is equal to 2, 1 plus 0 is
equal to 1, 1 plus 0 is equal to 1, 9 plus
347
00:52:22,079 --> 00:52:29,079
1 is equal to 10. So this is a solution to
the crypt arithmetic problem send plus more
348
00:52:30,190 --> 00:52:35,720
is equal to money. And we have solved this
problem by simple depth first search and in
349
00:52:35,720 --> 00:52:42,589
this case this is a simple problem with many
solutions so we could get this problem by
350
00:52:42,589 --> 00:52:49,589
only exploring one path.
351