1 00:00:09,400 --> 00:00:09,450 PROF. 2 00:00:09,450 --> 00:00:11,430 PATRICK WINSTON: It's too bad, in a way, that we can't paint 3 00:00:11,430 --> 00:00:14,260 everything black, because this map coloring problem sure 4 00:00:14,260 --> 00:00:17,410 would be a lot easier. 5 00:00:17,410 --> 00:00:21,930 So I don't know what we're going to do about that. 6 00:00:21,930 --> 00:00:23,920 How long is this going to take? 7 00:00:23,920 --> 00:00:24,740 Here's what we're going to do. 8 00:00:24,740 --> 00:00:26,480 We're going to wait till either all the laptops are 9 00:00:26,480 --> 00:00:28,910 closed, or this program terminates, 10 00:00:28,910 --> 00:00:30,160 whichever comes first. 11 00:00:32,520 --> 00:00:34,690 So how long is this going to take? 12 00:00:34,690 --> 00:00:36,590 I actually don't know. 13 00:00:36,590 --> 00:00:38,690 I think it'll take more than the life time of the universe, 14 00:00:38,690 --> 00:00:39,700 but I'm not sure. 15 00:00:39,700 --> 00:00:42,730 So let's take a look at a slightly easier 16 00:00:42,730 --> 00:00:44,560 map coloring problem. 17 00:00:44,560 --> 00:00:47,290 We'll stop this one and change the map to something I call 18 00:00:47,290 --> 00:00:49,340 [? simplicia. ?] 19 00:00:49,340 --> 00:00:53,780 There's 26 states, one for each letter in the alphabet. 20 00:00:53,780 --> 00:00:55,930 And what we're going to do is we're going to do a depth 21 00:00:55,930 --> 00:01:01,350 first search for a suitable coloring of this map. 22 00:01:01,350 --> 00:01:04,340 We're going to go in order, A, B, C, D, E. And as I've 23 00:01:04,340 --> 00:01:08,140 suggested here, at each level we're going to rotate the 24 00:01:08,140 --> 00:01:11,890 color choices so we don't over use any one color. 25 00:01:11,890 --> 00:01:14,800 So if we launch this particular search, this depth 26 00:01:14,800 --> 00:01:17,830 first attempt to color this map. 27 00:01:17,830 --> 00:01:18,530 There it goes. 28 00:01:18,530 --> 00:01:21,420 And maybe we should wait until it terminates. 29 00:01:21,420 --> 00:01:25,200 Or maybe we should just let it run and it'll terminate, 30 00:01:25,200 --> 00:01:27,360 perhaps, sometime within the lecture. 31 00:01:27,360 --> 00:01:30,960 Or maybe we should just let it run over the weekend. 32 00:01:30,960 --> 00:01:33,979 Or how long do you think we would have to wait, if we want 33 00:01:33,979 --> 00:01:37,206 to come back and watch it terminate? 34 00:01:37,206 --> 00:01:39,250 At roughly 30 frames a second-- 35 00:01:39,250 --> 00:01:41,960 I'm calculating it all in my head, I don't want to bet my 36 00:01:41,960 --> 00:01:46,530 life on it-- but I think about 5,000 years. 37 00:01:46,530 --> 00:01:50,330 And if we want to use as many states as there are in the 38 00:01:50,330 --> 00:01:53,990 United States, in this demonstration, you get up to 39 00:01:53,990 --> 00:01:58,940 numbers like 10 to the 17th years-- 40 00:01:58,940 --> 00:02:01,270 17th, 18th, 16th, I'm not exactly sure. 41 00:02:01,270 --> 00:02:03,670 I did a rough calculation. 42 00:02:03,670 --> 00:02:06,100 And, of course, you could do some parallels into that, and 43 00:02:06,100 --> 00:02:08,020 it's not as bad as chess, where you need all the atoms 44 00:02:08,020 --> 00:02:09,358 in the universe and you still can't do it, 45 00:02:09,358 --> 00:02:10,570 and things like that. 46 00:02:10,570 --> 00:02:11,510 Acting as computers. 47 00:02:11,510 --> 00:02:14,420 But still, it's pretty horrendous. 48 00:02:14,420 --> 00:02:20,570 The problem is, well the problem is illustrated by this 49 00:02:20,570 --> 00:02:22,810 diagram I put in back of me. 50 00:02:22,810 --> 00:02:27,950 If you do a depth first search and you have a 51 00:02:27,950 --> 00:02:31,590 problem like Texas. 52 00:02:31,590 --> 00:02:37,940 Texas has always, always been a problem, ever since they 53 00:02:37,940 --> 00:02:39,140 joined the Union. 54 00:02:39,140 --> 00:02:41,329 I could pick on other states, too. 55 00:02:41,329 --> 00:02:45,310 Kentucky, Tennessee, if you're from those states you 56 00:02:45,310 --> 00:02:47,630 represent something even worse. 57 00:02:47,630 --> 00:02:48,700 But Texas is down there. 58 00:02:48,700 --> 00:02:53,980 And the trouble is, if you assign a color to Arizona, 59 00:02:53,980 --> 00:02:58,730 Oklahoma, Arkansas, and Louisiana first, and then wait 60 00:02:58,730 --> 00:03:05,560 around to Texas last, then you get yourself into a bind by 61 00:03:05,560 --> 00:03:08,620 your fourth choice, that you don't discover until you're 62 00:03:08,620 --> 00:03:10,780 48th choice. 63 00:03:10,780 --> 00:03:13,840 So what happens then, is that you start developing this tree 64 00:03:13,840 --> 00:03:18,710 like this, you get to those states surrounding Texas. 65 00:03:18,710 --> 00:03:21,940 Texas is last state assigned a color and there's 66 00:03:21,940 --> 00:03:23,510 nothing left for it. 67 00:03:23,510 --> 00:03:26,316 And that problem was there on the fourth choice, and you 68 00:03:26,316 --> 00:03:28,700 don't discover it until your 50th choice. 69 00:03:28,700 --> 00:03:33,040 So you develop a horrendous, impossible, impossible search. 70 00:03:33,040 --> 00:03:37,070 So you simply can't do it that way. 71 00:03:37,070 --> 00:03:40,270 But now, not to worry. 72 00:03:40,270 --> 00:03:42,400 I've come equipped with the idea of constraint 73 00:03:42,400 --> 00:03:44,410 propagation. 74 00:03:44,410 --> 00:03:46,170 So we could just take a country with four 75 00:03:46,170 --> 00:03:47,840 states, like this. 76 00:03:47,840 --> 00:03:52,180 Each can be labeled red, green, blue and yellow. 77 00:03:52,180 --> 00:03:55,079 So just like in a case of line drawings, we'll pile up all 78 00:03:55,079 --> 00:03:59,270 the possible things that the value can be-- red, green, 79 00:03:59,270 --> 00:04:00,740 blue and yellow. 80 00:04:00,740 --> 00:04:03,420 Red, green, blue and yellow. 81 00:04:03,420 --> 00:04:06,460 Red, green, blue and yellow. 82 00:04:06,460 --> 00:04:09,330 And we start up constraint propagation. 83 00:04:09,330 --> 00:04:13,200 So we say for the upper left hand corner state, is there 84 00:04:13,200 --> 00:04:16,329 any reason to believe that R is impossible? 85 00:04:16,329 --> 00:04:18,190 Well we look at our neighbors and see what kind of 86 00:04:18,190 --> 00:04:20,329 constraint flows in from them. 87 00:04:20,329 --> 00:04:22,070 And sure, this guy could be green, and this 88 00:04:22,070 --> 00:04:23,320 guy could be blue. 89 00:04:23,320 --> 00:04:27,060 They don't have to be red, so there's nothing 90 00:04:27,060 --> 00:04:29,770 that rules out red. 91 00:04:29,770 --> 00:04:31,310 And there's nothing the rules out blue. 92 00:04:31,310 --> 00:04:34,250 And there's nothing that rules out yellow. 93 00:04:34,250 --> 00:04:36,430 And there's nothing that rules out green. 94 00:04:36,430 --> 00:04:40,422 So constraint propagation just sits there with its finger up 95 00:04:40,422 --> 00:04:43,380 its nose, doing nothing. 96 00:04:43,380 --> 00:04:49,630 So it doesn't look like we can use either depth first search, 97 00:04:49,630 --> 00:04:52,470 or constraint propagation. 98 00:04:52,470 --> 00:04:55,659 So we could just give up and cry. 99 00:04:55,659 --> 00:04:59,500 But maybe there's some other approach that will help. 100 00:04:59,500 --> 00:05:02,810 So let me actually work the Texas problem. 101 00:05:02,810 --> 00:05:08,690 So with apologies to Houston and Tyler, 102 00:05:08,690 --> 00:05:09,940 here's a map of Texas. 103 00:05:15,696 --> 00:05:16,595 There we are. 104 00:05:16,595 --> 00:05:19,660 And here's, roughly speaking, Arizona 105 00:05:19,660 --> 00:05:21,530 is over here somewhere. 106 00:05:21,530 --> 00:05:23,220 And we've got Oklahoma in there. 107 00:05:23,220 --> 00:05:27,440 And old Bill Clinton's state, Arkansas. 108 00:05:27,440 --> 00:05:30,420 And then Louisiana sticks out there a little bit. 109 00:05:30,420 --> 00:05:33,700 So there's our map of that 110 00:05:33,700 --> 00:05:36,170 particular part of the country. 111 00:05:36,170 --> 00:05:43,310 So we've got Arizona here, Oklahoma here, Arkansas here, 112 00:05:43,310 --> 00:05:47,350 and Louisiana here, and Texas here. 113 00:05:47,350 --> 00:05:52,060 And we have elected to assign colors to these states, in 114 00:05:52,060 --> 00:05:52,900 that order. 115 00:05:52,900 --> 00:05:57,090 So this is one, two, three, four. 116 00:05:59,970 --> 00:06:02,530 And we're going to do that. 117 00:06:02,530 --> 00:06:04,720 We're going to rotate our color choices, just so we 118 00:06:04,720 --> 00:06:08,460 don't over use any one color. 119 00:06:08,460 --> 00:06:11,620 But we're going to also have a look at Texas as we go around. 120 00:06:11,620 --> 00:06:14,930 Because Texas is a state that borders on the States they 121 00:06:14,930 --> 00:06:18,740 were choosing colors for. 122 00:06:18,740 --> 00:06:23,050 So the only possible colors that Texas could be are red, 123 00:06:23,050 --> 00:06:28,510 green, blue, and yellow. 124 00:06:28,510 --> 00:06:33,510 So as we make our choices around here, we'll say that-- 125 00:06:33,510 --> 00:06:36,540 we don't have to adhere to any particular style-- we can say 126 00:06:36,540 --> 00:06:43,800 that Arizona is going to get the colored red, R. That's 127 00:06:43,800 --> 00:06:47,240 going to rule out R over here for Texas, because no adjacent 128 00:06:47,240 --> 00:06:50,750 states can have the same color. 129 00:06:50,750 --> 00:06:53,020 Then we go over to Oklahoma, and we're rotating our color 130 00:06:53,020 --> 00:06:56,670 choices, so we'll say that can be green. 131 00:06:56,670 --> 00:06:59,610 And that's fine, because it's consistent with the red here, 132 00:06:59,610 --> 00:07:01,190 but it rules out the possibility that 133 00:07:01,190 --> 00:07:03,820 Texas could be green. 134 00:07:03,820 --> 00:07:10,170 And then we go over here to Arkansas, red, green, blue. 135 00:07:10,170 --> 00:07:13,460 That's fine, that's consistent with the green on Oklahoma, 136 00:07:13,460 --> 00:07:16,270 but if we look at its neighbors we know that Texas 137 00:07:16,270 --> 00:07:20,580 is forever forbidden to be blue, now. 138 00:07:20,580 --> 00:07:23,110 So now we go over to Louisiana, and remember, we're 139 00:07:23,110 --> 00:07:25,280 rotating our color choices because we don't want to 140 00:07:25,280 --> 00:07:27,240 overuse them. 141 00:07:27,240 --> 00:07:29,046 So this means that the first choice we're going to make 142 00:07:29,046 --> 00:07:30,695 here, for Louisiana, is yellow. 143 00:07:33,400 --> 00:07:36,380 And that's fine because it's consistent with Arkansas, but 144 00:07:36,380 --> 00:07:40,110 it's not so fine because it's now ruled out the last 145 00:07:40,110 --> 00:07:43,220 possibility for Texas. 146 00:07:43,220 --> 00:07:48,040 So even though Texas is going to be the 48th state that we 147 00:07:48,040 --> 00:07:51,770 color, we're going to say, at this point, there's no 148 00:07:51,770 --> 00:07:52,830 need in going on. 149 00:07:52,830 --> 00:07:54,680 We'd better back up. 150 00:07:54,680 --> 00:07:56,920 Because there's nothing left for Texas when we get around 151 00:07:56,920 --> 00:07:58,530 to coloring it. 152 00:07:58,530 --> 00:08:02,990 So that means that this yellow is ruled out here. 153 00:08:02,990 --> 00:08:05,550 This yellow reappears. 154 00:08:05,550 --> 00:08:09,740 We select the next color in my line for Louisiana, which 155 00:08:09,740 --> 00:08:11,640 happens to be red. 156 00:08:11,640 --> 00:08:15,310 And now that's consistent with this yellow that's 157 00:08:15,310 --> 00:08:16,800 still left for Texas. 158 00:08:16,800 --> 00:08:18,260 And it's also consistent with the blue 159 00:08:18,260 --> 00:08:21,270 that's up here for Arkansas. 160 00:08:21,270 --> 00:08:22,210 So that's cool. 161 00:08:22,210 --> 00:08:25,580 I wonder if maybe we could make an algorithm out of that, 162 00:08:25,580 --> 00:08:26,980 and solve problems like this. 163 00:08:26,980 --> 00:08:29,860 Do you see, sort of, the intuition of what we're doing? 164 00:08:29,860 --> 00:08:31,970 We're actually using the martial arts principle, again. 165 00:08:31,970 --> 00:08:35,520 Because the whole problem is that local constraints, 166 00:08:35,520 --> 00:08:37,600 undiscovered local constraints, are causing 167 00:08:37,600 --> 00:08:39,720 downstream problems. 168 00:08:39,720 --> 00:08:42,799 So we're going to use the enemy's powers against him, 169 00:08:42,799 --> 00:08:44,750 and we're going to look at those local constraints as we 170 00:08:44,750 --> 00:08:47,910 go and make sure they're not going downstream, not going to 171 00:08:47,910 --> 00:08:49,980 get us later on. 172 00:08:49,980 --> 00:08:55,060 So now I'm going to look like I'm getting a little formal, 173 00:08:55,060 --> 00:08:56,890 but I'm just getting a little bit more formal. 174 00:08:56,890 --> 00:09:02,090 Because I want to have some language that I can use to 175 00:09:02,090 --> 00:09:04,100 describe what's going on, so that it's clear what the 176 00:09:04,100 --> 00:09:06,180 choices are. 177 00:09:06,180 --> 00:09:08,590 So to start off with, we're going to have to have some 178 00:09:08,590 --> 00:09:10,310 vocabulary. 179 00:09:10,310 --> 00:09:13,670 So let's start up our vocabulary here. 180 00:09:13,670 --> 00:09:22,000 We're going to have a notion of a variable v. And that's 181 00:09:22,000 --> 00:09:23,250 something that can have an assignment. 182 00:09:41,850 --> 00:09:43,290 There's nothing complicated about that. 183 00:09:43,290 --> 00:09:44,540 And a value. 184 00:09:48,700 --> 00:09:54,040 A value x is something that can be in assignment. 185 00:09:57,360 --> 00:09:58,880 It's a little bit circular, but we're all in computer 186 00:09:58,880 --> 00:10:01,300 science so you know what I mean. 187 00:10:01,300 --> 00:10:05,770 So the next thing is a little slightly less obvious, and 188 00:10:05,770 --> 00:10:11,870 that's the notion of a domain, d. 189 00:10:11,870 --> 00:10:15,250 And that's going to be a bag of values. 190 00:10:19,190 --> 00:10:19,520 OK. 191 00:10:19,520 --> 00:10:21,150 So one more thing. 192 00:10:21,150 --> 00:10:22,400 A constraint. 193 00:10:27,810 --> 00:10:36,080 That's a constraint c, is a limit on-- 194 00:10:36,080 --> 00:10:38,670 in our examples it's mostly going to be pairs of 195 00:10:38,670 --> 00:10:40,910 variables, pairs of variable values. 196 00:10:40,910 --> 00:10:42,995 But in general, it could be variable values. 197 00:10:51,570 --> 00:10:55,040 So if we go back here to Texas we could say, OK, how does our 198 00:10:55,040 --> 00:10:58,190 vocabulary drape itself over that configuration? 199 00:10:58,190 --> 00:11:03,420 And the answer is, the states have the role of variables, 200 00:11:03,420 --> 00:11:08,670 the colors have the role of values. 201 00:11:08,670 --> 00:11:11,780 And the domains are the remaining color possibilities 202 00:11:11,780 --> 00:11:14,510 that we can still use on a particular state. 203 00:11:14,510 --> 00:11:16,770 And the constraint, in this case, is the simple map 204 00:11:16,770 --> 00:11:20,770 coloring constraint that no states that share a boundary 205 00:11:20,770 --> 00:11:23,100 can have the same color. 206 00:11:23,100 --> 00:11:26,840 So states are variables, colors are values, domains are 207 00:11:26,840 --> 00:11:29,760 bags of colors, and constraints-- 208 00:11:29,760 --> 00:11:31,310 there's only one-- 209 00:11:31,310 --> 00:11:34,330 adjacent states can't have the same color. 210 00:11:34,330 --> 00:11:37,440 So that's how it fits with this vocabulary. 211 00:11:37,440 --> 00:11:39,800 So now, what did I actually do here? 212 00:11:39,800 --> 00:11:42,950 Well what I actually did here, I'm going to now formalize a 213 00:11:42,950 --> 00:11:47,500 little by writing it down in pseudo code. 214 00:11:47,500 --> 00:11:51,100 So here we are, we're going to have a look at what we did 215 00:11:51,100 --> 00:11:53,630 here with our intuition, and we're going to 216 00:11:53,630 --> 00:11:55,700 reduce it to a procedure. 217 00:11:55,700 --> 00:11:56,950 And here's the procedure. 218 00:12:00,720 --> 00:12:02,860 Remember, we're doing depth first search on this stuff. 219 00:12:02,860 --> 00:12:04,650 I did a depth first search. 220 00:12:04,650 --> 00:12:10,200 We're going to do a depth first search, and for each 221 00:12:10,200 --> 00:12:13,580 depth first search assignment-- 222 00:12:19,190 --> 00:12:23,610 OK, so here I am, I'm labeling Arizona, and then Oklahoma, 223 00:12:23,610 --> 00:12:26,250 and then Arkansas, and then Louisiana. 224 00:12:26,250 --> 00:12:30,500 When I give each one of those a label, a color, I'm going to 225 00:12:30,500 --> 00:12:32,210 do this procedure. 226 00:12:32,210 --> 00:12:33,495 Every time I make one of those assignments. 227 00:12:33,495 --> 00:12:36,640 The last one that caused trouble was 228 00:12:36,640 --> 00:12:38,230 coloring Louisiana yellow. 229 00:12:38,230 --> 00:12:41,520 Each time I put one of those colors down, each time I make 230 00:12:41,520 --> 00:12:43,070 an assignment, I'm going to do this procedure. 231 00:12:43,070 --> 00:12:56,690 So for each depth first search assignment, for each variable 232 00:12:56,690 --> 00:12:58,095 v, considered. 233 00:13:03,730 --> 00:13:06,390 Now you don't know what I mean by considered. 234 00:13:06,390 --> 00:13:12,300 But when I put a label, when I put up a value, show something 235 00:13:12,300 --> 00:13:17,340 as a color for Louisiana, I thought about Texas. 236 00:13:17,340 --> 00:13:20,340 So I was considering the variable, Texas, when I made 237 00:13:20,340 --> 00:13:22,662 the assignment for Louisiana. 238 00:13:22,662 --> 00:13:24,890 Now I'm going to be a little bit vague about what I mean by 239 00:13:24,890 --> 00:13:25,720 considered, right now. 240 00:13:25,720 --> 00:13:27,500 Because there are lots of choices about how much stuff 241 00:13:27,500 --> 00:13:29,240 you actually consider. 242 00:13:29,240 --> 00:13:31,390 So let me just say consider, and then we'll open that up 243 00:13:31,390 --> 00:13:35,930 and talk about the options in a moment, so for each variable 244 00:13:35,930 --> 00:13:40,560 v considered for-- 245 00:13:40,560 --> 00:13:44,040 let's call that variable v sub i-- 246 00:13:44,040 --> 00:13:53,340 for each x sub i, for each value in the domain of that 247 00:13:53,340 --> 00:13:58,760 variable, consider each of the things that still surviving. 248 00:13:58,760 --> 00:14:13,530 For each of those, for each constraint c, that's between x 249 00:14:13,530 --> 00:14:26,390 sub i, and some x sub j, where x sub j is an element of the 250 00:14:26,390 --> 00:14:29,050 domain of j. 251 00:14:29,050 --> 00:14:32,020 Now that sounds awfully fancy, but this just says, in the 252 00:14:32,020 --> 00:14:35,940 case of Texas up there, whenever I consider one of the 253 00:14:35,940 --> 00:14:40,170 values that's still remaining as a choice for Texas, I want 254 00:14:40,170 --> 00:14:42,700 to consider all of the constraints between that 255 00:14:42,700 --> 00:14:47,550 variable and the adjacent states. 256 00:14:47,550 --> 00:14:52,600 And I want to be sure that anything I leave in the domain 257 00:14:52,600 --> 00:14:56,350 is OK for some selection in the other states, some 258 00:14:56,350 --> 00:14:58,960 remaining choices in the other states. 259 00:14:58,960 --> 00:15:01,090 So that's why we're getting pretty nested here. 260 00:15:01,090 --> 00:15:04,540 But we're doing depth first search. 261 00:15:04,540 --> 00:15:07,740 We are considering the variables in a certain 262 00:15:07,740 --> 00:15:12,660 collection of variables. 263 00:15:12,660 --> 00:15:15,160 For each one of those where considering all the values 264 00:15:15,160 --> 00:15:18,350 that still remain in the domains of those variables. 265 00:15:18,350 --> 00:15:20,950 And then for each of those values, we're checking to see 266 00:15:20,950 --> 00:15:24,010 if it satisfies this some constraint, satisfies the 267 00:15:24,010 --> 00:15:27,280 constraint that are placed upon it. 268 00:15:27,280 --> 00:15:32,580 So for each of these constraints if there does not 269 00:15:32,580 --> 00:15:40,910 exist an x sub j, such that, the constraint between x sub i 270 00:15:40,910 --> 00:15:51,090 and x sub j is satisfied, well if in that adjacent place 271 00:15:51,090 --> 00:15:54,770 there's nothing that is consistent with a value, then 272 00:15:54,770 --> 00:15:57,380 we've got to get rid of it. 273 00:15:57,380 --> 00:15:58,350 If that's true. 274 00:15:58,350 --> 00:16:03,810 If there does not exist some value in an adjacent variable 275 00:16:03,810 --> 00:16:06,380 such that that constraint is satisfied, we're hosed. 276 00:16:06,380 --> 00:16:08,770 We've got to get rid of that value. 277 00:16:08,770 --> 00:16:19,370 So we're going to remove x sub i from d sub i. 278 00:16:22,970 --> 00:16:23,250 OK. 279 00:16:23,250 --> 00:16:25,070 Now, that's fine. 280 00:16:25,070 --> 00:16:27,730 That's sort of what I did with Texas. 281 00:16:27,730 --> 00:16:31,610 As soon as I plopped down a value for Louisiana I said, 282 00:16:31,610 --> 00:16:33,770 well what are the possible values in Texas? 283 00:16:33,770 --> 00:16:35,610 Red, green, blue and yellow. 284 00:16:35,610 --> 00:16:37,620 Let's consider red. 285 00:16:37,620 --> 00:16:39,480 Let's consider the constraints between Texas and 286 00:16:39,480 --> 00:16:41,160 all adjacent states. 287 00:16:41,160 --> 00:16:42,660 One of those constraints says it can't be the 288 00:16:42,660 --> 00:16:44,660 same color as Arizona. 289 00:16:44,660 --> 00:16:46,690 The only color I've got available for Arizona, since 290 00:16:46,690 --> 00:16:48,870 I've already made the assignment is red. 291 00:16:48,870 --> 00:16:50,580 Red is not consistent with red, so I've got 292 00:16:50,580 --> 00:16:53,070 to get rid of it. 293 00:16:53,070 --> 00:16:57,080 So it looks complicated, but it's just intuition. 294 00:16:57,080 --> 00:16:59,780 So what do we do if we get to a situation where 295 00:16:59,780 --> 00:17:01,710 the domain is empty? 296 00:17:01,710 --> 00:17:03,975 That means whenever we get around to making assignment to 297 00:17:03,975 --> 00:17:06,560 it, there won't be anything left. 298 00:17:06,560 --> 00:17:21,310 So if that ever happens, if the domain ever becomes empty, 299 00:17:21,310 --> 00:17:22,746 then what do we do? 300 00:17:22,746 --> 00:17:23,996 We've got to back up. 301 00:17:31,010 --> 00:17:32,130 So the intuition is clear. 302 00:17:32,130 --> 00:17:33,070 This is the algorithm. 303 00:17:33,070 --> 00:17:35,960 The algorithm when you work through it, think about 304 00:17:35,960 --> 00:17:37,360 whether it makes sense and what not. 305 00:17:37,360 --> 00:17:38,370 How it fits with Texas. 306 00:17:38,370 --> 00:17:39,190 Yeah, it sure does. 307 00:17:39,190 --> 00:17:42,160 All we're doing is we're making these death first 308 00:17:42,160 --> 00:17:42,710 assignments. 309 00:17:42,710 --> 00:17:45,290 And in the neighborhood of those depth first assignments 310 00:17:45,290 --> 00:17:48,980 we're looking around to see if the values that are possible 311 00:17:48,980 --> 00:17:49,960 include something. 312 00:17:49,960 --> 00:17:53,180 And if they don't include anything, we know we made and 313 00:17:53,180 --> 00:17:57,380 irrevocable blunder, and we have to back up. 314 00:17:57,380 --> 00:18:01,050 So that's the essence of the idea. 315 00:18:01,050 --> 00:18:04,050 Now, how well does it work? 316 00:18:04,050 --> 00:18:11,570 Well a little bit depends on what we choose for considered. 317 00:18:11,570 --> 00:18:13,550 There are lots of choices for what we consider. 318 00:18:16,520 --> 00:18:20,360 So let me enumerate some of those choices and then we'll 319 00:18:20,360 --> 00:18:21,710 have a look and see what they do. 320 00:18:35,950 --> 00:18:39,700 Oh I guess one possibility is to consider nothing. 321 00:18:50,070 --> 00:18:51,320 Let's try it out. 322 00:18:56,920 --> 00:19:00,470 So our type of search is going to be no checks. 323 00:19:00,470 --> 00:19:01,890 What do you think is going to happen? 324 00:19:04,590 --> 00:19:07,910 We're not even checking the assignment. 325 00:19:07,910 --> 00:19:09,380 That's pretty fast. 326 00:19:09,380 --> 00:19:11,560 Unfortunately, since we haven't even check the most 327 00:19:11,560 --> 00:19:14,490 recent assignment, we get lots of places where there are 328 00:19:14,490 --> 00:19:16,490 states that are adjacent to each other that 329 00:19:16,490 --> 00:19:18,130 have the same color. 330 00:19:18,130 --> 00:19:19,380 That's no good. 331 00:19:22,940 --> 00:19:27,440 So another thing we can do is consider everything 332 00:19:27,440 --> 00:19:28,690 everything. 333 00:19:36,060 --> 00:19:38,600 That's no good, because that would say, as soon as we color 334 00:19:38,600 --> 00:19:43,020 our first state, we check to make sure that all 47 other 335 00:19:43,020 --> 00:19:45,270 states can be colored. 336 00:19:45,270 --> 00:19:49,090 That seems like it over doing it a little bit. 337 00:19:49,090 --> 00:19:52,795 But in any case, at least we want to check the assignment. 338 00:20:01,200 --> 00:20:05,230 So if we go back here and check the assignment, let's 339 00:20:05,230 --> 00:20:06,480 see what happens. 340 00:20:11,995 --> 00:20:14,950 Type assignments, assignments only. 341 00:20:14,950 --> 00:20:15,650 Boom. 342 00:20:15,650 --> 00:20:18,580 Aw, gees, that's where I got in trouble before. 343 00:20:18,580 --> 00:20:26,140 This is the thing is going to run for 17 billion years at 344 00:20:26,140 --> 00:20:28,330 nanosecond or something like that. 345 00:20:28,330 --> 00:20:30,630 It's only a billion years if you run it at nanosecond 346 00:20:30,630 --> 00:20:33,760 speed, so I guess maybe you could do that. 347 00:20:33,760 --> 00:20:35,110 Have a fast computer. 348 00:20:35,110 --> 00:20:37,360 But this isn't going to work because of our unfortunate 349 00:20:37,360 --> 00:20:42,950 choice of Texas as the last state to be considered, and 350 00:20:42,950 --> 00:20:45,690 the unfortunate coloring of the four surrounding states 351 00:20:45,690 --> 00:20:47,280 right up front. 352 00:20:47,280 --> 00:20:50,100 And our unfortunate decision to rotate the color so as to 353 00:20:50,100 --> 00:20:54,310 avoid overdoing any one color. 354 00:20:54,310 --> 00:20:55,200 So this doesn't work. 355 00:20:55,200 --> 00:20:58,760 We know we went to the trouble of working out the business 356 00:20:58,760 --> 00:21:03,950 with Texas by hand, using the domain reduction algorithm. 357 00:21:03,950 --> 00:21:05,470 Better make a note that this is the 358 00:21:05,470 --> 00:21:06,740 domain reduction algorithm. 359 00:21:16,340 --> 00:21:18,250 And what we're going to do is we're going to check the 360 00:21:18,250 --> 00:21:21,120 neighbors of the assignments. 361 00:21:21,120 --> 00:21:21,970 Just like we did here. 362 00:21:21,970 --> 00:21:24,360 We checked Texas each time we made one of those four 363 00:21:24,360 --> 00:21:28,050 choices, because it's a neighbor of all of the choices 364 00:21:28,050 --> 00:21:30,490 of the states that we made. 365 00:21:30,490 --> 00:21:32,640 So one thing to do is to check neighbors. 366 00:21:37,900 --> 00:21:41,510 This is one, two, three, now let's see what happens. 367 00:21:50,250 --> 00:21:52,805 Check neighbors only, go. 368 00:22:11,450 --> 00:22:12,390 Shoot, I don't know. 369 00:22:12,390 --> 00:22:15,560 It's OK with Texas, right? 370 00:22:15,560 --> 00:22:20,522 Because it didn't color the states around Texas with all 371 00:22:20,522 --> 00:22:22,760 of the four color choices. 372 00:22:22,760 --> 00:22:25,770 But it's still getting into trouble in other places. 373 00:22:28,490 --> 00:22:32,930 Like the states like Missouri, Kentucky, Virginia, Tennessee, 374 00:22:32,930 --> 00:22:35,085 states with lots of boundaries. 375 00:22:37,670 --> 00:22:40,080 So I don't know whether this is going to-- 376 00:22:40,080 --> 00:22:43,350 oh, there it finally worked. 377 00:22:43,350 --> 00:22:46,010 It went through a lot of effort, though. 378 00:22:46,010 --> 00:22:48,540 For the sake of comparison, we might make a note that it ran 379 00:22:48,540 --> 00:23:01,250 into 9,139 dead ends. 380 00:23:01,250 --> 00:23:02,720 But it did do some good. 381 00:23:02,720 --> 00:23:07,200 It didn't take a length of time longer than the remaining 382 00:23:07,200 --> 00:23:09,620 part of the universe. 383 00:23:09,620 --> 00:23:13,140 But if it's a good idea to check the neighbors, if we 384 00:23:13,140 --> 00:23:16,580 make a change to the neighbors, what might that 385 00:23:16,580 --> 00:23:20,940 suggests that we do in addition? 386 00:23:20,940 --> 00:23:22,680 Well it might suggest that if we make a change to a 387 00:23:22,680 --> 00:23:26,790 neighbor, that we check its neighbors, too, make sure 388 00:23:26,790 --> 00:23:29,040 they're all right. 389 00:23:29,040 --> 00:23:33,470 So another choice is to propagate. 390 00:24:03,460 --> 00:24:08,370 So propagate through variables with reduced domains. 391 00:24:08,370 --> 00:24:09,790 Let's see how that works. 392 00:24:21,510 --> 00:24:22,760 Wait a minute. 393 00:24:24,570 --> 00:24:26,210 I must have made a mistake. 394 00:24:26,210 --> 00:24:28,470 Let's try that again. 395 00:24:28,470 --> 00:24:30,930 Oh, maybe we better slow it down. 396 00:24:35,760 --> 00:24:38,785 All that grey stuff is showing the limit of the propagation. 397 00:24:45,270 --> 00:24:49,790 Man it's, let's see at four second of 40, 398 00:24:49,790 --> 00:24:55,520 that's about 10 seconds. 399 00:24:55,520 --> 00:24:57,190 Boom. 400 00:24:57,190 --> 00:24:58,340 Not bad. 401 00:24:58,340 --> 00:25:00,130 Zero dead ends. 402 00:25:00,130 --> 00:25:01,080 And it was a lot faster. 403 00:25:01,080 --> 00:25:02,854 I didn't happen to notice how many constraints were checked 404 00:25:02,854 --> 00:25:06,130 on that other thing, I think it was around 20,000 or so. 405 00:25:06,130 --> 00:25:08,700 This is a lot less. 406 00:25:08,700 --> 00:25:11,320 So this looks like a good idea. 407 00:25:11,320 --> 00:25:14,255 But why did I label it number five? 408 00:25:14,255 --> 00:25:17,960 Well because there's something between this and number three. 409 00:25:17,960 --> 00:25:32,300 So number four is, through v with d reduced to one value. 410 00:25:36,000 --> 00:25:38,730 So we're not going to propagate through all of the 411 00:25:38,730 --> 00:25:42,750 variables which have their domains shrunk a little bit. 412 00:25:42,750 --> 00:25:44,610 We're only going to propagate through those that have the 413 00:25:44,610 --> 00:25:49,520 greater shrinkage, all the way down to a single value. 414 00:25:49,520 --> 00:25:51,200 So let's see how that might work. 415 00:26:02,590 --> 00:26:05,860 Anybody want to place any bets on this one? 416 00:26:05,860 --> 00:26:06,280 Let's see. 417 00:26:06,280 --> 00:26:10,490 We checked 2,623 constraints last time. 418 00:26:10,490 --> 00:26:11,740 Let's see what happens this time. 419 00:26:14,580 --> 00:26:17,930 You can see that the extent of the gray is less, because it's 420 00:26:17,930 --> 00:26:19,440 not propagating so far. 421 00:26:28,630 --> 00:26:40,690 And as we breathily await the answer, I'd say we've found 422 00:26:40,690 --> 00:26:41,505 our winner. 423 00:26:41,505 --> 00:26:45,000 As this does a couple of dead ends, but the number of 424 00:26:45,000 --> 00:26:49,020 constraint checked is less than 1,000. 425 00:26:49,020 --> 00:26:51,360 So in general, with problems this, you have all of these 426 00:26:51,360 --> 00:26:53,690 choices for what you consider. 427 00:26:53,690 --> 00:26:55,320 You don't want to consider nothing, because then you're 428 00:26:55,320 --> 00:26:57,450 not honoring your constraints. 429 00:26:57,450 --> 00:26:59,320 You'll certainly want to consider the things you just 430 00:26:59,320 --> 00:27:05,670 made assignments for, because otherwise you'll construct a 431 00:27:05,670 --> 00:27:08,910 solution that violates a constraint. 432 00:27:08,910 --> 00:27:12,190 You don't want to do everything, because that's 433 00:27:12,190 --> 00:27:14,050 excessive work. 434 00:27:14,050 --> 00:27:20,830 And so checking the neighbors is a good idea, but it's 435 00:27:20,830 --> 00:27:23,305 always better in practice. 436 00:27:23,305 --> 00:27:26,160 In practice, inevitably it's the case that it's better to 437 00:27:26,160 --> 00:27:27,440 do some propagation through the 438 00:27:27,440 --> 00:27:29,000 things that you've changed. 439 00:27:29,000 --> 00:27:30,520 How much propagation? 440 00:27:30,520 --> 00:27:32,540 It doesn't seem to do much good to propagate through 441 00:27:32,540 --> 00:27:34,070 things are just changed. 442 00:27:34,070 --> 00:27:36,630 But it does seem to do some good to propagate through the 443 00:27:36,630 --> 00:27:37,730 things that have changed and been 444 00:27:37,730 --> 00:27:40,590 reduced to a single value. 445 00:27:40,590 --> 00:27:43,400 So as soon as you get a neighbor of some assignment 446 00:27:43,400 --> 00:27:46,290 you just made that has its domain reduced to a single 447 00:27:46,290 --> 00:27:48,730 value, then you check its neighbors, too. 448 00:27:48,730 --> 00:27:50,410 So you check the neighbors, of the neighbors, of the 449 00:27:50,410 --> 00:27:54,290 neighbors, of the neighbors, on and on and on, as long as 450 00:27:54,290 --> 00:27:57,950 you've found a domain being reduced. 451 00:27:57,950 --> 00:28:01,180 And not only being reduced, but reduced to a signal value. 452 00:28:01,180 --> 00:28:01,580 All right? 453 00:28:01,580 --> 00:28:03,230 So that's the demand reduction algorithm. 454 00:28:03,230 --> 00:28:06,860 And I guarantee you a problem like that. 455 00:28:06,860 --> 00:28:10,300 And I know you don't know how to work those problems yet, 456 00:28:10,300 --> 00:28:12,060 because this is a little bit abstract. 457 00:28:12,060 --> 00:28:16,340 And to work these problems in the exam setting you need to 458 00:28:16,340 --> 00:28:19,250 know a little bit about how to keep track of the variable 459 00:28:19,250 --> 00:28:21,690 values that remain in the domain, and 460 00:28:21,690 --> 00:28:22,310 that sort of thing. 461 00:28:22,310 --> 00:28:24,810 And you'll learn more about that in your recitations, and 462 00:28:24,810 --> 00:28:28,780 in this mega recitation, and in the tutorials. 463 00:28:28,780 --> 00:28:31,240 So we could go home except that there are few little 464 00:28:31,240 --> 00:28:33,840 flourishes to deal with here. 465 00:28:33,840 --> 00:28:43,210 And those flourishes, include some dirty, 466 00:28:43,210 --> 00:28:45,520 filthy little secrets. 467 00:28:45,520 --> 00:28:48,830 For example, I've chosen, as my classroom 468 00:28:48,830 --> 00:28:51,390 example, to pick on Texas. 469 00:28:51,390 --> 00:28:53,620 And arranged for this situation to 470 00:28:53,620 --> 00:28:56,130 be especially ugly. 471 00:28:56,130 --> 00:29:01,080 So I could arrange the states in a different way. 472 00:29:01,080 --> 00:29:03,420 We have highly constrained states, that have a lot of 473 00:29:03,420 --> 00:29:06,250 bordering states around them. 474 00:29:06,250 --> 00:29:11,950 And we have other states, like Maine, up there, that only 475 00:29:11,950 --> 00:29:14,660 borders on one other state. 476 00:29:14,660 --> 00:29:17,550 So I don't know. 477 00:29:17,550 --> 00:29:19,685 Will, what do you think? 478 00:29:22,980 --> 00:29:26,840 Should we arrange the states for our death first search in 479 00:29:26,840 --> 00:29:30,490 the order of least constrained to most constrained, or most 480 00:29:30,490 --> 00:29:31,740 constrained to least constrained? 481 00:29:35,690 --> 00:29:39,080 In other words, should we start with Missouri, or 482 00:29:39,080 --> 00:29:41,730 Tennessee, or Kentucky, or something like that? 483 00:29:41,730 --> 00:29:44,254 Or should we start with Maine? 484 00:29:44,254 --> 00:29:46,206 What do you think? 485 00:29:46,206 --> 00:29:49,140 You have a 50% chance of getting it right, just by 486 00:29:49,140 --> 00:29:51,650 [? looking ?] at points. 487 00:29:51,650 --> 00:29:53,950 WILL: Start with the most first. 488 00:29:53,950 --> 00:29:53,978 PROF. 489 00:29:53,978 --> 00:29:54,920 PATRICK WINSTON: He thinks we should start with the most 490 00:29:54,920 --> 00:29:56,600 constraint first. 491 00:29:56,600 --> 00:29:59,490 Do we have a volunteer who wants to suggest that we start 492 00:29:59,490 --> 00:30:02,210 with the least constraint first? 493 00:30:02,210 --> 00:30:05,570 That's the way I always work on stuff. 494 00:30:05,570 --> 00:30:09,050 I'm working on a book or something, I have 500 things 495 00:30:09,050 --> 00:30:11,920 to fix, I'll always choose to work on the easiest stuff 496 00:30:11,920 --> 00:30:15,980 first, so that I feel like I'm making the list a lot smaller. 497 00:30:15,980 --> 00:30:18,400 Leave the hardest things to last. 498 00:30:18,400 --> 00:30:21,910 But we don't have any volunteers who want to bet on 499 00:30:21,910 --> 00:30:25,060 that idea of least constraint first? 500 00:30:25,060 --> 00:30:26,700 OK. 501 00:30:26,700 --> 00:30:29,010 Jason wants to suggest that we should work on least 502 00:30:29,010 --> 00:30:30,050 constraint first. 503 00:30:30,050 --> 00:30:31,370 Well we have ground truth, because we 504 00:30:31,370 --> 00:30:32,620 can just try it out. 505 00:30:37,300 --> 00:30:39,030 I guess we'll stick with our shrinking to one 506 00:30:39,030 --> 00:30:41,950 value thing, here. 507 00:30:41,950 --> 00:30:46,880 But we will reorder things so that we have the least 508 00:30:46,880 --> 00:30:48,130 constrained first. 509 00:30:51,940 --> 00:30:54,900 So right away, we got a color for Maine. 510 00:30:58,160 --> 00:30:59,430 Maybe we ought to speed this up a little bit. 511 00:31:04,540 --> 00:31:06,450 Well, that's a good idea. 512 00:31:06,450 --> 00:31:12,020 Jason suggested this and we only 1,732 constraints and we 513 00:31:12,020 --> 00:31:13,010 had 59 dead ends. 514 00:31:13,010 --> 00:31:18,910 So let's try the other way around, and we'll go back to 515 00:31:18,910 --> 00:31:20,160 four frames a second. 516 00:31:32,890 --> 00:31:34,940 So we're working, kind of from the middle of the country out, 517 00:31:34,940 --> 00:31:36,330 with this one. 518 00:31:36,330 --> 00:31:37,860 We're going to deal with Maine, I guess, last. 519 00:31:43,870 --> 00:31:46,520 Which is better. 520 00:31:46,520 --> 00:31:49,640 Too bad, I think it looks like this is better. 521 00:31:49,640 --> 00:31:52,840 In fact, let's not be so aggressive with the use of 522 00:31:52,840 --> 00:31:53,950 constraint propagation. 523 00:31:53,950 --> 00:31:56,710 Let's just check the assignments only. 524 00:31:56,710 --> 00:31:59,060 If we go back to an arrangement where we have 525 00:31:59,060 --> 00:32:02,970 least constrained first, and we'll crank up the speed. 526 00:32:06,140 --> 00:32:08,190 Well actually, we would have to crank it up pretty big, 527 00:32:08,190 --> 00:32:12,700 because the states like Missouri, Tennessee, Kentucky, 528 00:32:12,700 --> 00:32:16,264 they're going to be like Texas. 529 00:32:16,264 --> 00:32:18,730 And so were kind of back to the length of the universe 530 00:32:18,730 --> 00:32:19,420 type problem, here. 531 00:32:19,420 --> 00:32:22,640 With the least constraint first, and no use of 532 00:32:22,640 --> 00:32:28,090 constraints, other than to check the current assignment. 533 00:32:28,090 --> 00:32:32,440 So let's stop that, though, and check the most constrained 534 00:32:32,440 --> 00:32:35,790 first, assignments only. 535 00:32:35,790 --> 00:32:37,310 I don't know how long's this going to take. 536 00:32:39,880 --> 00:32:42,150 That's the dirty little secret. 537 00:32:42,150 --> 00:32:46,010 If we had arranged our states from most constrained to least 538 00:32:46,010 --> 00:32:48,440 constrained, ordinary depth first search with none of this 539 00:32:48,440 --> 00:32:51,840 stuff we talked about today would work just fine. 540 00:32:51,840 --> 00:32:53,090 All right. 541 00:32:56,700 --> 00:33:00,460 So it's a little bit like games. 542 00:33:00,460 --> 00:33:02,260 Do you use progressive deepening, or do 543 00:33:02,260 --> 00:33:03,500 you use alpha beta? 544 00:33:03,500 --> 00:33:04,885 And the answer is both. 545 00:33:04,885 --> 00:33:09,730 You use everything you've got to deal with the problems. 546 00:33:09,730 --> 00:33:14,410 And depending on the problem, one or another of the things 547 00:33:14,410 --> 00:33:17,250 you incorporate into your approach will work just great, 548 00:33:17,250 --> 00:33:20,040 if you're lucky. 549 00:33:20,040 --> 00:33:24,035 So now, I promise that this is useful not only for people who 550 00:33:24,035 --> 00:33:24,755 want to color maps. 551 00:33:24,755 --> 00:33:25,820 God, who wants to do that? 552 00:33:25,820 --> 00:33:28,000 We know it can be done with four colors. 553 00:33:28,000 --> 00:33:30,870 But it's also useful for doing all kinds of 554 00:33:30,870 --> 00:33:33,530 resource planning problems. 555 00:33:33,530 --> 00:33:35,900 So I want to show you a resource planning problem, and 556 00:33:35,900 --> 00:33:37,810 I want you think about-- while I'm doing it-- 557 00:33:37,810 --> 00:33:39,900 think about whether it's actually analogous to the map 558 00:33:39,900 --> 00:33:40,700 coloring problem. 559 00:33:40,700 --> 00:33:42,280 All right? 560 00:33:42,280 --> 00:33:43,180 So here's the deal. 561 00:33:43,180 --> 00:33:46,950 You have just landed a summer job with the Jet 562 00:33:46,950 --> 00:33:50,210 Green, a new airline. 563 00:33:50,210 --> 00:33:58,560 And Jet Green is a low cost, no frills, hardly any 564 00:33:58,560 --> 00:34:01,460 maintenance type of airline. 565 00:34:01,460 --> 00:34:05,730 And they want to fly mostly between Boston and New York. 566 00:34:05,730 --> 00:34:08,480 Occasionally they want to fly to Los Angeles. 567 00:34:08,480 --> 00:34:09,880 And they're trying to get by with the 568 00:34:09,880 --> 00:34:11,889 smallest number of airplanes. 569 00:34:11,889 --> 00:34:15,351 So that's why we have a kind of resource allocation problem 570 00:34:15,351 --> 00:34:17,500 with Jet Green. 571 00:34:17,500 --> 00:34:19,889 So I'm going to write down what their 572 00:34:19,889 --> 00:34:20,350 schedule looks like. 573 00:34:20,350 --> 00:34:26,590 They have one flight, F1, that goes from Boston 574 00:34:26,590 --> 00:34:32,429 to JFK, like so. 575 00:34:32,429 --> 00:34:35,739 It's an early in the day flight. 576 00:34:35,739 --> 00:34:39,000 Then they want to have another one, F2, that 577 00:34:39,000 --> 00:34:42,290 flies from JFK to Boston. 578 00:34:47,389 --> 00:34:50,489 And then they want to have another flight a little later 579 00:34:50,489 --> 00:34:54,610 in the day that flies from Boston to JFK. 580 00:34:57,420 --> 00:34:59,340 And a little later than that, they want to have another 581 00:34:59,340 --> 00:35:04,580 flight that goes from JFK to Boston. 582 00:35:04,580 --> 00:35:07,230 They're going to start off mostly as a shuttle airline in 583 00:35:07,230 --> 00:35:07,670 the beginning. 584 00:35:07,670 --> 00:35:13,430 So that's F1, F2, F3, and F4. 585 00:35:13,430 --> 00:35:18,460 And they have a fifth flight, F5, that goes from Boston to 586 00:35:18,460 --> 00:35:21,600 Los Angeles, that takes a long time. 587 00:35:21,600 --> 00:35:24,460 So it looks like this on the schedule. 588 00:35:24,460 --> 00:35:26,940 Of course we have time going that way. 589 00:35:26,940 --> 00:35:30,325 So that's Boston to LAX. 590 00:35:33,836 --> 00:35:39,870 Now your job is to determine if they can fly this schedule 591 00:35:39,870 --> 00:35:42,610 with four aircraft? 592 00:35:42,610 --> 00:35:45,065 And naturally you don't want to over use any one aircraft, 593 00:35:45,065 --> 00:35:48,080 because you would like to have even wear on them. 594 00:35:48,080 --> 00:35:48,840 Right? 595 00:35:48,840 --> 00:35:53,090 So as you make your choices, you'll rotate the aircraft. 596 00:35:53,090 --> 00:35:58,140 So you'll assign to this one to A1, aircraft number one. 597 00:35:58,140 --> 00:36:00,160 This one will be A2. 598 00:36:00,160 --> 00:36:02,380 This one will be A3. 599 00:36:02,380 --> 00:36:05,160 And this one will be A4. 600 00:36:05,160 --> 00:36:09,370 And, oops, there's no aircraft left for the flight to Los 601 00:36:09,370 --> 00:36:12,240 Angeles, because you only have four. 602 00:36:12,240 --> 00:36:13,410 So, it's obvious, right? 603 00:36:13,410 --> 00:36:18,450 This is 100%, exactly, the map coloring problem, even down to 604 00:36:18,450 --> 00:36:20,380 the four choices. 605 00:36:20,380 --> 00:36:24,050 Because, you have the constraint, the no single 606 00:36:24,050 --> 00:36:29,300 physical aircraft can fly two flights at the same time. 607 00:36:29,300 --> 00:36:30,920 Just like no two adjacent states can 608 00:36:30,920 --> 00:36:32,820 be colored the same. 609 00:36:32,820 --> 00:36:38,025 So there's a no same time constraint, like so. 610 00:36:45,170 --> 00:36:49,620 So if you were assigning aircraft to these flights, you 611 00:36:49,620 --> 00:36:53,040 would get down to F4, the fourth flight, and you would 612 00:36:53,040 --> 00:36:59,310 say, well, let's see, this guy down here can be 613 00:36:59,310 --> 00:37:00,570 A1, A2, A3, or A4. 614 00:37:00,570 --> 00:37:03,700 But if I choose A4 for that fourth flight, then there 615 00:37:03,700 --> 00:37:07,540 would be nothing left in its domain. 616 00:37:07,540 --> 00:37:14,640 So you've thus set the problem up to be identical to the map 617 00:37:14,640 --> 00:37:15,540 coloring problem. 618 00:37:15,540 --> 00:37:18,100 And, of course, you can enrich it with other kinds of 619 00:37:18,100 --> 00:37:19,370 constraints. 620 00:37:19,370 --> 00:37:21,190 So, for example, you might have-- 621 00:37:21,190 --> 00:37:22,980 this is a not same time constraint-- 622 00:37:31,040 --> 00:37:36,030 and these, I mean, this is at JFK. 623 00:37:36,030 --> 00:37:40,590 And it flies out of JFK, so maybe you can use the same 624 00:37:40,590 --> 00:37:41,670 aircraft for those. 625 00:37:41,670 --> 00:37:43,550 But not if they're right up against each other, because 626 00:37:43,550 --> 00:37:46,110 you have a minimum ground time rule. 627 00:37:46,110 --> 00:37:48,030 So there's a minimum ground time constraint here. 628 00:37:50,650 --> 00:37:52,490 And there's a minimum ground time constraint here. 629 00:37:55,400 --> 00:37:57,230 There's a minimum ground time constraint here. 630 00:38:02,030 --> 00:38:05,310 And if these are at the same city, then you've got to allow 631 00:38:05,310 --> 00:38:07,520 enough time for them to fly between the two cities that 632 00:38:07,520 --> 00:38:08,800 are involved. 633 00:38:08,800 --> 00:38:10,820 So the constraints can get a little bit more complicated, 634 00:38:10,820 --> 00:38:13,430 but the idea is the same. 635 00:38:13,430 --> 00:38:16,690 So you say to me, I don't trust you, show me. 636 00:38:16,690 --> 00:38:17,660 OK. 637 00:38:17,660 --> 00:38:20,620 So let me show you. 638 00:38:20,620 --> 00:38:22,680 Oh, by the way, there's one more way to make this map 639 00:38:22,680 --> 00:38:23,930 coloring problem easier, right? 640 00:38:27,430 --> 00:38:28,330 Let's see. 641 00:38:28,330 --> 00:38:31,770 The arrangement is going to be alphabetical, the type is 642 00:38:31,770 --> 00:38:37,000 going to be assignments only, and we know that's a loser. 643 00:38:37,000 --> 00:38:42,650 But not if we use a whole lot of colors. 644 00:38:42,650 --> 00:38:46,520 So it's the use of four colors that got us into trouble. 645 00:38:46,520 --> 00:38:48,540 Now that's an aside, but it'll be coming back 646 00:38:48,540 --> 00:38:49,500 in a moment or two. 647 00:38:49,500 --> 00:38:52,951 Scheduling, here's that problem. 648 00:38:52,951 --> 00:38:55,110 Boom. 649 00:38:55,110 --> 00:38:56,910 You can almost see it working just like the 650 00:38:56,910 --> 00:38:58,612 map coloring thing. 651 00:38:58,612 --> 00:39:01,940 But that's maybe too easy. 652 00:39:01,940 --> 00:39:03,190 Let's do this one. 653 00:39:06,854 --> 00:39:10,020 See this is just like [? simplicia. ?] 654 00:39:10,020 --> 00:39:13,520 We've kind of got a goofy arrangement here that's 655 00:39:13,520 --> 00:39:16,790 guaranteed to lose at the bottom because of choices made 656 00:39:16,790 --> 00:39:18,700 at the top. 657 00:39:18,700 --> 00:39:19,740 But that's OK. 658 00:39:19,740 --> 00:39:25,370 We can that we can stop this, and we can change to check 659 00:39:25,370 --> 00:39:27,440 neighbors only. 660 00:39:27,440 --> 00:39:28,690 And boom, there it goes. 661 00:39:31,830 --> 00:39:34,220 Or alternatively, let me see if I can do it this way. 662 00:39:34,220 --> 00:39:38,738 Most constrained first, type will be assignments only. 663 00:39:38,738 --> 00:39:41,210 Boom. 664 00:39:41,210 --> 00:39:42,460 That worked fine, too. 665 00:39:44,790 --> 00:39:47,260 So you might choose to have a slightly harder 666 00:39:47,260 --> 00:39:50,920 problem, like this. 667 00:39:50,920 --> 00:39:53,590 And we can search away. 668 00:39:58,390 --> 00:40:00,420 Actually I don't know if this will complete or not. 669 00:40:00,420 --> 00:40:03,970 This is a randomly generated example. 670 00:40:03,970 --> 00:40:07,060 But you're going to lose your summer job if you can't figure 671 00:40:07,060 --> 00:40:08,960 out whether you can do this, or not. 672 00:40:08,960 --> 00:40:10,210 So what are you going to do? 673 00:40:13,175 --> 00:40:15,040 [? Elliott, ?] you got any thoughts about how you're 674 00:40:15,040 --> 00:40:18,260 going to save your job? 675 00:40:18,260 --> 00:40:20,850 So here's the question you've been asked. 676 00:40:20,850 --> 00:40:26,380 How many airplanes does Jet Green need? 677 00:40:26,380 --> 00:40:30,015 And you decide, well, four seemed to work before, so 678 00:40:30,015 --> 00:40:32,020 we'll try four here. 679 00:40:32,020 --> 00:40:34,980 You're not sure if it's going to terminate or not, I mean, 680 00:40:34,980 --> 00:40:38,170 in your lifetime, let alone in your summer job. 681 00:40:42,760 --> 00:40:44,890 [? Elliott, ?] let me give you a hint. 682 00:40:44,890 --> 00:40:46,140 Look at the outline. 683 00:40:48,110 --> 00:40:51,643 The outline up here, on the board, the last item. 684 00:40:51,643 --> 00:40:52,610 [? ELLIOTT: [INAUDIBLE] ?] 685 00:40:52,610 --> 00:40:52,685 PROF. 686 00:40:52,685 --> 00:40:53,935 PATRICK WINSTON: Yeah, what's that mean? 687 00:40:57,030 --> 00:41:00,380 What's the maximum number of airplanes we're going to need? 688 00:41:00,380 --> 00:41:04,990 Suppose we've got five flights, what's the maximum 689 00:41:04,990 --> 00:41:07,040 number of airplanes we would ever need? 690 00:41:07,040 --> 00:41:08,350 Five. 691 00:41:08,350 --> 00:41:11,020 What's the minimum number of airplanes we'll need? 692 00:41:11,020 --> 00:41:12,750 One. 693 00:41:12,750 --> 00:41:17,510 So let's try it with a small number of airplanes and a 694 00:41:17,510 --> 00:41:18,760 large number of airplanes. 695 00:41:25,430 --> 00:41:29,190 So that showed us very fast that we can't 696 00:41:29,190 --> 00:41:30,440 do it with one airplane. 697 00:41:39,210 --> 00:41:43,866 That showed us very fast we can do it with ten airplanes. 698 00:41:43,866 --> 00:41:46,794 SPEAKER 1: [INAUDIBLE] 699 00:41:46,794 --> 00:41:51,680 amount of overlappage from up [INAUDIBLE]. 700 00:41:51,680 --> 00:41:51,747 PROF. 701 00:41:51,747 --> 00:41:52,997 PATRICK WINSTON: Volunteer? 702 00:41:55,110 --> 00:41:58,140 What are we going to do to find the actual number, as 703 00:41:58,140 --> 00:41:59,080 fast as possible. 704 00:41:59,080 --> 00:42:03,110 And at least give our boss a reasonable answer, even if not 705 00:42:03,110 --> 00:42:05,230 necessarily the exact number very fast? 706 00:42:07,960 --> 00:42:08,630 It's easy, right? 707 00:42:08,630 --> 00:42:11,840 We're going to start up here with one computer, and we're 708 00:42:11,840 --> 00:42:14,850 going to start down here with another computer, 709 00:42:14,850 --> 00:42:16,930 and see what happens. 710 00:42:16,930 --> 00:42:19,280 So let's see if we can do it with nine. 711 00:42:24,240 --> 00:42:27,200 Let's see if we can do it with eight. 712 00:42:31,110 --> 00:42:34,100 Let's see if we can do it with seven. 713 00:42:34,100 --> 00:42:35,600 These take almost zero time, right? 714 00:42:35,600 --> 00:42:36,850 Because they're under constraint. 715 00:42:40,720 --> 00:42:42,130 Wow, that's good, seven. 716 00:42:42,130 --> 00:42:43,810 Let's try six. 717 00:42:43,810 --> 00:42:45,060 Actually let's try two. 718 00:42:48,790 --> 00:42:50,580 It loses fast. 719 00:42:50,580 --> 00:42:51,830 Let's try three. 720 00:43:01,860 --> 00:43:02,120 I don't know. 721 00:43:02,120 --> 00:43:05,440 Maybe if you let it run one long enough three will work. 722 00:43:05,440 --> 00:43:07,120 I doubt it. 723 00:43:07,120 --> 00:43:09,110 While we're at it though, we might as well go back here and 724 00:43:09,110 --> 00:43:09,790 try it with six. 725 00:43:09,790 --> 00:43:11,040 Remember seven worked real fast. 726 00:43:15,000 --> 00:43:17,510 Gees, six, that was six, right? 727 00:43:17,510 --> 00:43:17,870 Yeah. 728 00:43:17,870 --> 00:43:19,120 So let's try it with five. 729 00:43:22,650 --> 00:43:22,950 OK. 730 00:43:22,950 --> 00:43:24,730 So it runs real fast with five. 731 00:43:24,730 --> 00:43:27,660 It terminates real quick with two, so we got 732 00:43:27,660 --> 00:43:29,710 three and four left. 733 00:43:29,710 --> 00:43:33,955 So we could tell our boss, a la any time algorithm, that 734 00:43:33,955 --> 00:43:35,890 you're not real sure, but you know it's going to be either 735 00:43:35,890 --> 00:43:37,280 three or four. 736 00:43:37,280 --> 00:43:39,270 And then, you got two computers. 737 00:43:39,270 --> 00:43:43,120 You can let both run and see if either one terminate. 738 00:43:43,120 --> 00:43:44,730 So you have three and four. 739 00:43:44,730 --> 00:43:49,140 My guess is that three will eventually give up. 740 00:43:49,140 --> 00:43:51,040 But of course, there's another little problem here. 741 00:43:51,040 --> 00:43:53,700 We haven't used the most constraint first. 742 00:43:53,700 --> 00:43:56,520 If we did that, we might be able to do it even faster. 743 00:43:56,520 --> 00:43:59,620 Actually, I don't think I can make that switch without 744 00:43:59,620 --> 00:44:01,810 getting another random assignment, but 745 00:44:01,810 --> 00:44:04,320 let's see what happens. 746 00:44:04,320 --> 00:44:05,950 Maybe so. 747 00:44:05,950 --> 00:44:07,200 SPEAKER 2: [INAUDIBLE] 748 00:44:10,180 --> 00:44:10,266 PROF. 749 00:44:10,266 --> 00:44:12,000 PATRICK WINSTON: Oh, I already had most constraint first? 750 00:44:12,000 --> 00:44:13,370 OK. 751 00:44:13,370 --> 00:44:15,660 So it didn't help to actually switch. 752 00:44:15,660 --> 00:44:18,750 And I think I've got a new schedule to work here. 753 00:44:18,750 --> 00:44:21,190 So that's the end of the story. 754 00:44:21,190 --> 00:44:25,250 You can do good resource allocation if you do several 755 00:44:25,250 --> 00:44:26,510 things are once. 756 00:44:26,510 --> 00:44:29,450 Number one, you always want to use most constraint first. 757 00:44:29,450 --> 00:44:31,350 Number two you want to propagate through domains 758 00:44:31,350 --> 00:44:33,050 produced to a single algorithm. 759 00:44:33,050 --> 00:44:35,380 And number three, if you really try to figure out what 760 00:44:35,380 --> 00:44:39,086 the minimum number of resources needed is, you do 761 00:44:39,086 --> 00:44:42,380 this under over business and you can quickly converge on a 762 00:44:42,380 --> 00:44:45,550 narrow range where the search is taking a long time, and be 763 00:44:45,550 --> 00:44:49,310 sure that it lies within that narrow range. 764 00:44:49,310 --> 00:44:52,330 Because when you over resource, it's fast to 765 00:44:52,330 --> 00:44:54,670 complete, and when you under resource, 766 00:44:54,670 --> 00:44:57,180 it's fast to terminate. 767 00:44:57,180 --> 00:44:59,180 So you can just squeeze it right down into 768 00:44:59,180 --> 00:45:00,600 a very small range. 769 00:45:00,600 --> 00:45:02,270 And that is the end of the story. 770 00:45:02,270 --> 00:45:03,700 Enjoy your holiday on Monday. 771 00:45:03,700 --> 00:45:08,660 We'll have two classes next week on Wednesday and Friday, 772 00:45:08,660 --> 00:45:09,910 as advertised.