Hello and welcome to this lecture, where we are going to start with the implementation of their genetic
algorithm to solve deterrence parts problem, we already have this Google CoLab file.
If you were new to Google collab, you just need to follow the link, which is available in the class
materials and to make changes are to run this file.
You need to click on file, save a copy drive when you click this link.
A copy of this notebook will be made on your own Google Drive, so you must have a Google account and
you also needs to be connected to it.
The Google collab is very useful because we don't need to install anything in our old machine.
We can type the code using the browser and we'll click Connect to connect to the Google servers, and
now we'll open a new set of codes.
Clicking this button here The goal of this lecture is to build the product glass in order to represent
our problem, as we saw last lecture.
We have a set of 14 products and each product has a name.
This base that the product occupies in the truck, and also this sales price.
And now we need the wage who represents each one of these products.
And the best way to do that is to create a class.
This is a concept of object oriented programming, and if you were new to this technology, don't worry,
because we will implement all step by step and later on we will perform some tests.
Less great, the class products.
And in order to build a class in Python, we need to define this function, which is called INITS.
This is a kind of system, their function that will be called when we create the objects and it will
receive as a parameter self.
This is a system that are parameter that you need is just sans.
So that's Python language.
We understands that the variables that we are going to create later will be associated with this class.
Let's sans the main parameter, this space and also the price as we saw in this light.
Now we need to create some attributes and in order to do that, we need to use the word self.
I will create a new attribute called name, which will be equal should the name parameter that we are
going to.
Later on, I will create on larger attributes safe space equals space.
This parameter here self Dot's price equals price.
We are creating the attributes which are related to the concepts of object oriented programming.
Let's create this glass and now it will be easier to understand these variables.
Let's create product.
One equals let's go the name of the class with the find the here and take a look at that.
We can send three parameters namespace and price.
As I said before, the parameters self is not used here.
It's a kind of an internal process of Python programming language.
Let's suppose we want to represent a refrigerator a this size zero point seven five one and the price
nine nine nine point nine.
It is the representation of this first product, refrigerator a.
We can run these codes and now we can take a look at the attributes that we defined the here.
We can type B1 dots name.
Run this code, we can say the name of the product refrigerator, eh?
Just to better understand when we call this glass, these in needs function will also be codes and then
we sends this parameter.
Should the name.
And it will be copied should the attribute of the glass.
Then we send this space.
Should this section two reports.
And finally, we copy this value.
Should these parameter and then we associate with the attribute of the glass.
We can also take a look at the other parameters.
One.
But space?
And B word dot price.
Let's run these codes and we can see the results according to the values with sense, should the parameters.
We can also create products show equals products.
Let's Typekit the name of the product.
The first barometer cell phone this space zero point one two three four five zero eight nine nine and
the price.
One line nine points twelve.
It is the representation of this cell phone here.
Now we can take a look at the values just to make sure feature, but the main feature dot space feature
dot price.
Let's create the object.
Be sure we can take a look at the values which are the same, which is specified as a parameter.
Take a look here that as we have a very small number, it was sports in scientific notation.
Just to recap, first, we need to build the glass, which is the general structure, and then we can
create the variables.
Are the objects in this case.
One and bit.
Now we need a way to represent all the 14 products, and we can put all the products in the format of
a list in by them.
So let's create another variable products list.
Initially, it is an empty list, and when you use open and close brackets in Python, it means that
you are defining.
At least now we can ods the products to this list.
We can use the app bands Colman's and then we can just call our glass.
Let's send the heater defers, products refrigerate or a band we need should specify the space seven
five one and the price nine nine nine point nine.
Then we need should do exactly the same for all other products.
Let's sup bands this cell phone I.
We'll just copy and paste this code here.
Then we need to move on to the next product, according to our slides.
The next one products TV 55 inches.
Now let's specify the space zero point forty and the price for the trip for this six point ninety nine.
Now we should do exactly the same for all other products.
I we'll just paste this code here in order to have all the products in this list.
Now we can create this variable products list and we can take a look at the values.
If we type products list, we can see each one of the positions.
See, that's in each position off this list.
There is a product and you see the values we need to implement a far loop for products.
Product is the variable grading now in product lists and we.
Just Sprint's products, not that's name.
Let's run these codes and we can see the name of all products.
We can also take a look at the price.
Let's Oxes products that price and also the space just type products, dot space.
Run these codes.
And finally, we can see the results.
This is the first part of our algorithm in which we just implemented the list of products.
And in the next lecture, we'll move on to the concepts of genetic algorithms.
So you there?