1 00:00:01,230 --> 00:00:10,050 OK, this example is called the maximum flow, and we want to find out if how much is the maximum flow 2 00:00:10,050 --> 00:00:14,340 we can have between two specific notes in a graph. 3 00:00:14,830 --> 00:00:26,340 For example, if the amount of product or power or whatever is entering the node zero, um, and we 4 00:00:26,340 --> 00:00:29,970 are expecting that there is no loss as is happening in the system. 5 00:00:30,890 --> 00:00:35,760 I repeat, is not an electrical engineering kind of system, but it's a general form. 6 00:00:36,210 --> 00:00:46,260 And we want to know if we enter G to the node zero, is it possible to take out G from Node six or any 7 00:00:46,260 --> 00:00:47,040 other node? 8 00:00:48,290 --> 00:00:52,900 Without violating the capacity of these lines or these routes. 9 00:00:53,300 --> 00:00:59,520 OK, so in order to do so, we have to write down the balanced equation for every node. 10 00:00:59,900 --> 00:01:06,240 So as you can see, only one node has generation, which is not zero. 11 00:01:06,380 --> 00:01:11,470 For example, in this example, and the rest of them has to have them. 12 00:01:11,750 --> 00:01:13,520 They have no generation. 13 00:01:13,730 --> 00:01:20,480 But and I know demand and also only one node has demand, which is node six. 14 00:01:20,930 --> 00:01:23,020 OK, so and it's equal to G. 15 00:01:24,380 --> 00:01:34,160 So we want to know, um, how can we, uh, formulate it as a, um, optimization problem in Payam? 16 00:01:34,430 --> 00:01:39,110 OK, so here you can see that we import the required packages. 17 00:01:39,440 --> 00:01:39,670 Hmm. 18 00:01:40,010 --> 00:01:43,460 And then I create the model abstract model and. 19 00:01:44,990 --> 00:01:47,270 So this is the set. 20 00:01:48,770 --> 00:01:55,880 It is initialized with the range between zero and seven, so it will create a zero one, two, three, 21 00:01:55,880 --> 00:02:00,290 four, five and six G is the radius of that. 22 00:02:01,420 --> 00:02:05,690 Flo is telling us how much flow is happening between I and J. 23 00:02:05,950 --> 00:02:12,580 It's a positive number and also the capacity of each route is also specified by parameter ACAP. 24 00:02:13,990 --> 00:02:18,340 She is a valuable telling us how much we can inject. 25 00:02:19,610 --> 00:02:27,140 To one note, an extract from the other note, an objective function is, um, defined as G OK. 26 00:02:28,430 --> 00:02:29,900 So, uh. 27 00:02:31,140 --> 00:02:35,730 Here, let me continue, um. 28 00:02:36,630 --> 00:02:41,020 So I have to write down the balanced equation for every note. 29 00:02:41,040 --> 00:02:45,410 So the first note, which has generation, is written this way. 30 00:02:46,200 --> 00:02:48,300 So if I zero this is this way. 31 00:02:48,720 --> 00:02:53,220 And if it's the receiving point, this is written this way. 32 00:02:54,060 --> 00:03:01,290 But if it's none of any of those two types, then the there is no generation, no load. 33 00:03:02,760 --> 00:03:05,580 And that's the concern for every node. 34 00:03:06,790 --> 00:03:11,050 And also, the flow should be always less than the capacity. 35 00:03:12,870 --> 00:03:17,730 And the constraint is the final I think the rule is key to. 36 00:03:18,640 --> 00:03:22,840 And the objective function is expression, uh, model. 37 00:03:23,260 --> 00:03:29,290 So this way you can see that I don't need to define an extra variable called off. 38 00:03:29,360 --> 00:03:37,690 OK, does it give me anything else so I can remove it for simplicity and I choose the solver as the 39 00:03:37,710 --> 00:03:38,320 GOP. 40 00:03:38,350 --> 00:03:46,930 OK, so the the unknown, uh, I haven't discussed it so far is the capacity. 41 00:03:47,350 --> 00:03:50,190 So the capacity should be specified in the data file. 42 00:03:51,010 --> 00:03:52,320 So you can see it here. 43 00:03:52,780 --> 00:03:58,270 Um, it's a kind of table specifying how much is the capacity between each pair of nodes. 44 00:03:58,780 --> 00:04:04,930 And you can see that in this specific example, uh, it's not symmetrical. 45 00:04:04,930 --> 00:04:12,000 So the capacity between two and one is ten, but between one and two is zero. 46 00:04:12,010 --> 00:04:14,050 So it's a direct kind of graph. 47 00:04:14,620 --> 00:04:18,250 OK, um, you can change the numbers if you want. 48 00:04:19,590 --> 00:04:28,350 And see the impact, so, uh, it will read that, uh, data file and put it into the, uh, payable 49 00:04:28,860 --> 00:04:30,840 and assets to solve it. 50 00:04:30,870 --> 00:04:31,310 OK. 51 00:04:32,520 --> 00:04:44,370 And so you can see here that the eye can plot the results and show you what's happening, so ironic. 52 00:04:45,570 --> 00:04:49,980 And I explain what's happening at each stage. 53 00:04:50,010 --> 00:04:54,930 OK, so the model is solved here and the data is given here. 54 00:04:54,960 --> 00:04:58,560 So I want to plot that graph. 55 00:04:58,560 --> 00:05:06,360 So I put a circle and connect the connected points and the capacities are somehow graphically shown 56 00:05:06,360 --> 00:05:06,720 here. 57 00:05:07,110 --> 00:05:13,500 The roots with higher capacity are a bit thicker kind of lines. 58 00:05:15,140 --> 00:05:22,040 Uh, and also, you can see the objective function is seven, OK, so this is the maximum amount of 59 00:05:22,040 --> 00:05:26,840 energy that is, uh, capable of passing from zero to six. 60 00:05:26,990 --> 00:05:33,160 And there are some, uh, useful information regarding the, um, solid example. 61 00:05:33,430 --> 00:05:41,180 So just have a look at the, uh, this instance that display we want to find out if or modeling approach 62 00:05:41,180 --> 00:05:44,090 is efficient or not. 63 00:05:44,420 --> 00:05:46,340 OK, so, um. 64 00:05:47,250 --> 00:05:50,680 OK, so how much is the maximum capacity? 65 00:05:50,700 --> 00:05:54,270 It's, um, it was ten in the data to fight. 66 00:05:54,300 --> 00:06:01,830 OK, so we could also specify before I explain that, I just have a look at the variable. 67 00:06:01,830 --> 00:06:03,030 The variable is flow. 68 00:06:04,560 --> 00:06:12,970 Flo Gee, and, uh, what else, um, objective, objective function is something else. 69 00:06:12,990 --> 00:06:17,730 OK, so there are two main variables G and, uh, flow. 70 00:06:18,680 --> 00:06:22,670 So just have a look at the, uh, status of each variable. 71 00:06:23,000 --> 00:06:23,430 OK. 72 00:06:23,960 --> 00:06:28,930 So as you can see here that we have a variable called zero and zero. 73 00:06:29,270 --> 00:06:38,420 It means that the flow between nodes zero and node zero, which is not going to be true because I don't 74 00:06:38,420 --> 00:06:40,280 need that kind of variable in my model. 75 00:06:40,520 --> 00:06:43,180 OK, so why is it created? 76 00:06:43,190 --> 00:06:45,630 Let's have a look at the model the way I wrote it. 77 00:06:46,040 --> 00:06:54,680 So here you can see that I have a condition that I should be, um, different with is the same here. 78 00:06:54,710 --> 00:06:57,670 So this constraint is not creating a problem for me. 79 00:06:58,040 --> 00:06:58,970 This is the one. 80 00:06:59,140 --> 00:07:05,000 OK, so because I am defining it for every pair of, uh, i n j. 81 00:07:06,060 --> 00:07:14,550 For a small problems, um, it doesn't create that much hassle, but, uh, for larger kind of, uh, 82 00:07:14,580 --> 00:07:17,800 programming, it should be definitely avoided. 83 00:07:17,820 --> 00:07:21,320 So, uh, let's put a condition here. 84 00:07:21,350 --> 00:07:33,120 Let's say if I is not equal to Jay, then return this or else return 85 00:07:34,950 --> 00:07:36,650 counseling's. 86 00:07:37,840 --> 00:07:39,260 Dogs screamed. 87 00:07:40,790 --> 00:07:44,600 OK, so if I run the code again. 88 00:07:48,310 --> 00:07:52,540 Oh, I hope I, um, avoid that, um. 89 00:07:54,490 --> 00:07:55,420 What happened? 90 00:08:02,010 --> 00:08:07,660 OK, OK, so the problem is solved, but here, let me check. 91 00:08:07,680 --> 00:08:14,410 So there is no combination of zero and zero and, um, one on one and so on and so on. 92 00:08:14,430 --> 00:08:23,530 OK, so, um, in order to check what is happening here, I have to see, um, this line. 93 00:08:23,590 --> 00:08:25,460 OK, so let's have a look. 94 00:08:27,050 --> 00:08:27,620 And. 95 00:08:28,490 --> 00:08:29,120 Mm hmm. 96 00:08:29,360 --> 00:08:38,240 So it is telling me that it is trying to access one specific, um, components of air flow, which doesn't 97 00:08:38,240 --> 00:08:46,400 exist, it can be understandable because and now, um, let me, um. 98 00:08:48,670 --> 00:08:49,700 To this in this way. 99 00:08:49,760 --> 00:09:02,800 OK, so I put it here, it is bigger than the plot. 100 00:09:03,030 --> 00:09:03,490 OK. 101 00:09:03,610 --> 00:09:05,680 I hope this time it resolved the problem. 102 00:09:05,710 --> 00:09:05,970 Yeah. 103 00:09:06,640 --> 00:09:12,250 A good and one the last tab and see the results. 104 00:09:12,250 --> 00:09:17,260 So you can see here that um yeah. 105 00:09:17,560 --> 00:09:19,150 It doesn't exist in the model. 106 00:09:19,150 --> 00:09:22,050 The stall is uh now true. 107 00:09:22,060 --> 00:09:24,100 It means that it doesn't um. 108 00:09:25,170 --> 00:09:27,170 It's not included in the wall. 109 00:09:27,220 --> 00:09:27,590 OK. 110 00:09:30,190 --> 00:09:38,200 And and it doesn't have any value, as you can see here, and also there is another point that can be 111 00:09:38,200 --> 00:09:43,130 considered, and it's the fact that there is no upper bound for the flow. 112 00:09:43,420 --> 00:09:52,060 OK, so it's not so it's always, as I said before, and it's always good to have a bound for your valuables. 113 00:09:53,500 --> 00:09:58,890 So I even if it's not very tight, but at least it's something like that. 114 00:09:59,710 --> 00:10:07,330 So if I run the code again and, um, let's run all the tabs and see the results. 115 00:10:10,310 --> 00:10:17,480 OK, so as you can see here, the upper bound of the valuable flow is now determined. 116 00:10:17,840 --> 00:10:24,950 OK, so, um, these are the steps that you can follow to improve the way you.