 In the previous video, we learned about the critical time of a task, which the critical time is the length of the longest path on the project diagram from that task to the end and represents the shortest amount of time it would take to finish the project once you've started said task. I mean, that's not a guaranteed time it's going to take to finish, but if you have unlimited resources with processing, that is the absolute minimum time it would take to finish the project from the start of that task. And that's a pretty important thing. We had previously prioritized processing time, which is important, but it turns out critical time is really where the money's at. Critical time and processing time are related to each other because the bigger the processing time of a task, the longer the critical time will be. But the processing time completely ignores the president's relations while critical time has them baked into the cake. And so as we prioritize tasks, we actually want to prioritize them according to their critical time. And so this leads to the critical time priority list. The critical time priority list is the priority list where tasks are ranked by their critical time. The task with the highest critical time gets ranked first, then the task with the second highest critical time gets ranked second. And the third critical time highest, you got it. It's going to be the third one and we do that on and on and on and on. So if we can compute the critical times for all the tasks, which we can, we can then build a priority list. And with a priority list, we can build a schedule. And so that's exactly what the critical time algorithm is going to do. Very similar to the decreasing time algorithm, which just use processing times to rank the task and then you build a schedule from that ranking. The critical time algorithm, we use critical times instead. Now unlike the decreasing time algorithm for which the pre, the processing times are ever present to us, we know them from beginning of the problem. We don't know the critical times because you have to compute the critical times using the processing times, but also the president's relations. But as we learned in the previous video, we can use the backflow algorithm to compute the critical times for all of the tasks in the project. The backflow algorithm is basically just Dexter's algorithm, but you're looking for longest paths now instead of shortest paths. Once you compute all of the critical times, then you can rank all of the critical times based on all the tasks by their critical times. This then gives you a priority list. And using that priority list, we can construct a schedule. This gives us the critical time algorithm. And this is going to turn out to be a very fantastic algorithm for computing an optimal schedule to a project. So as a reminder, on the previous video, we took our Martian home project with these 15 tasks and we computed all of the critical times using the backflow algorithm. And so that's what you see these red numbers here on the screen. The white numbers and the parentheses are the processing times of each of those tasks. The red numbers and the brackets are the critical times that we computed and of course the arrows represent the president's relations that we're usually having here. All right, so in terms of the critical time priority list, since we've already computed the critical times using the backflow, we don't have to do that again. If you if you did miss that or didn't understand that, please look at the previous lesson from the previous video from lesson 12 to see exactly the calculation of those critical times. But assuming we now know those critical times, which we do, we can then start coming up with a critical time priority list for which we look for the highest critical time. That's going to be task AP. So that's our first on our list. It has a critical time of 34. No one's bigger than that. That's the critical time of the project. Next, we're then going to do AF, which has a critical time of 32. So that's going to be the second one. After AF, I'm going to do AW whose critical time is 28. Now in previous examples of this problem, we often prioritized AD because it's one of these four events that starts off in the ready position because it has no predecessors, but that's actually not the best one to do. The next best is actually going to be IF because it's critical time is 27. So it's fourth in our priority. After IF, we're going to do IW whose critical time is 22. And only after IW are we going to put AD in our list at 6th because 18 comes after 22 then. After AD, the next one would be IP, who has a critical time of 15. Then you see a curious thing happening. You have PL and HU. They have a tie with their critical times. They're both the critical time of 11 Martian days there. So who's lose the most priority one? Because if there has to be a decision, like a processor has to do PL or HU, we can't just leave it as a tie. You've got to make a decision there. Now, the critical time algorithm doesn't itself have a solution for this tiebreaker. But what we're going to do is the following. In some respect, it doesn't matter too much since they have the same critical time. So you potentially could run two schedules where one has PL before HU and the second one has HU over PL. This would be very easy with a computer who can build the schedule from a priority list as a student who maybe has a homework problem to do. We don't necessarily want to do that. So we're going to do the following rule here. Even though they have the same critical time, you'll notice that HU has three successors while PL only has one. So I'm actually going to prioritize HU slightly higher because the idea is, especially those between HU and PL, they're both the successors of IC. So the thing is I can't do IC until HU and PL are done. So it doesn't really matter for IC's sake, which one comes first because they have to both be accomplished. But HU does have other successors, which maybe otherwise opened up if you did HU first. So while maybe someone else is processing PL, you could then start working on PD or EU. That's sort of my thought process. So I'm going to prioritize HU a little bit more than PL because it has more successors, then PL will come next. After 11 would come ID, which has a critical time of 10. It's going to be the 10th one in our list. After that will be IC, which has a critical time of seven. So it's the 11th one there. Next, we're going to have FW here with a priority time of a critical time, excuse me, of six. So it goes there, then PU has a critical time of five. So we're going to put that at 13. And then PD, it has a critical time of three. So it's going to go 14. And then EU will be our last one, whose critical time is 15. Like so. And so this then gives us our critical time priority list. We got all of the vertices and they've all been ranked based upon who's the most important. Again, there was a little bit of confusion with PL and HU. But it turns out that we made a tiebreaker. So we're going to put HU a little bit higher and that's going to be advantageous for us. So now what we're going to do is I'm going to list the priority list over here now on the left-hand side. I want us still to be able to see the digraph. So I'm going to take a simplified smaller version right here because it's really just the precedence relations I need to see here because each of these tasks has its processing time and critical time listed. So I don't need those on the graph anymore. I couldn't fit the bigger graph here. So I'm going to build the schedule using this priority list and these precedence relations. So at the start of the schedule, the four tasks that have no precedence, no have no predecessors, they're going to be in the ready position. So AP is ready, AF is ready, AW is ready, and AD is ready. So we have two processors on this problem. So we're going to start off with the highest priority one, which is going to be AP. So processor one is going to get AP and that's going to work for seven Martian days. It's going to work on that. Do, do, do, do, do, do, do, do. And so we write that in there, AP. All right, I know it's not the easiest thing to see there, but that's our schedule there. What is processor two going to do? Processor two then will take the next highest priority, which is AF. So that'll take five days to accomplish it. And so we're going to get AF right there, okay? So then the next one, so we're going to fast forward until day five. Once we hit day five, then AF will then be completed. Looking at the graph here, AF proceeds IW, but AP's not done yet, so nothing opens up. So the processor then is going to grab AW right here. I will do that one in red. AW takes six days to compute. So since we're currently at day five, we're going to go up to day 11, like so. AW, like so. And so then we go from there, fast forward to day seven. At day seven, AP will then be done, okay? So since AP is done, and so is AF, that opens up IF. So IF is now available, it's ready. It has the highest priority of any ready tasks. So we're going to give IF to processor one there. So IF takes five Martian days to compute, we're at day seven currently. So this is going to go up to day 12. Fill that in there. And so this was task IF, like so. And so then we proceed from there. So the next thing to check is at day 11, AW will be completed. At AW, AW proceeds IW, but so does IF, which is in execution right now. So IP is not going to open up yet. So that means AD is the task that we're going to have to do next. So for AD, that'll start at day 11. It's going to go for eight Martian days. So that's going to give us to day 19, like so. Then we fast forward to day 12 at this moment. At day 12, task IF will then be done. So since IF is now done and AW is already completed, that's going to open up IW, it also open up PL. So IW is ready and PL is ready. We choose the higher priority one, which is going to be IW. So IW comes next, it takes seven days to complete. We are currently at day 12. So seven plus 12 is going to be 19. So it's actually going to terminate the exact same time that AD is going to terminate IW, like so. And so then let's fast forward to day 19. On day 19, IW and AD are both going to open up. So with IW now completed, it opens up IP, but since AD and IW are open, that opens up ID as well, like so. And so at this moment, we're going to get a processor on the highest priority job, which is going to be IP. IP takes four days to do. So let's see, we're currently at day 19. So we're going to take four plus 19, that's going to get us up to 23. And now it's task IP, like so. Now for processor two, who doesn't have a task yet, we're going to give processor two PL, as that's the next highest priority there. PL will also take four days, four martian days to execute, so it also will terminate on day 23. And so we'll mark that off as PL. And so then fast forward, four days. IP and PL will be completed on the exact same day. IP precedes H-U-N-P-U, okay? For which H-U is then going to be activated, but ID is not done yet. Notice how it's still in the ready state. And as such, P-U won't be activated yet, but H-U will. H-U is now opened up. Where are you, H-U? You're right here. But also, notice that PL was completed. PL, since it was completed, then we look at IC here. IC is not open yet because H-U hasn't been done yet. So we have only two ready tasks, but those are the two we're going to give to our processors. Processor one is going to get H-U, which will take four days. We're currently on day 23, so we're going to fast forward. Well, this task will be completed on day 27. What did I say earlier? I'm sorry, we are on day 23 right now. We're going to then do four more days. So H-U will be completed on day 27. Now for processor two, it'll be assigned task ID, which takes five days. So that actually will complete on day 28, like so. And then we're going to label that one ID. So now we're going to fast forward to day 27 for when an H-U will then be completed. So now that H-U is completed, that opens up PD, okay? Because that's H-U only precedes that one. How about IC? Well, PL is already done, so IC is going to open up. So we have IC and PD. But what about this one? H-U also precedes EU, but PU is not done and PU is still ineligible because ID isn't even done yet. So those are only the ones that are open right now. So then processor one will be assigned IC. I will do that one in blue. IC only takes one day. Oh boy, so it's going to be this one right here. I don't think I can label that in there. So IC is on that one day 27 to 28. So then on day 28, both of the tasks are completed. We're going to finish IC and ID on the same day. Since IC is done, that opens up FW, it's now ready. And since ID is done and IP was done previously, that opens up PU, which is right here. So processor one is going to take on FW, as it's the highest priority. We're on day 28 right now. Add six days to that, that'll go until day 34. That was task FW. And then how about processor two? I'm going to mark this here. So FW is now in execution. How about processor two? Will the highest priority will be PU? So it's going to take on that one. PU takes three days to do it. So since we're on day 28, that's going to take us up to day 31. And then we'll label that one PU. So then the next day to check in is on 31 when PU is now done. With PU being done, it proceeds EU. EU, since HU was already taken care of, EU is now ready, although it has the least priority here. So it turns out PD will be given to processor two. It takes three days to process. We are currently on day 31. So that'll then terminate on day 34. It's PD. So then fast forward into day 34. PD will be done. That's the one we just started. But then also FW will be done on that exact same day. EU is the last task. It's currently open anyways. So we're then going to do it for two more days. So from 34 to 36, that'll be EU. As for processor two, there's no more tasks to do. So it's going to have to idle for those last two days. And so that then gives us the finishing time of this project turned out to be 36 Martian days. Oh boy, we worked through that one and found our finishing time. Let me show you a much prettier designed table, one that's done by the computer and not by my drawing right there whatsoever. But you see the exact same tasks that we saw a moment ago. So P one is going to give me, it's going to be given the schedule of do AP, then IF, then IW, then IP, then HU, then ICFW, EU. Processor two will then be given AF, AW, AD, PL, ID, PU, PD and then idle for the last two days. That does give us a critical time of, excuse me, a finishing time of 36 Martian days. And this is a great improvement compared to the decreasing time algorithm that we saw in lesson 11, just as a reminder, when we did the decreasing time schedule, we actually took 42 days. So huge, huge improvement. Now, just like the decreasing time algorithm, I do have to point out that the critical time algorithm is still a heuristic algorithm. That is, it's a fast algorithm, but it doesn't guarantee that you get the optimal solution. It turns out that for this project, the critical time, excuse me, the critical time for the project is 34 days. So the fact that we are able to get 36 is fantastic. We got really close to the critical time, but it turns out with two processors, you can accomplish this task in 35 Martian days, looking at the following schedule. I'll let you study that for a second here. We'll talk about it. So you compare that to the 34 critical time. So we're only one day short, but look here, there's no idle time whatsoever. So that's how I know this answer is efficient. It's the optimal solution. There's no idle time as opposed to two idle days for P2 on the previous example there. You can't improve a schedule if there's no idle time whatsoever. And it's only one day short of the critical time anyway. So that's fantastic. This would suggest to me that having a third processor would not be a very efficient thing because we can't do better than 34 and we can get 35 with no idle whatsoever. So a third processor would probably not be very helpful for this project here. But where did this come from? Like, okay, I can see why it's optimal because there's no idle time, but how did we improve it? Well, it turns out that the critical time algorithm, it's not guaranteed the optimal solution just like with the traveling salesman. It's a heuristic algorithm. It's fast, but gets a really good answer. But as opposed to some of the traveling salesman problem algorithms we saw, the critical time algorithm gets really close to the optimal solution even if it's not perfect. It turns out to get the optimal solution, you can run the critical time algorithm and then play a little bit of Tetris, right? We gotta move our blocks around to fill in things. So like, notice what happened here. Let me highlight here. What I did is to get the final answer, I just played Tetris a little bit with these ending blocks here. Instead of doing IC right after HU, I actually moved PD there instead. PD has a long processing time, but IC had a slightly longer critical time and so that's why I got prioritized the way it did. IC has a critical time of seven, but a processing time of one as opposed to PD which has a critical, it's critical time is three but its processing time was three as well. So the idea is that the reason IC is so expensive is that FW that follows it is six days and IC has to proceed it. So this chunk right here takes seven days to process but there's nothing that follows it so it doesn't have to happen at this moment. So the thought is if I move this IC FW chunk downwards and put something like PD beforehand, you can see how this worked out here. The thing is we can't do PU at this moment yet because its predecessor wasn't done yet but PD was ready to go, you could do it right then. So you give processor one PD instead and then when you're done with that, you do PU and then EU and then you do this chunk, this IC FW right here because again after all this is a chunk of seven, nothing follows it so we have some freedom near the end. So I just kind of wiggled things around and actually made it work. That doesn't always work but you can still improve the critical time algorithm by sometimes playing Tetris and moving a few blocks around and seeing if you can improve it. And so that then brings us to the end of lesson 12 and also to the end of our chapter on scheduling. It's hopefully you learned a lot about scheduling in this chapter. I hope you did. If you did learn some things, please like these videos, subscribe to the channel to see more videos like this in the future. If you have friends or colleagues who might benefit from these videos, please feel free to share them. And as always, if you have any questions, feel free to post them in the comments below and I'll gladly answer them as soon as I can.