Hello and welcome to this lecture, where we are going to finish their representation of the flight
schedule problem, in my opinion, this is the most difficult part when working with genetic AH optimization
algorithms because you need to find a way to represent is a problem than you sand the date that should
the genetic algorithm.
We already have this variable here, which is composed of all flights.
You just a reminder we need a flight from Lisbon to Rome and from Rome to Lisbon.
Each city needs two flights as there are six people are sick.
See this we needs two flights for each one of them in order to represent its weekend defined in this
way here.
Schedule and some integers values, as we saw before, that are than options from Rome to each one of
these cities, and also better than options from each one of these cities to Rome, as the indexes in
by one starts at zero.
We have position zero one two three four five six seven eight nine.
So we need to generate integers numbers from zero to nine.
For example, we can consider that in these two positions, we have the first flights.
For example, let's take a look here.
That's the first person is Lisbon.
So in these two flights and this number one here means that we are going to take this second flight
of the day from Lisbon to Rome.
We can see here flight zero and fly to one.
It means the costs of that flight will be 200s and 9s thin.
And on the order hands, we will take the third flights from Rome to Lisbon.
We can see here position zero position when and positioned to the cost.
Our price is two hundred and then.
And regarding these odds are bearer of values.
They are related should this second person, which is Madrid's, so we can take a look at the data here.
I will just copy and paste this code here from Madrid to FCO and also from our CEO to Madrid run both
codes to have access to the data.
We will select flight number three, which means the Ford Fly half of the day from Madrid.
Rome position zero one two three four.
We will select these flights and the price is one hundred and thirty four and we will select the third
flights from Rome to Madrid's position zero, position one and position.
Q. The price is one hundred and seventy two, so we need to add both values to have the total price
remembering again that the goal is to select the cheapest flights.
And regarding this number seven and three, we will select flight number eight of the day from Paris
to Rome and on the order hands, we will select the four flights from Rome to Paris, and the order
pairs of values means this same for each one of this series we can type here.
Length schedule There are 12 positions and we can also divide this.
No geggel divided by.
Just correct here.
Length scare you.
The result is six.
We can put an additional bar here because see, that's the value is a float number.
And when we boards two bars, the result is an even bigger number.
So it means we need to create a for loop to go through this list here.
But we don't need to go for all positions.
We need to run the four loop only six times.
The first time is to select the flights for the first person.
This second time, should this second person, this third time, should the third person and so on.
So now will we implement a new function brand's schedule it will receive as a parameter?
This schedule, the first variable will be Flight Aidid, which will be initialized as minus one.
We will keep incrementing this variable during the FA loop.
Let's also create the total price, which will be initialized with zero.
Now let's implement a for loop for I in range.
Let's get you divided by two.
We can create the name variable.
Let's access the people variable position I and zero should Badger understands.
Let's brings the name here.
Let's call the function Brent's schedule, and I will.
Sand's the variable with these positions here.
Run this code.
We can see that we got the name of each one of this series.
We are accessing position number zero because the name of the person is in position zero.
In position one, we can see the name of the airports.
Now we need to get the origin, which is the name of the airports people position.
I call them zero.
We can also brands our engine just to.
Badger understands how we'll skip the line here just to be easier to visualize.
Run this code.
We can see here the name of the person and the name of the airport for each one of them.
Now we can increment flights 18 plus equal when this variable will be used to go through each one of
the indexes at the first execution.
The value is initialized with minus one.
And then we increment to zero.
So it means we will access position zero.
Now we can get the flights from this city to Rome and we will create the variable going.
Let's access flights and our code here.
Our engine and destiny and here schedule.
Let's Booth's flight I.D..
We can.
Brent's going just to see the partial results run this codes.
We can take a look at the flights and we will just put these codes and both here at the.
It will be easier to visualize run these codes and then we can see the corresponding flights for the
order series.
Now let's increment the total price plus equal going position two, because in this position, we can
access the price after increment in the price when needs to increment flights I.D. Plus equal one,
because that's the first is a crucial.
We take this flight from this city to Rome and now we need to access this other flights from Rome to
this city so we can create a model.
Variable returnee, let's access the flight data sets, and we will just change here, destiny and origin
and again scared you, whose initial flights I did, then we can increment the total price plus eco
returning position.
So just to make sure position zero, position one and in position two, we can get the price.
I will put all these brands in comments.
And finally, we can bring to this schedule.
We can both hear the name of the person they are enjoying going position zero, which is the departure
time going position one, which is their arrival time and going position two, which is the price.
Then we can both here returning zero, returning position one and returning position two and after default,
we can brings the total price of the solution, though the price variable.
Now we can run this code's brand disgaggio.
There's one Ihor where a flight idea there is a typo here.
Just change the order room again, and now we can see the final results, for example, from Lisbon
to run.
It is this flight here and from Rome to Lisbon, then from Madrid's Joram and from Rome to Madrid's.
And this value here is this sum of each one of these prices here.
The prices to go from this see the each room and from wrong to each one of this series, and we are
printing these solutions here.
And the goal of the genetic algorithm is to find these numbers here.
For example, we can't write to put zero here.
Let's recreate this variable and quote again, the brain's Kegel function.
See, that's the result is quite a difference.
The goal is to find the best sets of flights in order to minimize the total price.
Now that you understood how to represent the problem, we need to create a defeat in this function,
which will be similar to the brain's schedule.
We will use this function just to show the results, as the codes of the fitness function is quite similar
to this one.
Here are we all just based its fitness function deep.
We were seen as a barometer.
This sketch you'll see that the variables are the same.
We are going through each one of the people getting each one of the flights, and we are adding the
total price and we will just returns total price.
Here we have a function for deep library and then the other function for AM rows.
I will just based the code here because when we work with dip, we need to put this comma here and when
working with arrows, we don't need it.
So we will define social functions to be easier to understand.
Less great both fit in fitness function and in the next lecture, we will implement the genetic algorithm
using deep library.
See you there!