Hello and welcome to this lecture, where you are going to learn how to evaluate each individual of
the population again in the flow of the genetic algorithm.
Last lecture we created an initial population of 20 individuals and now we need to assign a score to
each one, which indicates the quality of the solutions.
This score is this some of the prices of all products and together to discover where we use the fitness
function that we implement as before.
So we are going to implement this second step of the flow of the genetic algorithm.
Let's go back to our Google collab file.
I will open a new set of codes and let's implement a far look for in video.
This variable and great now in genetic algorithm dot population.
Just a reminder that these attributes of the glass, we will start the list off of 20 individuals.
Now we need to go through each one of them and we will just call this fitness function we implement
as before.
If we go back here, should the individual class see here that we have this faith in this function.
And then we updated the attribute score evaluation, which is the total price of the products.
And also we update the used space.
How much space the products use in the truck.
So now we can just run these codes to evaluate each one of the individual blocks.
Now we can implement a for loop to see the results.
For I in range genetic algorithm dots, population size and then let's orient d'informations first in
the video, then we will brilliance this basis.
Just what's here.
A but population in position, I thought.
Basis, then let's brilliant did prices a lot, population position.
I thought prices.
Then we will perience the grandson, which is the solution.
G a got population position.
I let's access the attributes, the chromosome.
And finally, let's brands discarded.
Total price a bot's population position I inlets access.
The at throughput is Esquire evaluation at the end.
Let's just keep the light.
Now we can run this set of codes and we can see the results.
For example, the video zero.
This car is only a thousand.
Here we can see this basis, and the price is just a reminder that this base is and the prices are the
same for all individuals.
Because we are just copying the values from our case study data, we can see the chromosome which indicates
the products that we are going to load on the truck.
Individual twelve thousand.
It's bad there.
Then the first in the video in the video show as well.
Thousands in the video.
Three This car is only one because this set of products X sets the maximal capacity of the truck as
we implement as before.
Another solution only four thousand one one eleven thousand one, again sixteen thousand.
And then we can take a look at all these solutions.
But.
We can see that these values are not in order.
So we need to order the individuals to gather to the best one so we can go back to our genetic algorithm
class and we will implement another function to order the data.
Let's create different gene after population, each one to receive any parameter cell population, which
is the least that we want to order.
It will be equal to start dates.
This is a python function to start, at least.
Let's send here.
The population the attribute that was just start, and then we need to specify the key what value we
are going to use to start the list.
And we'll create a function in room time using the land that Coleman's population.
And then we just specify a population dot score evaluation.
So we are going to start this list based on the attributes of the individual class, which is this one
here.
This core evaluation, which stars the total price.
And finally, we can put here reverse equals true to get the higher values first.
Let's recreate this glass.
Let's go back to this part here.
We will create again a new population.
We can just make sure that we have 20 individuals.
We can see the solutions.
Just a reminder that every time you create a population, you will have different values here.
Now, let's run this code again.
We can see that we have similar results because after evaluating the individuals, we need to call our
new function or order population.
So first, we evaluate them, and after we are dirt boarding the higher values at the lower positions
of the list, let's run this code again.
And let's check the results.
For example, individual zero disquiet is 15000 individual one fifteen thousand one hundred.
This value is higher than these other value individual in the individual three, 13, individual four
and five, all 13 individual 612.
And we can go to the last positions, for example, for Individual 15.
This score is only 6000.
And regarding 16, 17, 18.
And then this card equals one because these sets of products X sets the capacity of the drug.
That's how you can evaluate the individuals.
And in this particular implementation, we are voting the best individual at position numbers zero of
the list.
Because of that, we had this implementation here.
When we initialize the population, we keep the best solution as the first position of the list and
in the next lecture, we are going to continue the implementation.
See you there.