Hello and welcome to this lecture, where we are going to generate a new population.
Let's recap all the process we create is the initial population and then evaluate it's in this part
of the implementation.
We are not considering this stopping there yet, but now we have all these functions here, select various
crossover mutation.
Then, after generating a new population, which is the application of crossover and mutation, we need
to evaluate the population again.
But now we will evaluate the new population that will be generated using crossover and mutation, and
that's what we are going to implement in this lecture.
Moving back to our Google collab file, I will open a new set of codes.
Let's create a new variable new population and am the least.
Let's also define the mutational probability equals zero point zero one, which means one percent.
And let's implement a far loop for new individuals in range from zero to genetic algorithm population
size.
Let's bring out the new individuals variable.
We can run this code, see that we are going through position zero two position nine thin, which means
this size of our population and to generate a new population, we are going to use the crossover function.
We can take a look at the differential here.
It belongs to the individual Class C that we are returning to Childs.
So when we run crossover only once there is old is two new individuals.
So if we run these codes that way, it is defined in the here.
So after running this far loop, here we will and we've for the individuals because in each one of these
runs here, the result will be two individuals.
So we will increase the size of the population birds when we work with genetic algorithms.
The most common is to keep this same size so we can put an additional parameter here.
Number two, it means that we are not going to run these codes one by one.
Now we will run two by two zero two four six eight.
And so one.
Now we need to select two parents.
We will create the new variable variants.
One equals genetic algorithm, select parents.
Let's send the here this sum, and I will also create parents to genetic algorithm, select parents.
And how will PWDs here year?
Also this so we can just go up to the class, the genetic algorithm.
And I will put this Branston comments just to be easier to visualize with the results.
Let's create again the genetic algorithm glass.
I will go back to these barred to here where we are creating the population.
We can run all this code again.
Here we are, set the the best in the video.
We can see that the new some value is one hundred and seventy.
And now let's go back to this part here.
We can friends' parents one and parents.
Sure.
And I will put at the beginning this school months choose Keep the line.
For example, in the first section, we will combine individual zero with individual.
Almost zero as the result is the same, we will combine the same individuals.
So the result will be the same.
If you want, you can implement an additional all the here.
If you don't want to return, this same parents in this section is a crucial.
We will combine 11 with three five nine five two seven nine.
And so one, as we saw in the theoretical lecture, the probability of selecting the best individuals
are higher than the probability of selecting the worst individuals to hear at the end.
Because of that, you can see that we are selecting the individuals that are at the first positions
of the list.
The worst individual that was selected was 11.
We can take a look at the value here, individual 11 and here is the solution.
But in none of these equations we select, it's these bad solutions.
For example, 14 15 where this score equals one.
So these solutions are bad because we cannot load the products on the truck.
This is the first step to generate a new population.
We need to select the parents.
Now let's create the children equals genetic algorithm population.
Let's select parents one and we are going to call the cross over functional and we'll sans population.
Parents.
In this saccone's equation.
We are combining 11 with three in the third.
Five with four nine.
And so one, we can bring the results.
Brent's genetic algorithm, but population parents, one but chromosome we can all brands, population,
parents, true, but chromosome we can run.
This code suggests you see the partial results.
Now we have different values.
We selected Position Zero, which is the best solution because it is in the first position of the list
and we are combining with solution number five.
Then we select then, which is the these chromosome here and we are combining with nine these chromosome
here.
And we keep combining the chromosomes using crossover after dads.
We can see the children that were generated.
Brian's children was these zero dots chromosome and also children in position one dots chromosome.
Let's run this code again.
We will get different values.
We are combining individual number three with individual number one.
These two lines represent the chromosome of the regional parents.
And these are their two lines.
Each represents the combination.
We are applying the cross over function.
And now we need to access the new population list.
Let's set bands.
The new individuals, children position zero.
And then we can apply the mutation in order to change some of the genes.
Let's send the here mutation probability new population dots, bands, children position one again mutation,
and let's send the here mutation probability.
Let's run this code again.
We can see the massagers related to the mutation.
For example, let's review this first execution.
We are selecting solution number three of the original population.
It is this chromosome here and solution our individual number nine, which is the first chromosome here.
Then we apply crossover.
And as a result, we have these two combinations here.
We are combining three with nine.
Then we are applying mutation with one percent probability.
We have a before and after.
We can see that it was a curated for our children.
Number one, the original value was zero.
And then we change its H1 and then you can see all the results here, according to the individuals that
were selected.
And this is how you can create a new generation.
However, that codes is creating only one new generation, and we need to create several new generations.
So in the next lecture, we are going to start working with this stop being reburial so we can define
the number of generations that we may use in order to have the final result of the genetic algorithm.
So there?