Hello and welcome to this lecture, where we are going to solve the flight schedule problem using the
library.
Let's start by defining the toolbox to initialize the library Bayes dots to box.
Then we need to create the fitness function and also the individual.
Let's go.
Greater blots create a yellowing needs to type fitness meme because we have a minimization problem.
We need to get the lowest possible price.
Then we need to type base, but fitness again.
We have with the weights and as we have on minimization problem, we need to put two here minus one
when we have a maximization problem, which puts positive one.
Now let's create the individual's grade through dots, create the name of the class individual.
It will be in the format of a list the next.
Fitness equals greater dot fitness min again because we have a minimization problem.
Now we need to register some objects.
The box dots register before we had a Boolean attributes.
Now we have three composed of integer values because as we can see here in the solution, it is composed
of numbers in the range from zero to nine because that are then available flights for each one of this
series.
So now we need to define an integrate attribute.
Let's go again random wrens eons to generate the random numbers and that are two other parameters a
zero and B equals nine.
It means the generated random numbers will be in this range from zero to nine.
Let's keep registering other objects.
The next one individual those dots init repeat to generate random individuals.
Greater thoughts individual.
Let's call it bluebox dots.
A data are aeons the same.
We defined the year in this last line of code and now an equals 12 because there are 12 options, as
we can see here.
The next step is to register the population.
Let's type population again.
Those in need repeats.
The population will be in the four of a list and it will be a population of individuals, according
to the name given in these line here.
Now we needs to register the order parameter, how we are going to evaluate the algorithm.
Let's just type fitness function deep.
The function we created last lecture that returns the total price of the flights, the next one, the
box registered mate.
The way we will apply the cross over again, we will use cross over one point, the next one, how we
are going to perform the mutation new bait.
Those but most flip bits in this case, here we can just change the values.
For example, if it is three, maybe we can change use to seven two eight two nine.
As we have more options, we can change to any integer value in the range from 029.
And let's specify here the probability of mutation, for example, only one percent.
The next one to box not register how we are going to select the best individuals.
And before we were using this sale roulette, however, this method is used only for maximization problems.
As in this particular case study, we have a minimization problem.
We need to use order type of selection and there is one very famous, which is called star ornaments.
We will use these authors selection technique.
Then let's create the population equals tool box thought population and equals five hundred.
This is the population size, as this problem has more data than the transplants of the products.
We heeds a higher number here, and after executing the algorithm, you can choose other options.
Let's create another variable crossover probability.
I will set it to 70 percent and mutation probability to 30 percent, and the number of generations will
be equal to 100.
You can try other parameters and see the results.
Finally, I will just based a code to hear the definition of the statistics and also these last bards.
That's a short run, the algorithm.
Again, we are calling it a simple and just correct here.
Number of generations.
Let's run this codes.
There is one missing parameter when we are calling the tournaments, which is the dance size.
Let's specify three, which is the default value.
Run this code again.
And finally, we can see the genetic algorithm running.
We can see the first generation see that the minimum price was one thousand nine hundred and fifty six.
And we can see that after the generations after running the genetic algorithms, we could find this
value here.
So the cost of all airline tickets for the round trip for all people would be this one here one thousand
five hundred and sixty six.
Again, this is a minimization problem.
We can select the best individual.
Less great.
Best solution equals those dots sell best population.
I want to select only one individual.
Let's go through this.
Solution and best solution.
Unless friends, the individual and also lets brands individual got fitness here, we can see the flights
that were chosen.
And you see it in a bad way.
We can call brilliance Kegel and let's sans as parameter the individual.
Let's run this code.
You can see here that we have a bad visualization, and it happened because they change the dysfunctional
brain schedule.
I just bought some additional spaces here should be more organized.
We can see the ship flights from Lisbon to Rome and also the cheapest flight from Rome to Liverpool.
And this value here is this sum of all the prices from this series to Rome in this column here and from
Rome to each one of the other cities in this column here.
And again, you can run this code a couple of times to get different results.
Let's check what was the best value.
See that we have exactly the same as before, and in the next lecture, we are going to solve the same
problem using Melrose Library.
See you there!