1
00:00:00,330 --> 00:00:08,430
Hello and welcome to this lecture, where we are going to create a new project in bicarb to connect

2
00:00:08,430 --> 00:00:19,050
our genetic algorithm to the database we created using my scale so we can click New Project in Dubai

3
00:00:19,050 --> 00:00:20,530
Sha idea.

4
00:00:20,970 --> 00:00:26,190
We can define it the name of the project, for example, genetic.

5
00:00:26,550 --> 00:00:31,350
And here you can specify the folder you were going to save it.

6
00:00:31,830 --> 00:00:35,520
We are going to use the goal in that environment.

7
00:00:35,730 --> 00:00:46,110
So when we created the project, a new environment will be created in Anaconda that we installed before.

8
00:00:46,560 --> 00:00:48,390
Let's click Create.

9
00:00:48,780 --> 00:00:54,690
We can delete this file that was automatically generated.

10
00:00:55,170 --> 00:01:03,780
Let's create a new by file how will call genetic algorithm.

11
00:01:04,140 --> 00:01:13,540
And now we can import some libraries from random in part, random in part.

12
00:01:14,310 --> 00:01:20,640
Mads Lots lib dots by plot s VLT.

13
00:01:21,030 --> 00:01:34,730
This is a library to visualize graphs by them and also lets you boards by my L to contact our Python

14
00:01:34,740 --> 00:01:36,960
file through the database.

15
00:01:37,710 --> 00:01:48,090
When we try to run this code, see, that's when it was returns because there is no module named Matt

16
00:01:48,090 --> 00:01:52,620
blot the Lib, so it means we need to install this package.

17
00:01:52,950 --> 00:02:02,430
We can click through, you know, here and let's type B install Matt Blot Lib.

18
00:02:02,850 --> 00:02:07,050
This is a Python Colman's to install libraries.

19
00:02:07,260 --> 00:02:08,640
Run this code.

20
00:02:09,270 --> 00:02:14,220
We can see that the downloads process has already started.

21
00:02:14,880 --> 00:02:18,600
After that, we can see that the package was installed.

22
00:02:19,110 --> 00:02:22,440
Now we need to install by my --.

23
00:02:22,770 --> 00:02:29,420
Well, let's type people install by my ask.

24
00:02:29,460 --> 00:02:31,740
You'll run this code.

25
00:02:31,860 --> 00:02:35,880
We can see the message successfully installed.

26
00:02:36,240 --> 00:02:39,570
Now we can try to run this code again.

27
00:02:39,930 --> 00:02:43,620
See, that's no air or was returned.

28
00:02:43,950 --> 00:02:48,150
So it means that the libraries were installed correctly.

29
00:02:48,570 --> 00:02:49,050
We will.

30
00:02:49,050 --> 00:02:52,260
We use the same code we implemented as before.

31
00:02:52,620 --> 00:02:55,690
So we'll just based the code.

32
00:02:55,710 --> 00:02:57,840
Here it is this same.

33
00:02:57,930 --> 00:03:01,530
We implemented step by step in Google CoLab.

34
00:03:02,700 --> 00:03:09,810
Glass products, glass in the video glass genetic algorithm.

35
00:03:10,170 --> 00:03:20,160
And now we need to generate the list of products because we are not going to use up by phone list as

36
00:03:20,160 --> 00:03:21,270
we did before.

37
00:03:21,690 --> 00:03:27,450
The idea is to connect to the database in order to do that.

38
00:03:27,720 --> 00:03:33,060
We can create a main function here in by Shaam.

39
00:03:33,600 --> 00:03:40,560
If Maine equals Maine, we can see here these arul.

40
00:03:40,680 --> 00:03:50,580
It means that every time we run these codes, the flow of the program will start executing all the codes,

41
00:03:50,760 --> 00:03:53,490
which is inside this block.

42
00:03:53,850 --> 00:04:05,370
We can create our products list and an empty list, and now we can connect to our database.

43
00:04:05,670 --> 00:04:09,180
So I will create this new variable connection.

