1
00:00:00,690 --> 00:00:08,220
Hello and welcome to this lecture, where you are going to learn about one of the main concepts of genetic

2
00:00:08,220 --> 00:00:14,100
algorithms, which is the individual, as you can read here.

3
00:00:14,400 --> 00:00:17,370
They represent solutions to the problem.

4
00:00:17,790 --> 00:00:22,200
Let's assume that are banned individuals in the algorithm.

5
00:00:22,710 --> 00:00:28,350
Each one of them will have a different solution for the problem.

6
00:00:28,770 --> 00:00:38,550
For example, considering the problem of transporting products, the first individual may indicate that

7
00:00:38,550 --> 00:00:41,790
we should only carry refrigerators.

8
00:00:42,270 --> 00:00:51,600
This section one may indicate that we should carry televisions and notebooks, while the 10th individual

9
00:00:51,840 --> 00:00:56,250
may indicate that we should only carry cell phones.

10
00:00:56,970 --> 00:01:02,070
Therefore, a set of individuals forms a population.

11
00:01:02,370 --> 00:01:13,860
We have another concept that is called chromosome, which actually represents a solution to better understand

12
00:01:13,860 --> 00:01:14,160
it.

13
00:01:14,430 --> 00:01:26,070
Let's consider this image that contains the four theme products for our case study and the sets of zeros

14
00:01:26,070 --> 00:01:27,060
and ones.

15
00:01:27,540 --> 00:01:37,980
Then number one indicates that we are going to take the products, and the number zero indicates that

16
00:01:37,980 --> 00:01:41,070
we are not going to take the product.

17
00:01:41,460 --> 00:01:50,400
For example, in this solution, we will load on the drug, this cell phone, this televisual here,

18
00:01:50,730 --> 00:02:00,060
the notebook, the microwave, the refrigerator and these all other notable Cahir, all these other

19
00:02:00,060 --> 00:02:02,010
products, for example.

20
00:02:02,460 --> 00:02:04,580
These are other refrigerator.

21
00:02:04,980 --> 00:02:09,120
There's two devices here the ventilator.

22
00:02:09,420 --> 00:02:15,570
This two microwaves designed the refrigerator and the last the note.

23
00:02:15,570 --> 00:02:21,720
The broker here, once loaded on the truck, the chromosome is.

24
00:02:21,720 --> 00:02:29,550
This sets off zeros and ones, which indicates whether the product will be loaded.

25
00:02:29,970 --> 00:02:33,180
Let's go back to our Google CoLab file.

26
00:02:33,540 --> 00:02:43,620
I will open a new cell of codes and we are going to create the individual class in order to represent

27
00:02:43,620 --> 00:02:44,670
this solutions.

28
00:02:45,270 --> 00:02:54,540
Let's state Glass in the video, and again, we need to define the constructor of the glass.

29
00:02:54,940 --> 00:03:03,510
The in-need function self is the standard parameter and it will receive this basis.

30
00:03:04,230 --> 00:03:15,030
The prices this base limits and also another concept generation equals one.

31
00:03:15,330 --> 00:03:18,690
This is the initial value for this parameter.

32
00:03:18,990 --> 00:03:26,970
Later on, we'll discuss more about the generations we will sand's to this glass.

33
00:03:27,360 --> 00:03:38,000
The information about the products, for example, we have the prices of the products and also this

34
00:03:38,040 --> 00:03:42,390
base each product occupies in the truck.

35
00:03:42,900 --> 00:03:48,390
This is the list of prices and the list of spaces.

36
00:03:48,660 --> 00:03:56,880
And also we will sand's this base limits, which is related to this information.

37
00:03:57,270 --> 00:04:04,850
In our case study, the maximum capacity of the truck is three meters.

38
00:04:05,460 --> 00:04:13,740
Now we can create the attributes of the class, so basis equals basis.

39
00:04:14,130 --> 00:04:26,180
The new attributes we are defining now will be equal to this basis parameter self that prices equals

40
00:04:26,190 --> 00:04:27,120
prices.

41
00:04:27,150 --> 00:04:36,420
This parameter here sells space limits equals space limits.

42
00:04:37,230 --> 00:04:44,160
Self generation equals the parameter generation.

43
00:04:44,880 --> 00:04:49,920
And finally, let's define the list of solutions.

44
00:04:50,220 --> 00:05:00,110
Are the lists of zeros and ones we will define the naming chromosome equals open and closed.

45
00:05:00,250 --> 00:05:10,510
Brackets, it means that we are defining an the list, and the next step is to initialize the chromosome

46
00:05:10,690 --> 00:05:14,590
with a random solution, as we saw here.

47
00:05:14,770 --> 00:05:25,540
And we need a list composed of 14 positions and in each position we are going to set one.

48
00:05:25,870 --> 00:05:35,950
If we are going to load the products and zero, if we are not going to load the product, of course,

49
00:05:36,160 --> 00:05:46,960
later on, the genetic algorithm will put ones should the best products in order to maximize the profits.

