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