44
00:04:09,390 --> 00:04:17,010
Let's call the new library dots connect and we need to specify so parameters.

45
00:04:17,340 --> 00:04:21,690
The first one host local hosts.

46
00:04:21,690 --> 00:04:25,980
It means that we are connecting to our local machine.

47
00:04:26,400 --> 00:04:36,960
If you are using another database which starts in the internet, you can just put the IP number, the

48
00:04:37,000 --> 00:04:40,150
next parameter user ID.

49
00:04:40,210 --> 00:04:46,950
The phone user in this database is roads and the order parameter.

50
00:04:47,430 --> 00:04:48,690
The passwords.

51
00:04:49,110 --> 00:04:56,700
Now you'll need to specify here that passwords you choose when you install the library.

52
00:04:56,970 --> 00:05:00,630
In this case, here I use this best word here.

53
00:05:00,870 --> 00:05:06,390
One two three four, five, six, seven and eight and the last parameter.

54
00:05:06,840 --> 00:05:11,730
The database, which defines the name as products.

55
00:05:12,090 --> 00:05:23,970
As we can see here in work bank, let's create another variable cursor, equal connection dots cursor.

56
00:05:24,210 --> 00:05:28,110
It means that we are connecting to the database.

57
00:05:28,470 --> 00:05:31,290
Now we can execute some queries.

58
00:05:31,710 --> 00:05:32,410
Cursor.

59
00:05:32,760 --> 00:05:37,590
But is it cute and we can type ASCII L code?

60
00:05:38,070 --> 00:05:47,160
For example, this code here just selects all the columns so we can type here the name of the columns.

61
00:05:47,160 --> 00:05:59,280
For example, we want to get product name space price quantity from products.

62
00:05:59,640 --> 00:06:05,740
We can just copy these codes and go back to the workbench.

63
00:06:06,120 --> 00:06:16,050
When we run this code, we will select all Carlos products, the names, base price and quantity.

64
00:06:16,350 --> 00:06:21,600
We can type that code here, select and run.

65
00:06:21,930 --> 00:06:31,140
See that we are specifying only the columns we want to get product name, space, price and quantity.

66
00:06:31,590 --> 00:06:36,420
Now we can go through these results for products.

67
00:06:36,810 --> 00:06:45,720
This is a new variable and great email in cursor, and let's pourrions the product.

68
00:06:46,080 --> 00:06:55,470
Now we can run this code, see that we are going through each one of the rows of our data sets.

69
00:06:55,500 --> 00:06:59,220
We are going through these stable here.

70
00:06:59,730 --> 00:07:05,880
We can see that we have positioned zero position one and position two.

71
00:07:06,450 --> 00:07:12,960
If we type here, position zero, we will get only the names.

72
00:07:13,710 --> 00:07:14,250
We can.

73
00:07:14,250 --> 00:07:19,320
Also type products was the position number one.

74
00:07:19,890 --> 00:07:32,280
We can see this basis and in position number two, we will see the prices of the products now that we

75
00:07:32,280 --> 00:07:34,650
have the information we need.

76
00:07:35,010 --> 00:07:40,740
We can access products list, but up bands.

77
00:07:41,280 --> 00:07:46,620
We will create a new object product and let's sans the parameters.

78
00:07:46,890 --> 00:07:51,870
The first one, as we can see, is the name of the product.

79
00:07:52,170 --> 00:08:01,800
This second one, this base was issue one and the third one, the price was issue number.

80
00:08:01,910 --> 00:08:11,300
Sure, we can put these quotes in comments, and after executing the aquaria in the database, we can

81
00:08:11,300 --> 00:08:14,030
close the cursor.

82
00:08:14,420 --> 00:08:19,850
And also we can close the connection to release the memory.

83
00:08:20,210 --> 00:08:25,400
After that, we can print products lists.

84
00:08:26,030 --> 00:08:35,720
Let's run these codes and we can see that we have one object in each one of the positions.

