 Hello, don't you just hate it when you're driving and you run into road maintenance? You have to take a detour and that also runs into other road maintenance? Today I'm going to show you how to automate and optimize maintenance scheduling with OptaPlaner or Open Source AI Constraint Solver. You can use this to plan better maintenance of roads, railroads, electricity grids, buildings, vehicles, elevators and any other type of machinery. And with a few changes it also works for inspection planning, for example for bridges or schools. Let's get started. So in maintenance scheduling we have to assign jobs to crews and a certain start date for each of these jobs. Now for example in this case we do road maintenance and so we have an uptown street job, maintenance on the uptown bridge, maintenance on the Florence road and also on the airport tunnel. So that's four jobs we have to assign. Now we can assign these to either crew A or crew B and we can let them start on any of these dates. Like we can start on any of these jobs on the 1st of November, 2nd of November and so forth. However, the crews do not work during the weekend but we can start something before the weekend and have it finished a few days after the weekend. That's fine. Each of these jobs takes a number of days. So for example the first three jobs take three working days while the last one takes four working days. And they also have a ready date and a due date. So the ready date is the earliest starting date and the due date is by when it should have ended. So for example the green job here, the uptown street job has a ready date of the first of November. So we can start on the 1st of November. It takes three days then it will finish by the 4th of November. That's fine because it's only due until the 5th. So end dates and due dates are exclusive while ready dates and start dates are inclusive. It's easier to calculate that way. Now if we started the 2nd of November then it will still be finished by the 5th of November. So that's fine. But if we would start at the 3rd of November then it will not be finished in time and then it will actually violate that due date. So that's a hard constraint that we would violate and we don't want to do that. Similarly we can do it all of these jobs have these ready and these due dates and you get a good glimpse here on how much flexibility we have per job to plan them. So what we're going to do is we're going to give this to Optoplanar but there's a few other constraints we need to take into account. So for example each of these jobs, each of these crews can only do one job at a particular date. They cannot have jobs, cannot overlap and be assigned to the same date, to the same crew. And also when we have two jobs in the uptown area we don't want to do them at the same time. Remember what I started with when we have road maintenance we don't want to take a detour for road maintenance and run into other road maintenance. So let's not plan maintenance in the same area at the same time. So what do we do is we give this to Optoplanar and Optoplanar gives us a solution. It's that simple. So here we can see that crew A is doing the uptown street job and then from the 1st of November till the 3rd and then it does the airport tunnel and so forth. Crew B starts with a forest road on the 2nd of November. Why it cannot start with the forest road earlier? Now you could start with the uptown bridge earlier on the 1st of November and that's true but if it would do that it would not be able to finish the forest road job, would not be able to finish in time because that's due by the 6th of November. So it actually turns out that this is the optimal schedule. Now you can also see here that the uptown, the two uptown jobs are not scheduled, are not overlapping. So that means that when I drive into the road maintenance of this, of the uptown street, my detour will not drive me into another road maintenance on the bridge. So that's also a good thing to have. So now let's take a look at how that works in UI. So here we go. This is the demo application. The source code of this is course available. You can alter this to your needs. And here we have a number of unassigned jobs like we have the downtown bridge, downtown street, uptown street and so forth. You can see the same thing, again a number of working days, a number of ready and due dates and a number of tags, like what area do they affect or in this case do they affect the subway network? And of course we only want to affect the subway network, one maintenance job at the time, right? So very similar to not working the same area, don't work on the subway at two different places at the same time. Here you can see our schedule. So let's start solving this, let's start assigning this, let's give Optoplanar a few seconds to assign this and you can see it's found the solution to this. And in this case you can see that no crew has two jobs at the same time. So that hard constraint is already fulfilled. You can also see that the, now let's take a look at them by job. So here we show them by job and what you can see here for each of the jobs you can see the green part is starts when the ready date opens and the yellow part ends when the due date ends. So for example this downtown bridge job for five working days assigned to the alpha crew starts in time, starts at its ready date and finishes, well, it takes five days and then the weekends there, but anyway it finishes before it's 20 seconds, right? If you scroll down here you can see this particular job over here, this, the uptown street job is three working days. It actually starts within after its ready date and it actually finishes before it's due date, the yellow part ends with the due date. So that's still fine, that still adheres to the hard constraints. But you can see in issue here, right? It's really very, very late, it's just in the nick of time and that's not really a good thing. Any sort of delay in this plan could actually push this past its due date. So we want to avoid that, it's not really hard constraint, it shouldn't always be like this. But we want to try to avoid this as much as possible, as much as we're allowed. One of the constraints we'll have to add right now is to make sure that it is not pushed beyond its due date. So let's do that. So what I'm going to do is I'm going to switch to the code right now. And as you can see here, those constraints that I talked about are already activated, the crew conflict constraint is to make sure that no two jobs happen at the same time for the same crew. The ready date constraint makes sure that no job starts before it's ready. And the due date makes sure that no job ends after it's due. Now let's add that particular one that we don't go over the, do not go into the yellow area. So the yellow area starts with an ideal date. So if we now go back to the application, what you will see is that if we refresh, let's refresh, I click at five, here we go. I click solve, and then Optaplan will solve this again. But this time when we actually look at the jobs per crew, you will see that none of the jobs are assigned in the yellow area. None of the jobs are assigned and after they're ideal ending date. So this is how we can add constraints just to see the effects of that. Now let's go back to the crews here. There's still a few issues here, right? We talked about the fact that we didn't want to have jobs in the same area at the same time, so we didn't want to have the uptown job. For example, two uptown jobs here at the same time, right? You can also see that the gamma crew is not really doing any work. So we could also add a constraint to more fairly distribute this work across the teams. But in this particular case, we can just solve it by saying, okay, we don't want to have two jobs in the same area at the same time. So let's just activate that. So when I go back to my code, when two jobs have a tag conflict, that means they have the same tag at the same, and they're overlapping. Then that's a bad thing, so that's a soft constraint. So we're going to tell Optaplaner don't do that. And now when we go back to our code here, we again hit the refresh button. This is using Quarkus underneath. That's the reason why we can refresh so quickly. And then we solve it again. We see the effects with this in play. And here we go. What we can see now is we have no two jobs that are actually, that use the same area and are overlapping, like the uptown job here. You can see uptown is a yellow tag. So if you follow the yellow tags, you will not see two yellow tags happening at the same time. Same for the green ones, same for the park one, and same for the subway one, the blue one here. So that's good. But we still want to make the schedule better, because if you look at it per job, what you will see is that it doesn't really pull the jobs forward, nor pushes them backwards. So depending on what you want to do, you might want to forward schedule, where you want to have your jobs done as early as possible. But you also might want to schedule just in time. That means you want to wait with your maintenance as long as possible. Because the sooner you do your maintenance, the sooner you have to do it again. And that's not really cost-effective. So let's take a look at the rules for that. Here we go. So we have two rules here, one that says I want to do forward scheduling. So let's activate forward scheduling. Go back to the code, let's hit F5. OK, let's click the Solve button. Here we go. It's assigning the jobs again. You can see we're now actually having some soft constraints broken. Because now it actually becomes a difficult problem. And before that, it was, for Optipliner, at least, pretty easy to do. So what we can now see, I'm just going to stop solving here. If we go to look at them per job, you can see it pushes the jobs as much forward as it can. Not all of the jobs start at their ready date, but a lot of them start pretty close to their ready date. This is forward scheduling. Do all of the jobs as quickly as possible. If it would be inspection scheduling, again, you might want to pull your inspections forward as much as possible. So when new inspections come in, you are more likely to still have room for them later down the period. But on the other hand, we could also do just in time for maintenance scheduling again. You might want to wait until the very last moment to do that maintenance. So let's try doing that. So let's push it. Let's do JIT scheduling. Just in time scheduling. That means we want to push it as close to that ideal date as possible. So if we go back here, we hit F5 again. We solve this again. Now we're going to push the end date of the jobs as closely as possible to the ideal date. So basically, if you look at it at the green area, let's take a look here, what we do is we try to push it as close to the last green date, ending on this last green date. You can see some of these happening here already. And it's still optimizing. It's still improving it. But you can see that it's really pushing the jobs to the end. You can see many jobs ending at the best moment, which is that end date, or close to that at least. And of course, you can change the constraints any way you see fit to really fit your needs and your business. And you will probably have some custom constraints specifically for your business. And you can just add those, of course, too. Now, if you want to learn more about this, this quick start is available in Optoplanar. So just go to optoplanar.org and try it out. Thank you for listening.