1 00:00:00,240 --> 00:00:10,140 OK, this lecture is referring to calculational sensor of mass, for example, suppose we want you formulated 2 00:00:10,140 --> 00:00:15,910 as a as an optimization problem and the input data of the problem is as follows. 3 00:00:16,260 --> 00:00:24,330 So, um, we want to find out the center of mass of a given set of objects which their location and 4 00:00:24,330 --> 00:00:26,250 their mass are known. 5 00:00:27,030 --> 00:00:32,640 And we want to find out what is the X and Y coordinates of the center of mass. 6 00:00:32,670 --> 00:00:39,390 OK, so based on the formula, we know that the X of the center of mass is calculated using this Formula 7 00:00:39,630 --> 00:00:43,980 X multiplied by the mass of an object. 8 00:00:43,980 --> 00:00:50,580 I do the summation of our eye divided by, um, summation of all masses. 9 00:00:51,060 --> 00:00:55,930 The same formula is for uh, applies for the, uh, y coordinate. 10 00:00:55,960 --> 00:00:58,950 OK, so let's have a look at the. 11 00:01:00,970 --> 00:01:02,740 Python code for this purpose. 12 00:01:02,770 --> 00:01:11,320 OK, so you can see here that, um, at the beginning, as usual, we have to import all the required 13 00:01:11,320 --> 00:01:12,460 packages here. 14 00:01:12,480 --> 00:01:17,440 We do need to import Puyo Modot environment, uh, import everything. 15 00:01:17,740 --> 00:01:23,950 Import Mathlouthi that's pipelined as pretty important vampi as ENPI and import random. 16 00:01:24,400 --> 00:01:31,780 OK, um, we define an abstract model, uh and is representing the number of objects. 17 00:01:32,170 --> 00:01:38,800 I specify the default value equal to 15, but you can easily change that in order to be able to change 18 00:01:38,800 --> 00:01:39,220 that. 19 00:01:39,220 --> 00:01:46,240 You can define defined as immutable parameter and then you have to define the set set of objects. 20 00:01:47,850 --> 00:01:56,940 Um, if you need, uh, the, um, the location and also the masses of the objects can be specified 21 00:01:56,940 --> 00:01:58,440 as the input parameters. 22 00:01:58,480 --> 00:02:03,500 OK, but, um, you can define them as some random numbers. 23 00:02:04,890 --> 00:02:09,510 So, um, you do need to, uh, specify them. 24 00:02:09,510 --> 00:02:18,180 So X location, Y location, um, are the locations of the objects and the mass is already, uh, specify 25 00:02:18,180 --> 00:02:25,830 the mass of each object and you initialize these parameters using the defined, uh, function so the 26 00:02:25,830 --> 00:02:36,360 interval function will give random coordinates to X and Y and also the uh interval M is, um, giving 27 00:02:36,360 --> 00:02:42,930 you some random masses to your objects, but you can also specify them in a file or something like that. 28 00:02:44,010 --> 00:02:50,240 And also there are two decision variables, X and Y, the center of mass of the overall objects. 29 00:02:50,820 --> 00:03:01,560 And since we are trying to find them in, um, uh, since we already specified, uh, X and Y locations 30 00:03:01,560 --> 00:03:07,230 between zero and one, then the center of mass will be somewhere between zero and one. 31 00:03:07,260 --> 00:03:15,480 OK, so I define them as valuable non-negative negative ones and I initialized the X and Y and using 32 00:03:15,480 --> 00:03:16,170 this formula. 33 00:03:16,530 --> 00:03:19,430 So initialize some uh, some constants. 34 00:03:19,440 --> 00:03:24,030 OK, and then uh, we do need to write down two constraints. 35 00:03:24,030 --> 00:03:32,160 One for X, one for Y, X is calculated using this formula, it's equal to and summation of X location 36 00:03:32,160 --> 00:03:37,570 multiplied by their mass through the summation over the all the eyes in model and model. 37 00:03:37,770 --> 00:03:42,030 I divide it by uh sum of all masses in the system. 38 00:03:43,200 --> 00:03:52,560 The same concept holds for Y and uh, you have to define some constraint for that to be calculated. 39 00:03:53,220 --> 00:03:58,830 Um, then, um, the objective function is the important part here. 40 00:03:58,850 --> 00:04:07,050 So um, actually in this problem we don't have any specific objective function, we just have some constraints 41 00:04:07,050 --> 00:04:08,760 that should be satisfied. 42 00:04:09,120 --> 00:04:16,620 So you can simply specify X or Y as your objective function and you specify the sense as maximization 43 00:04:16,620 --> 00:04:17,880 or minimization. 44 00:04:18,330 --> 00:04:22,950 It doesn't matter because you want to. 45 00:04:22,950 --> 00:04:25,560 And there is only one unique solution for that. 46 00:04:25,650 --> 00:04:29,100 Uh, and there's nothing to maximize or optimize. 47 00:04:29,550 --> 00:04:35,880 OK, so then you will have to, um, use some solver. 48 00:04:36,090 --> 00:04:41,490 So since it's a linear programming, it's better to use pick as the solver. 49 00:04:42,240 --> 00:04:48,630 And then and initially I have to specify the default value of the objects. 50 00:04:48,810 --> 00:04:53,670 The number of objects is 15, but you can definitely change that. 51 00:04:54,090 --> 00:04:57,080 You can say it's five or seven or anything at all. 52 00:04:57,090 --> 00:05:04,270 You can leave it as it is it equal to fifteen and then ask, uh, more to solve it for you. 53 00:05:04,470 --> 00:05:06,120 And finally, you can plot the results. 54 00:05:06,120 --> 00:05:10,480 So let's run the code one by one tab. 55 00:05:10,540 --> 00:05:15,360 OK, this one is run successfully, but this one. 56 00:05:16,080 --> 00:05:16,600 Mm hmm. 57 00:05:16,650 --> 00:05:20,480 This is also done, uh, the final one. 58 00:05:20,490 --> 00:05:27,300 So you can see here that, uh, the there are five objects, um, randomly generated here. 59 00:05:27,300 --> 00:05:27,420 Uh. 60 00:05:29,530 --> 00:05:30,850 So, um. 61 00:05:32,450 --> 00:05:38,990 You can see them here, and if I change the numbers, let's say it's, um, six. 62 00:05:39,020 --> 00:05:41,900 OK, so I run this model again. 63 00:05:42,200 --> 00:05:44,030 I calculated. 64 00:05:55,740 --> 00:05:58,210 So there are six objects here. 65 00:05:58,230 --> 00:05:59,610 One of them is very small. 66 00:06:01,500 --> 00:06:07,650 So, um, let's hear one of them is here, here, here, here, here and here. 67 00:06:07,680 --> 00:06:13,500 OK, so for six objects, the location of Center of Mass is found. 68 00:06:13,680 --> 00:06:17,160 You can also print their values. 69 00:06:17,370 --> 00:06:20,220 So XLF Center of Mass is. 70 00:06:22,010 --> 00:06:26,820 I found, um, using the formula, so it's here, actually. 71 00:06:27,060 --> 00:06:27,280 Hmm. 72 00:06:27,920 --> 00:06:31,190 So, uh, this is the value of the center of mass. 73 00:06:31,220 --> 00:06:33,530 You can also print it if you want. 74 00:06:34,340 --> 00:06:37,800 Uh, and this is the this is it for this example. 75 00:06:37,820 --> 00:06:38,660 Thank you very much.