85
00:08:36,230 --> 00:08:48,160
We can also implement a for loop just to see the results for product in product list for its product.

86
00:08:48,650 --> 00:08:50,540
Let's run this code.

87
00:08:51,050 --> 00:08:58,400
We can see the objects and just see the names we can just type product that name.

88
00:08:59,090 --> 00:09:04,910
Run this code and we have the names of each one of the products.

89
00:09:05,360 --> 00:09:11,450
But there's something additional in this code, which is the quantity column.

90
00:09:11,840 --> 00:09:19,800
For example, there are five cell phones on the start and that are two TV 55.

91
00:09:20,390 --> 00:09:30,740
So we need to create five cell phone objects and to be these 55 objects.

92
00:09:31,130 --> 00:09:37,910
And regarding order products, we can see that that are then ventilators.

93
00:09:38,150 --> 00:09:46,370
So we need to create than objects regarding this product should do that is quite simple.

94
00:09:46,790 --> 00:09:50,960
We can just implement another far loop here.

95
00:09:51,380 --> 00:10:04,040
For I in range product imposition number three, we can see that position zero is the name World Space

96
00:10:04,250 --> 00:10:13,130
Shoe is the price and position three is the quantity and odds each one of the products in the list.

97
00:10:13,700 --> 00:10:20,090
We can just run this code again, and now it's easy to see the results.

98
00:10:20,870 --> 00:10:24,170
There is only one refrigerator a.

99
00:10:24,500 --> 00:10:27,650
And there are five cell phones.

100
00:10:27,950 --> 00:10:41,270
We can see that there are three 550 for the VFR de Q and so one we can also bring two here product list.

101
00:10:41,630 --> 00:10:43,840
Let's check the length.

102
00:10:44,360 --> 00:10:46,400
Run this code.

103
00:10:46,790 --> 00:10:54,290
See that before there were 14 products and now that are 47 products.

104
00:10:54,800 --> 00:11:04,040
Basically, this is the only change we need to perform to run the genetic algorithm connected to my

105
00:11:04,220 --> 00:11:04,970
scale.

106
00:11:05,330 --> 00:11:09,140
We just need to access the product stable.

107
00:11:09,530 --> 00:11:18,920
Now we can put all these screens in commands and then we'll just base this same code we had implemented

108
00:11:18,920 --> 00:11:19,580
before.

109
00:11:19,850 --> 00:11:27,320
We can see here that we are creating this basis prices and names variables.

110
00:11:27,650 --> 00:11:36,170
We are going through each one of the products for these seven products, then limits population size,

111
00:11:36,200 --> 00:11:38,810
mutation, number of four generations.

112
00:11:39,050 --> 00:11:42,020
We are creating here the genetic algorithm.

113
00:11:42,290 --> 00:11:46,220
And after that, we are calling this solve methods.

114
00:11:46,640 --> 00:11:49,940
We can run this set of codes.

115
00:11:50,330 --> 00:11:56,690
And now we can see the results, for example, in generation number zero.

116
00:11:56,990 --> 00:11:59,960
The total prize was won.

117
00:12:00,170 --> 00:12:09,950
It means that this space occupied by all the products exceeded the maximum capacity of the truck as

118
00:12:09,950 --> 00:12:18,740
we saw earlier, and the chromosome is different that are more products are here because before there

119
00:12:18,740 --> 00:12:28,340
were only 14 products and now that are four, these seven products because we are considering the quantity

120
00:12:28,760 --> 00:12:32,420
we can see here that we have bad results.

121
00:12:32,780 --> 00:12:44,510
Total price is equal to one for all generations, and it may have been because now there are more products

122
00:12:44,510 --> 00:12:47,660
and we have the limits only three.

123
00:12:47,930 --> 00:12:53,270
So we need to increase the size of the limits to work with more products.

124
00:12:53,660 --> 00:12:58,490
Let's change should then run this code again.

125
00:12:58,880 --> 00:13:01,730
And now we can take a look at this solution.

