1 00:00:01,470 --> 00:00:11,100 This example is, um, let's name the paper company, so suppose we have that black paper and let's 2 00:00:11,100 --> 00:00:22,530 assume the lens of these big paper is one meter and we want to create, um, and we want to cut these 3 00:00:22,530 --> 00:00:25,050 big paper into a smaller, smaller pieces. 4 00:00:25,560 --> 00:00:27,840 And you can see these are the requirements. 5 00:00:27,840 --> 00:00:40,300 So, uh, piece X has a weight of five and P's, um, Y has rates of seven pieces that it has and the 6 00:00:40,340 --> 00:00:45,300 width of um nine and they have the same length of the black one. 7 00:00:45,450 --> 00:00:52,320 OK, so the question is, how should I, uh, cut the paper in order to minimize the number of big papers 8 00:00:52,320 --> 00:00:53,220 I have to use. 9 00:00:53,730 --> 00:00:55,470 For example, let me give you an example. 10 00:00:56,640 --> 00:01:06,440 If I want to, uh, cut this paper into, uh, and create some X, uh, piece, it means that each paper 11 00:01:06,450 --> 00:01:10,000 can give me four pieces of, uh, X. 12 00:01:10,530 --> 00:01:10,920 Yeah. 13 00:01:11,310 --> 00:01:18,240 And also it can give me two pieces of these red ones or two of these yellow ones. 14 00:01:18,290 --> 00:01:21,570 OK, and there are some, uh, parts are lost. 15 00:01:21,810 --> 00:01:22,250 Yeah. 16 00:01:23,730 --> 00:01:31,110 So how should I do that in a way that the amount, the number of big papers that I'm using is minimized. 17 00:01:31,140 --> 00:01:31,590 OK. 18 00:01:32,690 --> 00:01:39,290 So, um, definitely I have to choose the binary variables. 19 00:01:39,800 --> 00:01:40,880 OK, so. 20 00:01:41,940 --> 00:01:51,150 I want to know, and for each piece of paper, let's call it, I, um, how many eggs I can extract, 21 00:01:51,150 --> 00:01:57,810 how many women I can extract, how many that I can extract, for example, one X, one Y, which will 22 00:01:57,810 --> 00:01:58,650 be twelve. 23 00:01:59,100 --> 00:02:05,980 I can't do any more, um, Z because then the bits of the paper is not big enough. 24 00:02:06,000 --> 00:02:06,450 OK. 25 00:02:07,020 --> 00:02:08,340 Or what else I could do. 26 00:02:08,340 --> 00:02:12,330 I could say five and two pieces of read. 27 00:02:12,600 --> 00:02:13,910 It will be nineteen. 28 00:02:14,220 --> 00:02:15,490 Yeah it's less than twenty. 29 00:02:15,540 --> 00:02:20,550 OK, so five X plus seven Y plus nine Z. 30 00:02:20,550 --> 00:02:25,470 I should be less than um you I yeah. 31 00:02:26,010 --> 00:02:29,430 So um it's better to write it down. 32 00:02:29,430 --> 00:02:29,880 It's. 33 00:02:58,540 --> 00:03:05,530 OK, this example is called the paper company, suppose a paper company should cut its raw papers, 34 00:03:05,920 --> 00:03:09,640 which you can see them as the black and big papers. 35 00:03:10,560 --> 00:03:20,390 Uh, into the color ones and the size of each color paper is known and also the black one as well, 36 00:03:20,700 --> 00:03:28,830 and I want to know, um, how should we optimally cut these big black papers into the color ones? 37 00:03:28,910 --> 00:03:31,080 OK, so let me give you an example. 38 00:03:31,080 --> 00:03:32,850 If I only need the. 39 00:03:33,630 --> 00:03:43,800 Um, x kind of size, it means that each black paper can give me four of these, um, green ones or 40 00:03:43,800 --> 00:03:48,680 two of these, uh, red ones or one green and two red. 41 00:03:49,200 --> 00:03:49,620 Yeah. 42 00:03:49,950 --> 00:03:51,310 Or two yellow ones. 43 00:03:51,360 --> 00:03:56,460 OK, so the weights of the paper should be always, um, taken into account. 44 00:03:57,300 --> 00:04:05,790 So we want to minimize the number of big papers I'm going to cut and for each given paper how many X 45 00:04:05,790 --> 00:04:08,030 and Y and Z I can extract. 46 00:04:08,430 --> 00:04:21,480 So uh five X plus seven Y plus nine Z, less than uh twenty yuan and, and X and Y and Z are telling 47 00:04:21,480 --> 00:04:26,070 me the required number of each uh piece. 48 00:04:26,100 --> 00:04:26,610 OK. 49 00:04:28,080 --> 00:04:32,080 As you can guess, I have to define them as binary variables. 50 00:04:32,100 --> 00:04:36,290 OK, so let me show you the code. 51 00:04:36,630 --> 00:04:40,830 So here I import the required packages I defined as a concrete model. 52 00:04:41,400 --> 00:04:53,760 And also you can see here that you is a binary variable and X and, um, Y and Z are, let's say, um, 53 00:04:54,480 --> 00:05:00,150 um, integer and non-negative integer variables. 54 00:05:00,210 --> 00:05:11,280 OK, so, um, first rule five X plus seven Y plus nine Z, less than equal to twenty you Y. 55 00:05:11,970 --> 00:05:17,490 And the next rule is specify how many of X is required. 56 00:05:17,700 --> 00:05:24,390 So let's assume that an X is ten and Y is 12 and Z is five. 57 00:05:24,420 --> 00:05:25,710 You could define them as. 58 00:05:26,990 --> 00:05:33,770 Some parameters, it would be much, much better and professional, but that's fine and the objective 59 00:05:33,770 --> 00:05:43,970 function is summation of I multiplied by you, I, I could uh, amidst I multiplication here, but I 60 00:05:43,970 --> 00:05:46,000 will show you why I put it here. 61 00:05:46,580 --> 00:05:50,360 And also the, um, solver. 62 00:05:50,360 --> 00:05:57,590 I'm going to use this because it's linear programming and the results are found here and everything 63 00:05:57,590 --> 00:05:59,130 is calculated here. 64 00:05:59,150 --> 00:06:05,770 So for example, by this answer I know that there are ten big papers are needed. 65 00:06:06,110 --> 00:06:11,890 The first one is giving me one X and to Y, the second one the same. 66 00:06:12,230 --> 00:06:18,260 The third one is only using three for X and so on and so on. 67 00:06:18,290 --> 00:06:22,570 OK, um, let me run the code from the beginning. 68 00:06:24,920 --> 00:06:26,720 I show you the results again. 69 00:06:35,800 --> 00:06:37,750 OK, this party is executed. 70 00:06:38,680 --> 00:06:43,330 Now the program is running the optimization part. 71 00:06:47,900 --> 00:06:55,820 But one question is here that, um, how many big papers I should consider for my optimization, because 72 00:06:55,970 --> 00:06:59,740 initially before solving the problem, I don't know how many papers are needed. 73 00:06:59,750 --> 00:07:04,640 So I define, um, a big number at the beginning. 74 00:07:04,670 --> 00:07:12,380 OK, so how can I determined that by looking at the number of required, um, X, Y and Z I can say. 75 00:07:12,920 --> 00:07:14,840 And this is the maximum number of. 76 00:07:16,260 --> 00:07:19,080 And big papers that might be needed. 77 00:07:19,360 --> 00:07:26,580 OK, so, um, so at the end, I know that 10 papers are needed. 78 00:07:26,700 --> 00:07:31,350 So let me check something else for you before I finish this example. 79 00:07:32,070 --> 00:07:35,490 Before I remove this multiplication, what's will happen? 80 00:07:35,670 --> 00:07:36,420 Guess what? 81 00:07:37,110 --> 00:07:39,770 So I run it from the beginning. 82 00:07:47,770 --> 00:07:51,290 So I'm waiting for the solver to finish the job. 83 00:08:12,410 --> 00:08:18,560 So I just slightly modified the, um, objective function. 84 00:08:26,180 --> 00:08:28,080 And I'm waiting for the soldier to finish. 85 00:08:28,100 --> 00:08:30,090 OK, so have a look at the results. 86 00:08:30,590 --> 00:08:36,440 This is exactly what I wanted to show you so you can see that is one three five seven, eight, nine, 87 00:08:36,440 --> 00:08:38,690 10, 13, 14 and 15. 88 00:08:39,540 --> 00:08:47,300 OK, so, um, the objective function is telling me there are 10 pages are needed exactly the same as 89 00:08:47,300 --> 00:08:47,750 before. 90 00:08:48,080 --> 00:08:55,030 But, um, it doesn't matter for the Solver that each page is being chosen. 91 00:08:55,040 --> 00:08:59,680 So the page with a higher rank or lower rank. 92 00:08:59,960 --> 00:09:02,300 I mean and they are not sequential. 93 00:09:02,630 --> 00:09:07,550 You can see here one three five seven 15. 94 00:09:07,760 --> 00:09:08,200 You see. 95 00:09:08,360 --> 00:09:16,960 So but if you multiply it by I, it will give you a more kind of clean, um, solution. 96 00:09:17,750 --> 00:09:19,760 OK, thank you very much.