Hello and welcome to this lecture, where we are going to generate a graph to better visualize the results
going back to our genetic algorithm glass.
We can see these attributes list of solutions.
It was initialized as an empty list and now we are going to put in each position of the list.
The best solutions are the best individual in each one of the generations.
Let's go back to our sole function and after our during the population, we will access our attributes.
Based solution equals self population in position zero.
After we are order, we know that the best solution is in this position and we are starting needs in
these three boat here.
Then we will access our new lists.
Self thoughts.
List of solutions.
Thoughts of bands.
Self based solution.
Thoughts.
Score evaluation.
So we are adding to the list.
The best solution of the first generation.
And then after setting the best solution regarding the other generations, we will access again our
list of solutions.
Thoughts up bands.
And again, let's specify here best thoughts.
Our evaluation, which is the total price.
Let's run this code again, should create the glass.
Run this part of the code again to have the solutions.
Basically, this code Winkler meant it's now is a story.
Each one of these values here we can see that's the best solution is in generation number 20.
Let's open a new set of codes just to make sure the variable was created correctly.
Let's implement that for a loop for our value in genetic algorithm.
List of solutions and let's Bryants the values.
As we can see here, we have the list of the best individuals regarding each one of the generations.
Now let's go to the graph boards bloodily boards xpress aspects.
This is a very nice library to work with graphs, and by then I will create a Figure B X dots line.
It is a line graph in the x axis.
We will puts the range from zero to one hundred and one, so it will goes from zero to 100 because that
are 100 generations and regarding y axis genetic algorithm.
List of solutions we can specify the title of the graph.
For example, genetic algorithm results.
Finally, lets type your lot show to see the results.
Let's run these codes, and now you can see a very nice graph showing all the results.
For example, generation zero, their result was nine then generation 20, which was the best one twenty
four thousand.
In other generations, for example, thirty two, we have the results and then you can follow their
values in order to check the results.
We can also run this code again every time you run this code.
You will get different results.
Now, the best one was found on generation nine to one.
Let's run this code again.
Just see the new graph.
It is quite different from the other one.
And this graph is very useful, especially when you.
Run the called for margin operations, for example, 5000, 10000 generations, so you can easily find
where the best solution is.
And I encourage you to change this parameters.
For example, if you are working in a real world problem regarding trucks, you can change these limits
here.
According to the size of the truck, and you can also add more products here.
Change the population, size the number of generations and so on.
As this problem is quite small, there are only Fardeen products when running this code for only 100
generations, we can get good results.
However, if you are working in our real world projects, maybe you need to change its parameters,
increasing the population size and also the number of generations.
And that's all for this lecture.
See you next time.