126
00:13:02,300 --> 00:13:07,520
For example, generation zero four thousands.

127
00:13:07,880 --> 00:13:14,450
And this base is equal to zero point zero nine in generation one.

128
00:13:15,080 --> 00:13:24,950
The total prize equals one because as we can see here than point six, the six is greater than the capacity

129
00:13:24,950 --> 00:13:25,850
of the truck.

130
00:13:26,270 --> 00:13:31,340
We can see all the results considering all the generations.

131
00:13:31,760 --> 00:13:41,600
And finally, we can see that the best solution was found one generation for this seven, and the total

132
00:13:41,600 --> 00:13:44,870
price is fifty five thousand.

133
00:13:45,170 --> 00:13:48,860
And this space equals 9.10.

134
00:13:49,100 --> 00:13:54,560
And here we can see the products that we are going to load on the truck.

135
00:13:54,860 --> 00:14:02,690
Something very interesting about this new implementation, considering the quantity of the products,

136
00:14:02,990 --> 00:14:11,540
is that there are five cell phones and all of them are going to be loaded on the truck.

137
00:14:11,870 --> 00:14:20,970
On the order of hands that are banned, ventilators and only five of them were loaded.

138
00:14:21,320 --> 00:14:32,090
And it happens because this space occupied by this cell phone is less then this space occupied by the

139
00:14:32,090 --> 00:14:33,140
ventilator.

140
00:14:33,440 --> 00:14:43,160
And the price of the ventilator is only one hundred and ninety nine, and the price of the cell phone

141
00:14:43,460 --> 00:14:47,450
is two thousand one hundred and ninety nine.

142
00:14:47,780 --> 00:14:53,690
So the genetic algorithm will adapt to this kind of situation.

143
00:14:53,930 --> 00:15:03,590
It's very interesting because the genetic algorithm knows that when loading more cell phones, the profits

144
00:15:03,590 --> 00:15:04,400
will be bad.

145
00:15:05,090 --> 00:15:08,060
We can try to run this code again.

146
00:15:08,300 --> 00:15:17,360
As I said before, a good way to test the algorithm is to run it for a couple of times and see the results.

147
00:15:17,870 --> 00:15:18,890
See, that's now.

148
00:15:18,890 --> 00:15:24,400
The best solution was found on generation number 59.

149
00:15:24,680 --> 00:15:30,350
And the total price is a little lower than the last is a crucial.

150
00:15:30,590 --> 00:15:36,800
And we can see that's only for cell phones were loaded on the truck.

151
00:15:37,190 --> 00:15:39,140
And regarding the ventilator.

152
00:15:39,410 --> 00:15:43,400
Only three of band were is on that trip.

153
00:15:43,820 --> 00:15:49,640
And finally, we can see the graph with the results here.

154
00:15:50,330 --> 00:15:52,670
So we'll put this quote here.

155
00:15:53,180 --> 00:16:03,080
BLT Dot plots the healthy dots by, though we are using the matte blot label library to see the results.

156
00:16:03,470 --> 00:16:04,760
Let's run again.

157
00:16:05,030 --> 00:16:12,800
And then we can follow their results, considering each one of the generations something very similar.

158
00:16:12,830 --> 00:16:21,740
We implemented using Google CoLab and we can see the results 50 Q, and then you can take a look at

159
00:16:21,740 --> 00:16:27,260
the products that will be loaded on the truck for cell phones.

160
00:16:27,560 --> 00:16:30,950
Now we are loading Refrigerator A..

161
00:16:31,220 --> 00:16:39,020
And in this solution, we are going to load one two three four five six ventilators.

162
00:16:39,320 --> 00:16:45,800
And just a reminder, if you are also fans of a company, you need to sand's.

163
00:16:45,800 --> 00:16:53,420
This list of products should be manager of the company, and in the next section of the course, you

164
00:16:53,420 --> 00:16:58,490
are going to learn how to work with genetic algorithm libraries.

165
00:16:58,880 --> 00:16:59,570
See you there!
