 Hi, in this Optoplanar Example video, I look into the problem of assigning hospital beds to patients. Now, this is actually quite similar to assigning hotel rooms to guests or prison cells to prisoners, as I'll explain later in this video. And it is also quite similar to other equipment scheduling problems, which can range from assigning small things or larger things to periods or teams bounded by time, of course, right? Now Optoplanar has actually been used for these kinds of use cases around the globe. So let's take a look at this particular use case, the assigning of hospital beds. As you can see, a hospital bed has some equipment around it, right? And this will actually be one of the constraints we'll need to take into account in this particular use case, because depending on the equipment that each bed or each room has, we cannot, we can only put certain patients, types of patients into that room, right? So here's actually a solved case, so let me zoom that out a little bit. Here's a solved case. So, as you can see here, we have a number of rooms on the side. So for example, we have room 11, room 12, room 13, and so forth. And each room has at least one bed. So for example, room 11 has only one bed. It's bed A. Room 12 only has also has only one bed. The room 16 has bed A and bed B. Each room also has some equipment and the equipment you can actually see on as these rectangle boxes. For example, the room, this room has the green equipment, which might be the oxygen mask. And this room has the green equipment and the yellow equipment. So the yellow equipment might be something else like the availability of a morphine pump or something like that. As you can see, room 13 and room 14 don't have any specific equipment. Now, then we also have a number of nights, as you can see here on the top. So, for example, this is the night of the first of January, the second of January, and the third of January. Now, for each of these patients that you see here, each of these things, each of these buttons are actually a patient. We know when the patient is arriving and when he's leaving. We cannot alter that. But we have to choose in which bed we are going to put this patient. So for example, in this particular setup, we've actually assigned patient 147, this patient here, into bed 13. Now, this particular patient, as you can see, it's a male patient. He doesn't need any particular equipment. So he doesn't need an oxygen mask or anything like that. So that's fine because this room doesn't supply any of that. As you can see here, for example, a female patient is 177. She needs the yellow equipment and you can see that the room we've put her in actually has this yellow equipment. So that's a good thing. There is also the green equipment available in that room. She doesn't need that and that's fine. Now, what we could not do, what we cannot do is, for example, put this patient into one of the beds that does not have the yellow equipment, as that would endanger her life. And we don't want to do that, of course. That is a hard constraint. Another hard constraint that we have is that we cannot put two patients in the same bed in the same night. So there should not be any overlaps. So for example, we can put this patient 177 into not in the same bed as this patient 141 because they are actually sharing two nights there. But we can put her in the same bed as this particular patient because this patient is only arriving at the 4th of January while this patient is already leaving at the 2nd of January. So as long as there are no overlaps, it's good. It's fine. So what are the hard constraints that we have? Well, we also have each room has a certain type of gender it will allow. Now, in this particular data set, all of the rooms are pretty much the same. As you can see, they all are based on the split gender principle. What basically means that you can put any gender in the room and sometimes in some data sets, there are actually rooms that only allow female or only allow male patients. But here you can put any gender in the room, but you cannot have this mixed gender in the same night. So for example, you can see here in this particular room has two beds in there. We can put a female patient in there. We can put another female patient in there. But now we have a male patient over here and you can see that the other patient is also male. So that's fine. As long as there is no overlap of a male and a female patient in the same room at the same night, then that's fine in these kinds of rooms. You could actually have rooms where you allow that. Most hospitals probably don't allow that. That depends on the settings of the hospitals, of course, and how you've implemented these constraints as a Java program or how you tailor them to your use case, of course. Now, each of these rooms also actually belongs to departments. So this is actually department one. In this data set, there are just number department two and so forth and so forth and department three. Now, one of the hard constraints that in certain departments, you have to be a certain age to be permitted in there. For example, you might need to be in some departments need to be 65 years or older in other departments. You need to be a minor to be able to or even a kid or even a baby to be able to enter there. And of course, we take these restrictions into account, these hard constraints into account. So that actually explains the hard constraints. So you can see right now, all of these hard constraints are actually met. We have a green score. We have zero hard constraints broken. And then, of course, we have the two other types here. Now, the second one is actually the medium constraints. That's actually the number of unassigned patients. I'll explain later in the video why this is important. But right now, let's just ignore it because this is a very easy data set. We have enough beds so we can assign all patients into a bed. And therefore, we don't this will always be zero, basically. And then the last one is the soft constraints. And there are a number of soft constraints here. One of them is that patients can actually prefer an equipment. So for example, you might want to have a room with a single bed. That's a typical that's a typical preference, right? Or you might want to have a room with a specific chair in there, or the ability for your spouse to sleep there, too. Now, the second kind is basically, for example, the extra bed. That's basically the same as the hard constraint, but then just waited at the soft constraint. But the other one, the single room thing is actually quite specific because if the hospital is able to give you that single room when you request it, the hospital can actually charge you more. So from the hospital's point of view, what they want to optimize is they want to make sure that all of the patients who request a single room actually also get a single room as that's better for their finances, right? And once that's done, they might actually still want to on top of that, optimize and putting so as many patients in single rooms as possible again, or maybe not. That's, of course, depending on how they envision their business constraints. In any case, we can handle those regardlessly. OK, so let's take a look here. Let's see why we are what is breaking here. So we have the preferred room maximum size. You can see most of the points. Let me just bring this on screen. Most of the points we 229 times we don't are we are not able to give them their single room. And so we're basically losing about 7000 points for that, right? The preferred equipment type. We're actually not being able to do that three times. And then also you have something called room special specialism. That basically means that if a specific room or actually the department is specialized, for example, in lung cancer, you really want to have the patients with lung cancers assigned into that room or into that department. And you can see we even have a we even miss one of those, right? OK, so let's see what happens when you start to optimize it because it's actually the initial solution. It's not that easy to find already. It's already found with a decent algorithm, but now we're going to use one of the the advanced algorithms in Optoplanar to optimize this further. So here we go and you can see that the score is actually going down. And you can see as it finds newer and better solutions, it is actually moving things around and you'll see that's happening on the screen too. So for example, you can see this patient moving around. Now, do note that we're only looking at a very small part of the screen, right? There are 40 nights in this data sets, but we do have up to about 500 rooms. So OK, it's not exactly 500 rooms. There are some gaps in it, but we do have a few, I think, 100, 200 rooms here. So it is not a serious data sets. This is actually the smallest data set. We have some bigger data sets to which you can show if needed. OK, let's take a look now at the constraints. So we can see we have we have we have better scores now. First of all, we don't have this. We don't break the specialism constraint anymore. So that's good to be the person with long cancer is actually now in the department that specializes with long cancer and so forth. We still have one type where we somebody asked, let's say, bed for a spouse and we weren't we weren't able to deliver. And we actually were able to bring down the number of single room requests we had to deny about with a with a few hundred cases. So that's actually a few hundred points, right? So that's actually a good thing, right? If you give it more time, you would probably find an even better solution. Now, do note that we cannot give all the patients that want a single room to actually give them a single room, as there are just too many patients asking for that, right? OK, now, I told you this is actually very similar to assign to assigning hotel rooms or assigning prison cells. Well, in hotel rooms, you basically have guests and you know when they'll arrive and when they leave and you have to sign them a room. So you don't have to actually have to sign them a bed. You just have to sign them a room. But again, you have similar constraints. You have, for example, the constraint that they paid for a basic room. So you have to give them at least a basic room. If they paid for a luxury room or a suite, you have to at least give them that kind of room. And of course, you need to make sure that if you give somebody the suite and this patient is staying several nights, that basically means that you might need to give that this is a long period that there is actually being blocked by that guest, not patient, of course, guest, of course, right? So hospital assigning hotel guests to rooms is very similar to this use case. And the same thing with actually assigning prisoners to prison cells. And in that case, you won't have to deal with a male female constraint, although you'll be assigning beds, not just cells, but actually beds. You don't want to have to deal with that case because all of the population in one prison is actually the same gender. But you will want to make sure that you have the prison runs as smoothly as possible, so you might want to take into account other constraints, such as, for example, the violence levels or the profiles or religion or things like that, which might or might make or might not make well in certain prison cells together. So these are all kinds of constraints. You can actually put into the system if you want to. You don't have to. And you can then actually make life better for hospitals, hotel guests, or in hotel guests, it's actually especially financially better, I guess, I guess, as well as for prison cells, where we can actually make life better of the prisoners, at least. And also probably better life for them is probably less violence in the prison, which is good for everybody working there, too. OK, now let's take a look at another data set. And this is, unfortunately, very relevant for prisons as well as for hospitals, is that there might be too many patients, there might be too many prisoners, right? And there might be too few beds, basically, for all to host all of these, right? So here we have a number of patients and we have to assign them. You have 2000 patients, but we actually have far too little beds. So what we're going to do right now is we're going to solve this. And what you'll see is, look here, we have our initial solution. And in our initial solution, you can see that a lot of the patients are actually assigned to beds, as you can see, right? But what you can also see is that in the same time, we have a number of patients which are still unassigned. And you can see these are typically the patients which require certain equipment to be there. And then that's basically their annoying part. Sometimes you actually do have some room in a bed, but we don't have the equipment in that room and we cannot schedule them, as that would break a hard constraint. So here we're saying, and this is, of course, defined by the use case, that we want to make sure that, first, all of the hard constraints are met. If we put a patient into a certain room, we want to make sure that the equipment in that room is there. We want to make sure we don't overbook our hospital. And then the second thing is what we'll do is, given those constraints, we want to still put as many patients into the beds as possible under those hard constraints. And that's why that's a medium constraint. Putting as many, and this is the number of, this one thousand three hundred and fifty-four is actually the number of unassigned patients. So we'll actually, as we roll by, we'll actually see by moving things around, we can actually put more patients into that bed, right? And then you'll see that, for example, now we've just added one extra patient into one of the beds by moving things around. OK, so this is the hospital bed planning example. If you want to implement this use case in Java, then definitely take a look at our website, optoplanner.org and try out this example. It's very simple. Just download the zip and start the examples. There's a shell script and a batch script to start those.