1 00:00:01,410 --> 00:00:07,040 In this optimization problem, we are going to solve the problem of biggest rectangle inside a circle. 2 00:00:07,590 --> 00:00:16,830 So, um, we do have a rectangle with radius R and we want to find out what is the maximum area of a 3 00:00:16,830 --> 00:00:19,170 rectangle inside that circle. 4 00:00:19,830 --> 00:00:24,060 So in order to solve the problem, we have to formulate it mathematically. 5 00:00:25,150 --> 00:00:28,830 Now let's talk about how we can do this. 6 00:00:29,040 --> 00:00:35,930 Suppose this side of the big rectangle is X. This one is X, this one is Y, OK? 7 00:00:36,420 --> 00:00:43,590 And then the air the surface of that rectangle will become four times X multiplied by Y. 8 00:00:44,610 --> 00:00:48,120 And also we do have some other constraints that should be written. 9 00:00:48,870 --> 00:00:53,640 The X value is something between minus R and R. 10 00:00:54,160 --> 00:00:54,450 Hmm. 11 00:00:55,170 --> 00:01:01,420 And also Y and squared plus X squared is equal to our square. 12 00:01:02,420 --> 00:01:07,550 OK, now we want to find out how can we solve this problem. 13 00:01:52,140 --> 00:01:58,920 Hello, everybody, this lecture is going to be talking about the problem of biggest rectangle inside 14 00:01:58,920 --> 00:01:59,490 a circle. 15 00:01:59,940 --> 00:02:05,520 Suppose we have the following optimization problem and we want to formulate it as an optimization problem. 16 00:02:05,730 --> 00:02:11,400 We want to know what is the maximum area of a rectangle inside a circle. 17 00:02:12,030 --> 00:02:14,730 So suppose we do have this graph. 18 00:02:15,160 --> 00:02:22,660 We do have a circle with Radius R and we want to know how can we find a maximum area of that rectangle? 19 00:02:23,070 --> 00:02:31,190 This side is X, this side is Y, and now we want to find out what is the area of the whole rectangle. 20 00:02:31,200 --> 00:02:35,530 So it will be obviously four times one of these small rectangles. 21 00:02:35,530 --> 00:02:38,730 So four times X multiplied by Y. 22 00:02:39,060 --> 00:02:48,120 Obviously you can see on this graph X can move between zero and R at maximum and also Y is doing the 23 00:02:48,120 --> 00:02:48,660 same. 24 00:02:48,690 --> 00:02:56,460 It is moving from zero to R, then we do have a relation between X and R because they are all on the 25 00:02:57,240 --> 00:02:58,010 um. 26 00:02:59,170 --> 00:03:08,350 Circle, then X squared plus Y square is our square, and the other two constraints are given as follows. 27 00:03:08,770 --> 00:03:14,140 Um, X is between zero and Y is between zero and ah, OK. 28 00:03:14,410 --> 00:03:22,690 In order to solve it in Python, we need to define some, uh, input data and also some decision variables. 29 00:03:22,720 --> 00:03:26,710 Now you can imagine what are the decision variables here. 30 00:03:27,900 --> 00:03:36,920 So we have two decision variables, X and Y and also one objective function, which is called off here, 31 00:03:38,280 --> 00:03:44,610 then we need to find out how can you write down the equations describing the objective function? 32 00:03:44,610 --> 00:03:51,180 How can we define the decision variables and how should we define the limits of the variables and how 33 00:03:51,180 --> 00:03:52,520 can we finally solve it? 34 00:03:52,950 --> 00:03:58,570 So please refer to your Python code, as you can see in the attachment. 35 00:03:59,340 --> 00:04:02,190 Then let's solve this all together. 36 00:04:02,740 --> 00:04:08,880 OK, so here you can see that we have formulated the pro problem. 37 00:04:08,880 --> 00:04:14,160 And here in Palermo, let's start with the first stop. 38 00:04:14,160 --> 00:04:21,080 The code is written in Jupiter notebook and it can be easily run on your machine. 39 00:04:21,180 --> 00:04:25,230 It can be a MacBook or a Windows based kind of, um, machine. 40 00:04:25,680 --> 00:04:31,350 So first of all, we import plomo package using this. 41 00:04:31,350 --> 00:04:34,650 Um, come on from plomo. 42 00:04:34,650 --> 00:04:37,140 Don't environ import. 43 00:04:37,440 --> 00:04:38,370 Uh, Astrachan. 44 00:04:38,400 --> 00:04:39,660 It means import everything. 45 00:04:40,470 --> 00:04:41,850 So these are the comments. 46 00:04:42,780 --> 00:04:46,260 And to find out what's going on. 47 00:04:47,600 --> 00:04:53,420 OK, so these these are not going to change anything on your formulation, but just give you some hints 48 00:04:53,430 --> 00:04:54,090 what's happening. 49 00:04:54,590 --> 00:05:00,270 OK, so for this example, I'm going to use the concrete model. 50 00:05:01,320 --> 00:05:10,680 Then using the data that we have for this problem, I'm going to initialize it then, for example, 51 00:05:10,680 --> 00:05:18,430 are is a perimeter because we know the value of it initially and we initialise it with number 10. 52 00:05:18,570 --> 00:05:20,700 You can choose any other number that you want. 53 00:05:21,600 --> 00:05:24,750 And then X is a variable. 54 00:05:24,750 --> 00:05:31,630 So model that X is equal to where, um, bounds are specified here. 55 00:05:31,830 --> 00:05:38,220 It's moving between zero and model that are don't write down R because it doesn't recognize R, it only 56 00:05:38,220 --> 00:05:44,100 recognizes model that are which is already defined and we can initialize it with some value. 57 00:05:44,130 --> 00:05:52,890 I have chosen models that are as the initial value model dot and y variable again and the bounds are 58 00:05:52,890 --> 00:05:57,850 the same between zero and R and we have initialize that with models. 59 00:05:57,850 --> 00:06:02,070 Those are then are you do have a constraint. 60 00:06:02,070 --> 00:06:06,510 C One constraint is equal to constraint. 61 00:06:07,140 --> 00:06:15,190 Expression is and which is describing the model is equal to Model X and square. 62 00:06:15,210 --> 00:06:23,440 I've written this square in this way and also model that Y square is equal to model not R and square. 63 00:06:24,240 --> 00:06:32,280 And finally, the objective function is equal to expression four times Model X multiplied by Model Y 64 00:06:32,520 --> 00:06:37,160 and with a sense of maximization because we want to maximize the objective function. 65 00:06:37,500 --> 00:06:41,790 Then on the next top, let's broaden the tabs individually. 66 00:06:41,790 --> 00:06:44,260 The first top is drawn, ok? 67 00:06:44,280 --> 00:06:46,440 The second type is done. 68 00:06:46,440 --> 00:06:48,650 The same on the third top. 69 00:06:48,810 --> 00:06:53,000 I'm going to define the solver I'm going to use for solving the problem. 70 00:06:53,190 --> 00:06:57,120 Let's have a look at the shape of the optimization problem. 71 00:06:57,340 --> 00:07:01,530 It has a multiplication of X by Y and it becomes nonlinear. 72 00:07:01,540 --> 00:07:04,850 So I have to use a non-linear kind of solver. 73 00:07:05,220 --> 00:07:09,510 So for this purpose I have use EPOP solver is a specified here. 74 00:07:09,510 --> 00:07:15,190 Solver is equal to solve factory EPOP and the results is equal to solving that. 75 00:07:15,210 --> 00:07:19,020 Solve the name of the model B and I have chosen the model. 76 00:07:19,530 --> 00:07:27,020 You can't you could use any other kind of A naming and then let's run these top. 77 00:07:27,040 --> 00:07:35,190 So this tab is already drawn and then the simulation is finished and I do have the values for the X 78 00:07:35,190 --> 00:07:42,810 and Y, so if I run it again, you can see the values of X and Y equal to each other equal to seven 79 00:07:42,810 --> 00:07:47,970 point zero seven one and the amount of objective function is two hundred. 80 00:07:49,140 --> 00:07:54,000 And also I can get some other results from the simulation. 81 00:07:54,000 --> 00:08:00,810 If I run this, I can get some other results and I can fix one of the variables. 82 00:08:00,810 --> 00:08:07,560 For example, I can fix and one of the variables like X equal to something which is one here which can 83 00:08:07,560 --> 00:08:08,460 happen for you. 84 00:08:08,910 --> 00:08:14,580 And for example, you want to have a fixed variable in your model and you already know the value so 85 00:08:14,580 --> 00:08:18,240 you can fix it and solve the rest of the problem. 86 00:08:18,240 --> 00:08:22,050 So with X equal to one, Y becomes something else. 87 00:08:22,200 --> 00:08:24,880 An objective function is something else. 88 00:08:24,990 --> 00:08:31,050 So by comparing these to a simulation, you can see by manipulating the decision variables, you are 89 00:08:31,500 --> 00:08:34,740 you are getting them far away from the optimal value they can get. 90 00:08:34,920 --> 00:08:40,080 Some of the optimum value for X and Y are equal to each other, equal to seven point zero seven one. 91 00:08:40,080 --> 00:08:46,470 But if you change that and fixed some of them, the results become something else. 92 00:08:46,680 --> 00:08:54,090 OK, so, um, for in order to on fix the decision valuable and fixed something else, you can use this 93 00:08:54,090 --> 00:08:57,840 command model that x that on fix. 94 00:08:58,170 --> 00:09:04,980 It means that the variable X is no longer a fixed value and you can fix something else or you can, 95 00:09:05,730 --> 00:09:14,210 you can do nothing, OK, and then solve it again and you can see the results here. 96 00:09:14,460 --> 00:09:18,490 This time Y is equal to one and X is something else, OK? 97 00:09:18,570 --> 00:09:20,700 And the objective function is found. 98 00:09:20,700 --> 00:09:27,330 You can fix everything OK and then solve the problem again and see the results. 99 00:09:27,630 --> 00:09:32,610 OK, so here you can see that there are some um, useful information regarding the model. 100 00:09:32,610 --> 00:09:38,160 You have solved the number of constraints, the number of variables, the objective function, the balance 101 00:09:38,160 --> 00:09:39,480 for everything is found. 102 00:09:39,660 --> 00:09:46,850 And also it tells you that the solver has been successful in finding the optimal solution or not. 103 00:09:46,860 --> 00:09:51,870 OK, so you can expand this model to any other application if you want. 104 00:09:52,290 --> 00:09:55,500 And that's it for this session.