50
00:05:47,380 --> 00:05:57,700
But in this initial step, we need a totally random initialization so we can implement a for loop.

51
00:05:58,150 --> 00:06:11,590
For I in range length basis, for example, if we have four denes basis, we need to build a far loop

52
00:06:11,680 --> 00:06:12,730
to go through.

53
00:06:12,730 --> 00:06:18,940
Each one of the spaces are to go through each one of the products.

54
00:06:19,390 --> 00:06:25,870
Now we can access a functional from by them, which is the random function.

55
00:06:26,230 --> 00:06:30,130
I will open a new cell of code tree bark.

56
00:06:30,130 --> 00:06:35,740
This function from random, in part random.

57
00:06:36,250 --> 00:06:40,360
Let's run this cell and just shoot past it.

58
00:06:40,600 --> 00:06:51,670
We can just type random, run this code, see that every time we run these codes, we have four different

59
00:06:51,670 --> 00:06:58,390
random number and it will generate numbers from zero to one.

60
00:06:59,110 --> 00:07:09,520
And we can use these random function to define if the value of the chromosome will be zero or one.

61
00:07:09,850 --> 00:07:17,860
So we can apply the following if random, less than 0.5.

62
00:07:18,460 --> 00:07:28,780
We can access the chromosome attributes and lets up bands zero here or otherwise.

63
00:07:29,140 --> 00:07:40,120
If the random number that was generated is greater are equal to zero point five, then we will axis

64
00:07:40,120 --> 00:07:46,060
the chromosome and we will the bands number one we are doing.

65
00:07:46,060 --> 00:07:52,180
It's because there is a probability of 50 percent off.

66
00:07:52,180 --> 00:08:04,570
Select the R number over 0.5 and also there is a 50 percent probability of selecting a number under

67
00:08:04,570 --> 00:08:06,280
0.5.

68
00:08:06,580 --> 00:08:16,930
So we are using this random function to choose if we are going to load or if we are not going to load

69
00:08:16,930 --> 00:08:18,700
the product in the truck.

70
00:08:18,880 --> 00:08:25,300
And as I said before, this is just the initialization of the individual.

71
00:08:25,810 --> 00:08:35,620
Now we can create this class and to perform the initial best, we can create three new variables.

72
00:08:36,010 --> 00:08:49,090
The first one spaces and the list, this section one crisis and the list and names again and empty list.

73
00:08:49,450 --> 00:08:59,350
In this order list here, see that we have the name of the product, the price and this space, and

74
00:08:59,350 --> 00:09:05,740
we are defining three new lists just to be easier to implement the codes.

75
00:09:06,070 --> 00:09:16,660
As the names of the variable suggests, we will use each one of this lists to store the information

76
00:09:16,660 --> 00:09:23,530
regarding the products so we can now go through each one of the products.

77
00:09:23,800 --> 00:09:30,670
I will define that this new variable for products in products lists.

78
00:09:30,940 --> 00:09:39,850
We are going through each one of the products and let's suggest the values, spaces, dots are bands,

79
00:09:40,450 --> 00:09:44,140
products, but space prices.

80
00:09:44,620 --> 00:09:51,970
But the bands, products, lots, price and finally names.

81
00:09:52,390 --> 00:09:59,890
But the bands product but name I will also define the limit.

82
00:10:00,090 --> 00:10:09,030
Variable, which will be equal should three it the means that the maximum capacity of the truck is only

83
00:10:09,030 --> 00:10:10,710
three cubic meters.

84
00:10:11,220 --> 00:10:14,840
We can create this variable and see the value.

85
00:10:15,330 --> 00:10:18,160
Let's sprint spaces.

86
00:10:18,900 --> 00:10:25,800
We can see the information regarding this space of each one of the products.

87
00:10:26,220 --> 00:10:27,260
We can also.

88
00:10:27,280 --> 00:10:31,890
Brent's prices run this codes.

89
00:10:32,250 --> 00:10:34,860
We have the corresponding prices.

90
00:10:35,160 --> 00:10:43,140
And finally, Bryant's names, and here we can see the name of the products.

91
00:10:43,590 --> 00:10:51,240
We can also access specific positions, for example, names in position.

92
00:10:51,360 --> 00:10:52,050
Five.

93
00:10:52,440 --> 00:10:56,670
We can see Notebook A to see the price.

94
00:10:56,670 --> 00:11:01,630
We can access the list of prices in the same position.

95
00:11:02,220 --> 00:11:05,580
We can see here more than $2000.

96
00:11:05,910 --> 00:11:10,200
And finally, we can take a look at this space.

97
00:11:10,830 --> 00:11:13,500
Accessing this through variable.

98
00:11:13,800 --> 00:11:17,490
Zero point zero zero thirty five.

99
00:11:17,820 --> 00:11:25,860
As I said before, we just separated our original list in three new lists.

100
00:11:26,070 --> 00:11:29,310
So the access will be easier now.

101
00:11:29,310 --> 00:11:35,690
We can create the first in the feedlot and we'll create the new object.

