1 00:00:01,110 --> 00:00:06,660 OK, in this example, we are going to solve a very fun and optimization problem. 2 00:00:06,690 --> 00:00:11,400 Suppose you are going to play the game called Clash of Clans. 3 00:00:11,910 --> 00:00:18,320 So in this game, you have to train your troops to fight against other clans, OK? 4 00:00:18,720 --> 00:00:25,340 And each of your, let's say soldiers have different characteristics. 5 00:00:25,800 --> 00:00:32,520 They have maximum different maximum heat pumps and heat points or. 6 00:00:38,780 --> 00:00:47,390 This example is referring to the clash of clans game, and we are going to unmowed as a linear kind 7 00:00:47,390 --> 00:00:58,730 of programming, um, if you are familiar with this game and you do have different groups and each of 8 00:00:58,730 --> 00:01:05,780 them has different characteristics, the amount of heat points you can tolerate, amount of damage it 9 00:01:05,780 --> 00:01:12,320 can cause, and the training time is different for every, um, single troop. 10 00:01:13,260 --> 00:01:23,070 And sometimes you want to attack your enemies and you want to have maximum hit points, you or you might 11 00:01:23,070 --> 00:01:30,510 want to maximize the attacking capabilities and you want to do it at the minimum training time. 12 00:01:30,750 --> 00:01:32,870 OK, so, uh. 13 00:01:33,920 --> 00:01:42,560 Depending on how much you want and to tolerate damage or how much damage you can cause or how long does 14 00:01:42,560 --> 00:01:49,190 it take to train your troop, or how much cost does it create to train your troop? 15 00:01:49,400 --> 00:01:53,810 And your strategy for training the troops is different. 16 00:01:53,990 --> 00:02:00,040 So, as I said, depending on your troop and they have different requirements and different costs, 17 00:02:00,380 --> 00:02:05,690 so some of them take more time to train and they use more. 18 00:02:05,740 --> 00:02:08,480 And Axia, OK. 19 00:02:08,810 --> 00:02:18,680 And, um, so in order to find out the best strategy to train your troops, uh, you can create an optimization 20 00:02:18,680 --> 00:02:20,360 problem and solve it for yourself. 21 00:02:20,390 --> 00:02:26,840 So, as I said, there are multiple number of troops that you can train and, uh, each of them has 22 00:02:27,140 --> 00:02:28,690 its own characteristics. 23 00:02:28,970 --> 00:02:38,780 So, uh, in order to do that, um, the attack capabilities of each troop is stored in a parameter 24 00:02:38,780 --> 00:02:42,320 called the tank or heat or time of training. 25 00:02:42,320 --> 00:02:47,790 And EXI is telling Gown's how many of each troop you are going to choose. 26 00:02:47,990 --> 00:02:54,770 So obviously you have to choose and the integer kind of variables to model that properly. 27 00:02:54,920 --> 00:02:57,950 And also the housing of the camps are limited. 28 00:02:58,280 --> 00:03:07,340 So multiply by housing summation is should be less than the camp capacity and also, uh, based on the 29 00:03:08,120 --> 00:03:13,190 availability of Lexia and your training costs should be limited. 30 00:03:13,310 --> 00:03:23,240 OK, so, um, for solving this model, you do need to have the, um, different characteristics associated 31 00:03:23,240 --> 00:03:24,110 with, um. 32 00:03:25,400 --> 00:03:34,580 Each troop, for example, in this, that's fine, um, you can see that different troops here, you 33 00:03:34,580 --> 00:03:41,300 can see them here have different characteristics housing, space and damage they can create. 34 00:03:41,300 --> 00:03:48,140 Training cast in using Red Lexia or dark lexia is different. 35 00:03:48,230 --> 00:03:52,400 The amount of heat point they can tolerate is different training. 36 00:03:52,400 --> 00:03:54,200 Time is different for all of them. 37 00:03:54,470 --> 00:03:58,910 And the capacity of your camp should be specified here. 38 00:03:58,910 --> 00:04:06,680 And the availability of your red or dark elixir is also specified in this python code. 39 00:04:06,710 --> 00:04:11,810 OK, so let's have a look at the Python code itself. 40 00:04:12,230 --> 00:04:21,410 So first of all, as usual, we have to import all the required packages and then we have to declare 41 00:04:21,410 --> 00:04:23,270 the parameters that we are going to use. 42 00:04:23,450 --> 00:04:31,730 For example, um, set I is representing every troop you have and also these parameters like housing, 43 00:04:31,730 --> 00:04:40,070 space, damage, training costs, red training, cornstalk hit point training time, camp capacity and 44 00:04:40,070 --> 00:04:49,760 also read lexia availability and um, availability should be a specified and also how many of each. 45 00:04:49,760 --> 00:04:50,210 Um. 46 00:04:51,990 --> 00:05:00,390 True, you have to train and should be defined by a variable called X and that X, for example, since 47 00:05:00,390 --> 00:05:10,680 your camp has at two hundred eighty, I think, capacity, so the number of troops cannot be more than 48 00:05:10,680 --> 00:05:10,980 that. 49 00:05:11,390 --> 00:05:18,930 Um, and also they are coming from non-negative integers, so positive integers and initialize them 50 00:05:18,930 --> 00:05:28,590 with zero and also total attack, uh, capability, total heat point and also the time required for 51 00:05:28,590 --> 00:05:31,010 training those troops is also specified. 52 00:05:31,020 --> 00:05:34,980 So there are some rules or some constraints that are defined here. 53 00:05:35,430 --> 00:05:37,440 And I will explain some of them for you. 54 00:05:37,450 --> 00:05:42,330 For example, the amount of damage total attack is exceptional to buy by damage. 55 00:05:42,330 --> 00:05:50,400 I summation overall I in the model and also the total, um, housing is space should be less than your 56 00:05:50,820 --> 00:05:52,980 account capacity of your camp. 57 00:05:53,400 --> 00:05:59,490 And also the required red Alexia's should be less than your available rather lexia. 58 00:05:59,670 --> 00:06:01,200 The same for dark lexia. 59 00:06:01,710 --> 00:06:09,150 And also um the total heat point is defined over and heat multiplied by Exide summation over I. 60 00:06:10,050 --> 00:06:13,910 And also finally the training time is defined as follows. 61 00:06:14,400 --> 00:06:18,250 So we do have three objective, uh, functions. 62 00:06:18,300 --> 00:06:19,370 This is the tricky point. 63 00:06:19,410 --> 00:06:26,900 OK, so, um, in plomo, uh, you can't have more than one objective function. 64 00:06:26,950 --> 00:06:28,530 OK, so that's fine. 65 00:06:28,530 --> 00:06:34,040 If you define three objectives and it doesn't depend what name you choose here. 66 00:06:34,050 --> 00:06:36,600 This is the key word which is important here. 67 00:06:37,110 --> 00:06:44,640 Um, but you can define them, but you can't have them all active in your model, so you specify your 68 00:06:44,640 --> 00:06:45,210 solver. 69 00:06:45,240 --> 00:06:53,100 I use GLP K because it's a linear integer programming and you have to deactivate two of them and just 70 00:06:53,100 --> 00:06:54,270 keep one of them. 71 00:06:54,720 --> 00:06:58,230 So I deactivate objective two and three. 72 00:06:58,440 --> 00:07:00,270 I have activated objective one. 73 00:07:00,270 --> 00:07:06,360 It's not really necessary for the first time because it's already activated and then create instance 74 00:07:06,420 --> 00:07:14,130 using the data I already showed you and of the results, uh, it gives you the final solutions so it 75 00:07:14,130 --> 00:07:19,470 can tell you that if you want to maximize the damage, you have to. 76 00:07:21,220 --> 00:07:30,220 Put all your efforts in training wizards, OK, and one goblin, um, or for example, if you want to, 77 00:07:30,220 --> 00:07:34,360 uh, make the objective number to activate it, let's have a look. 78 00:07:34,370 --> 00:07:37,090 What was the objective to object to is total heat point. 79 00:07:37,120 --> 00:07:41,860 OK, so if you want to maximize your heat point, you have to train giants. 80 00:07:41,890 --> 00:07:44,070 OK, and that's it. 81 00:07:44,800 --> 00:07:47,880 So you can change your objective functions. 82 00:07:47,890 --> 00:07:54,850 You can change your availability of the red lexia or a dark Alexiou and see what will happen to your, 83 00:07:55,330 --> 00:07:57,580 um, capability of the troops. 84 00:07:58,150 --> 00:07:59,140 Thank you very much.