1 00:00:00,060 --> 00:00:05,970 For example, we want to solve a set of general kind of linear programming approach. 2 00:00:06,420 --> 00:00:15,390 So suppose we have an objective function, which is a summation of some X, let's say some over. 3 00:00:15,390 --> 00:00:26,790 I now see I multiply by exi subject to summation of a am I multiplied by X, I created an equal to B 4 00:00:26,790 --> 00:00:34,800 M and we have M constraints and I am decision variables. 5 00:00:34,810 --> 00:00:42,130 OK, so b m i a am I and C I r known parameters to the model. 6 00:00:42,390 --> 00:00:48,120 So in order to solve that, I want to give you an example, a simple one. 7 00:00:48,120 --> 00:00:56,460 Actually every two decision variables like X1 and X2 and also the coefficients of X are specified here, 8 00:00:56,550 --> 00:00:58,470 C seven and 12. 9 00:00:58,740 --> 00:01:09,000 These are the C one and C to see here and also A is a matrix specified here and here we are writing 10 00:01:09,000 --> 00:01:12,800 down each row of these multiplication. 11 00:01:13,110 --> 00:01:17,680 So three x one plus four x two greater than four. 12 00:01:17,730 --> 00:01:24,810 This is one row of it and the other will be two x one five x two bigger than two. 13 00:01:24,890 --> 00:01:32,370 OK, so since we want to write it down as a general model and if we increase the number of decision 14 00:01:32,370 --> 00:01:36,720 variables or the number of constraints that should be also working. 15 00:01:36,870 --> 00:01:41,790 So we decided to do it in the abstract kind of modelling. 16 00:01:41,870 --> 00:01:50,730 OK, so in order to do that, um, after we define the model as an abstract model, we need to specify 17 00:01:50,730 --> 00:01:51,730 the input data. 18 00:01:51,750 --> 00:02:01,380 So in order to do that, we have to create another file with that extension and then specify the sets 19 00:02:01,380 --> 00:02:05,370 and also the parameters of the model and so on. 20 00:02:05,400 --> 00:02:14,640 OK, so here you can see that C since it's defined over one and two, you can see here one and two, 21 00:02:15,880 --> 00:02:17,730 the value is seven and twelve. 22 00:02:18,030 --> 00:02:26,670 And also um the other parameter like B is defined overset M and one and two. 23 00:02:26,970 --> 00:02:30,790 You see here that one and two is here and four and two is here. 24 00:02:30,880 --> 00:02:35,700 OK, and also finally A is described here. 25 00:02:35,890 --> 00:02:40,620 OK, so let's have a look at the, um, code together. 26 00:02:41,620 --> 00:02:44,080 So it's here, let me show you. 27 00:02:44,380 --> 00:02:51,690 OK, so first of all, I, uh, imported the required, um, packages. 28 00:02:52,060 --> 00:02:56,800 OK, since we don't need any kind of plotting, I remove the and plot. 29 00:02:57,130 --> 00:02:57,610 Um. 30 00:03:00,050 --> 00:03:06,960 Importing and also I don't think I need the non-pay, so let's leave it right there. 31 00:03:06,980 --> 00:03:07,930 That's fine. 32 00:03:07,970 --> 00:03:10,050 If we need it, we can use it. 33 00:03:10,460 --> 00:03:17,870 OK, so we have two imports and then I have defined the abstract model and set in. 34 00:03:19,350 --> 00:03:25,790 And set em set and is telling us how many decision variables do we have, how many acts do we have? 35 00:03:25,800 --> 00:03:33,180 OK, and set em is telling us how many constraints do we have C, A, B are the coefficients of the 36 00:03:33,180 --> 00:03:33,570 model. 37 00:03:33,870 --> 00:03:37,450 OK, C is defined overset nt mm. 38 00:03:37,980 --> 00:03:44,910 A is defined or M an rn and B is defined over M and decision variable is defined. 39 00:03:44,910 --> 00:03:47,070 Overset np ok. 40 00:03:47,280 --> 00:03:52,290 And we are assuming that these are non-negative reales positive ones. 41 00:03:52,430 --> 00:03:59,490 OK, and um we have some constraints that needs to be created in order to do that. 42 00:03:59,490 --> 00:04:02,550 Uh we need to define model can't or. 43 00:04:02,610 --> 00:04:05,400 I just named it con you could name it something else. 44 00:04:05,400 --> 00:04:06,900 That's fine constraint. 45 00:04:07,230 --> 00:04:13,860 This constraint is defined Orvil model M it means for every constraints we have such some rules. 46 00:04:14,140 --> 00:04:16,440 OK, so how should we define that. 47 00:04:16,620 --> 00:04:27,930 This is the way we define define control um model and m and return summation of this expression model 48 00:04:27,960 --> 00:04:37,710 a M and I multiplied by I for every I in model nd bigger than equal to model b m. 49 00:04:38,520 --> 00:04:43,720 OK, so we are exactly repeating what we saw here. 50 00:04:43,770 --> 00:04:47,910 OK, so let's have a look at this, uh code again. 51 00:04:48,360 --> 00:04:51,720 You see, this is the concern that we have written here. 52 00:04:51,750 --> 00:04:53,570 OK, so let's continue. 53 00:04:53,610 --> 00:05:03,030 The objective function is the summation of see I multiply by X I for every I in sets model ln and the 54 00:05:03,030 --> 00:05:08,070 objective function and follows these specific rules that we have already defined. 55 00:05:08,400 --> 00:05:13,180 So that will follow the rule and the sense is the minimization. 56 00:05:13,890 --> 00:05:22,200 So if we look at the model structure, we see that it's a linear programming one, then we have to um, 57 00:05:23,880 --> 00:05:26,880 uh, define the solver we are going to use. 58 00:05:27,440 --> 00:05:35,790 OK, and so let's say opt is equal to solver factor like JLP user solver that can be used for linear 59 00:05:35,790 --> 00:05:36,450 programming. 60 00:05:37,050 --> 00:05:43,710 And um, in order to solve an abstract model, we have to create an instance. 61 00:05:44,010 --> 00:05:46,980 Instance will be created using this command. 62 00:05:47,130 --> 00:05:55,200 It is equal to model that create instance, um, using the data file that we have in the same routes 63 00:05:56,070 --> 00:05:59,700 and then we will ask Polynomial to solve the model for us. 64 00:06:00,050 --> 00:06:04,490 Results will be equal to opt uh that solve instance. 65 00:06:04,650 --> 00:06:13,170 So the model will be created and the data will be fed into the model and this line will solve the model 66 00:06:13,170 --> 00:06:13,510 for us. 67 00:06:13,530 --> 00:06:19,560 Let me, um, solve the model and, uh, see what is going on. 68 00:06:19,560 --> 00:06:27,570 OK, so after the solve is finished, the results are already in the results for every I in the instance 69 00:06:27,570 --> 00:06:31,640 don't and we will print the value of X. 70 00:06:31,650 --> 00:06:34,500 OK, so how should we define the value of X? 71 00:06:34,950 --> 00:06:44,790 We have to print the value of uh an instance that X I but um, we have to create a loop to set to tell 72 00:06:44,940 --> 00:06:49,820 uh Palomo to print every X that exists in the model. 73 00:06:49,830 --> 00:06:55,290 And finally um o F is equal to value of instance. 74 00:06:55,290 --> 00:07:04,800 Don't o f OK, so in order to have access to the uh sol values we have to use the command value instance. 75 00:07:04,800 --> 00:07:07,990 That's something that we want to see the value. 76 00:07:08,010 --> 00:07:15,780 OK, so let's run this one as well so you can see that the X1 is equal to one point thirty three. 77 00:07:16,050 --> 00:07:20,160 X2 is equal to zero, A.F. is equal to one point thirty three. 78 00:07:20,790 --> 00:07:28,350 OK, so and this is a very general kind of model for, um, solving the optimization problem. 79 00:07:29,040 --> 00:07:35,670 So you can see here, if we can, if we want to increase the, um, number of decision variables that 80 00:07:35,670 --> 00:07:37,080 can be easily done. 81 00:07:37,440 --> 00:07:43,020 Uh, if we increase the number of decision, uh, decision variables, then we have to change the number 82 00:07:43,020 --> 00:07:48,510 of NP not only is one and two, then we can have three, four, five and so on. 83 00:07:48,840 --> 00:07:54,420 And that model is a general format for, uh, solving any linear programming. 84 00:07:55,410 --> 00:07:56,220 Thank you very much.