Hello and welcome to this lecture, where we are going to solve the problem related to the transport
of products using M. L Rose Library.
This is another interesting library where you can find implementations of genetic algorithms.
Follow this link!
If you want to know more detail, you can see some informations about optimization problems and differently
from deep, which is focused on evolutionary algorithms.
These order library is focused on optimization algorithms.
For example, we can click algorithms here and then our implementations of the hillclimb algorithm.
We can see here the simulated annealing and also genetic algorithms.
They are different kinds of algorithms to minimize or maximize of value.
So instead of using genetic algorithms to solve this problem, you can also use simulated annealing
and also the hillclimb.
The good point is that you have easy access to the source codes.
For example, you can click Sirs here, and you can take a look at the genetic algorithm implementation.
Maybe if you was to make some changes to our algorithm implemented from scratch, you can see more information
here.
Now, let's install the library.
Let's type PIP.
Install Email Rose.
Run this sale of codes we are using version one point three point zero.
If you have some problem in music, you would think the codes we are going to implement.
Maybe it is because of different versions so you can type B install.
Email rose equal one point three point zero, so the codes will be compatible with the one we are going
to implement now.
The next step we need to impart to the library in parts and URLs.
Run this cell.
No error was returns, so it means the library was successfully installed.
Now we need to define the list of products.
Any stands of defining use in the four months of a class.
We can also paste this code, which is a simple list in Python.
In each one of the positions, we can see the features about the products.
The name this base and also the price you can use.
The class we implement as before, and also you can define in the form of a list.
We can create this variable.
Lets type products.
You can see all the information about our data.
Let's also create another variable limit equals three, which means the available space in the truck.
Now in these should define the in function again and choose not to be so repetitive.
I will just based this code to here fitness function.
We sans a solution which is composed of zeros and ones.
Just a reminder, zero means that we are not going to load the products on the truck, and one means
that we are going to load the product on the truck.
At the end, we return the cost and we don't need to type a call here because it is not necessary.
Using this library, let's create the function and now we can create a new variable.
Fitness equals email rose custom fitness because we are using our own fitness function.
Let's just dive here.
Fit in this function.
This same name of the function?
Run this code.
Now we needs to refer.
Zandt's, the problem?
Email rules got this crap.
Obesity this crats means that we are going to work only with integer numbers.
We need to specify the length of this solution.
Land products we can type this code to here.
Land products just correct this typo.
Here we can see that the results equals 14, which means the amount of products in our data.
Then, when these two is specified, this fit in this function, which will be equal to fitness.
This variable we define the higher than the X parameter maximize equals true because we want higher
values.
And finally, Max Vo equals chu.
It means we was to generate only zeros and ones.
So when we define number two, the library will generate only zeros and once we run this sale of codes.
And finally, we can create two new variables.
The first one, the best solution and the best fit in this are the best value equals email rules we
can call the genetic algorithm.
We will sans the problem.
Then the experimenter pops size, population size.
For example, we can define only 20 individuals, and there is another parameter mutational prob the
probability of mutation zero point zero one.
This same parameters according to our last implementation, and we don't need to specify the number
of generations because the algorithm itself will try to find the optimal number of generations after
ruining this code.
We can take a look at the best solution and the best fit in this let's run this code.
We can see the chromosome, and here it is.
Solution twenty four thousand three hundred and eighty five.
Every time we run this code, we will get a different value because the initialization of the chromosome
in the beginning of the algorithm is random.
Let's run these codes a couple of times, and we can see results quite similar to the one we got before.
To show the products that we are going challenge, we can implement the far loop for I in range length
based solution.
We are going through these lists of zeros and ones.
If the best solution position, I equals one.
Let's just sprints the name of the product.
We can access our list products position.
I am position zero and then the price of the product lets access again our list products position.
I am position to just two.
Badru understands we can type where products we can see all information if we was to get the cell phone.
It is in position zero and position one.
We can type a products position when we get only the cell phone.
If we want to get the name, it is in position zero.
For this reason, we have these implementation here.
We can also access the price products product one and position two.
Ran this code, and we have the price of the product.
Now we can run this code, and here is our results.
This is the list of products that we are going to load on the drug.
As you could see, it's much easier to work with Melrose Library in the next lecture and we will present
you.
This second case is the the the second problem that we are going to solve using both libraries.
See you there!