102
00:11:36,040 --> 00:11:46,800
The individual one equals let's call the name of the glass just to remind that we need to sense the

103
00:11:46,800 --> 00:11:50,430
original basis of all products.

104
00:11:50,860 --> 00:11:52,150
Vaporizes.

105
00:11:52,800 --> 00:11:54,240
Space limits.

106
00:11:54,420 --> 00:12:03,900
And when we create the object, we will assume the individual will be part of generation number one.

107
00:12:04,250 --> 00:12:08,220
Later, we will see more details about this parameter.

108
00:12:08,700 --> 00:12:18,000
Now let's sends the list off space is the list of prices and the limit.

109
00:12:18,270 --> 00:12:26,990
It's important to emphasize that each one of these parameters will be qubits.

110
00:12:27,360 --> 00:12:38,340
Should this part the here and then we create the attributes of the glass and we use lamp spaces just

111
00:12:38,340 --> 00:12:41,250
to implement this for loop here.

112
00:12:41,580 --> 00:12:47,080
For example, we can type LEM spaces.

113
00:12:47,730 --> 00:12:53,490
The result is 14, which means that there are 14 products.

114
00:12:53,790 --> 00:13:00,780
So we need to use this number here to generate 14 values.

115
00:13:01,260 --> 00:13:07,620
Each one of the values will be related to each one of the products.

116
00:13:07,980 --> 00:13:12,280
After creating the object, we can print some information.

117
00:13:12,750 --> 00:13:13,920
The first one?

118
00:13:15,460 --> 00:13:23,530
Spaces we can Typekit here in the video, one thoughts spaces.

119
00:13:24,400 --> 00:13:25,330
This section.

120
00:13:25,360 --> 00:13:33,870
Information the list of prices of all products in the world.

121
00:13:33,910 --> 00:13:36,820
Thought prices brands.

122
00:13:37,150 --> 00:13:38,910
The next information.

123
00:13:39,460 --> 00:13:42,520
The chromosome individual.

124
00:13:43,550 --> 00:13:54,710
One dots chromosome, let's run this cell of code we can see here this basis, the price and the chromosome.

125
00:13:55,430 --> 00:14:05,300
What is important to say is that every time you run this codes, you will have a different chromosome.

126
00:14:05,600 --> 00:14:11,600
As you can see here, because we are using this random function.

127
00:14:11,840 --> 00:14:15,650
So this is a totally random initialization.

128
00:14:15,980 --> 00:14:20,750
Now we can associate this chromosome to the products.

129
00:14:21,170 --> 00:14:29,120
For example, no one here means that we are going to select refrigerator.

130
00:14:29,150 --> 00:14:35,420
A zero means that we are not going to select this cell phone.

131
00:14:35,930 --> 00:14:42,650
One means that we are going to select this for these other one.

132
00:14:42,660 --> 00:14:48,470
Here means that we are going to also select this order TV.

133
00:14:48,890 --> 00:14:59,270
Now we can implement codes to get the names of the products so we can associate ones with the names.

134
00:14:59,660 --> 00:15:02,120
So let's implement a for loop.

135
00:15:02,720 --> 00:15:07,700
For I in range land.

136
00:15:09,230 --> 00:15:20,000
Product lists, we are going to be at this for loop for 14 times the same amount of the products, and

137
00:15:20,000 --> 00:15:29,090
we can also print to hear the individual one dots chromosome position high.

138
00:15:29,360 --> 00:15:31,070
Let's run this code.

139
00:15:31,400 --> 00:15:34,730
We can see here each one of the files.

140
00:15:35,090 --> 00:15:41,420
Of course, every time we run this code, we will get different results.

141
00:15:41,870 --> 00:15:48,830
Now, it's quite easy to associate the ones with the names of the products.

142
00:15:49,280 --> 00:15:57,650
I will implement an if statement if individual chromosome was the issue, I.

143
00:15:58,610 --> 00:16:13,230
Equals one, then we can just prints the name of the product and we can access our product lists, position

144
00:16:13,230 --> 00:16:24,980
pi dots, name, we need to tie the dots name here because remember that we have a list of products

145
00:16:24,980 --> 00:16:27,530
in each position of the list.

146
00:16:27,950 --> 00:16:29,960
There is one product.

147
00:16:30,320 --> 00:16:32,660
Now we can run this code again.

148
00:16:33,170 --> 00:16:34,550
Take a look here.

149
00:16:34,580 --> 00:16:36,650
That's in this solution.

150
00:16:36,920 --> 00:16:48,860
We are going to select Refrigerator A that cell phone, TV 55, 50, 50, TV 42 and so on.

151
00:16:49,280 --> 00:16:51,140
Let's run this code again.

152
00:16:51,440 --> 00:17:00,950
We will get another list of products, and that's how we implement the first step of the genetic algorithm,

153
00:17:01,280 --> 00:17:06,500
which is the definition and representation of the solutions.

154
00:17:06,920 --> 00:17:11,750
And in the next lecture, we will continue the genetic algorithm.

155
00:17:12,170 --> 00:17:12,860
See you there!
