1
00:00:00,240 --> 00:00:07,790
Hello and welcome to this lecture, where we are going to finish their representation of the flight

2
00:00:07,850 --> 00:00:17,250
schedule problem, in my opinion, this is the most difficult part when working with genetic AH optimization

3
00:00:17,250 --> 00:00:25,830
algorithms because you need to find a way to represent is a problem than you sand the date that should

4
00:00:25,830 --> 00:00:27,330
the genetic algorithm.

5
00:00:27,750 --> 00:00:34,470
We already have this variable here, which is composed of all flights.

6
00:00:34,710 --> 00:00:42,840
You just a reminder we need a flight from Lisbon to Rome and from Rome to Lisbon.

7
00:00:43,290 --> 00:00:50,310
Each city needs two flights as there are six people are sick.

8
00:00:50,320 --> 00:01:01,950
See this we needs two flights for each one of them in order to represent its weekend defined in this

9
00:01:01,950 --> 00:01:02,910
way here.

10
00:01:03,310 --> 00:01:14,790
Schedule and some integers values, as we saw before, that are than options from Rome to each one of

11
00:01:14,790 --> 00:01:25,500
these cities, and also better than options from each one of these cities to Rome, as the indexes in

12
00:01:25,500 --> 00:01:28,320
by one starts at zero.

13
00:01:28,620 --> 00:01:37,980
We have position zero one two three four five six seven eight nine.

14
00:01:38,280 --> 00:01:43,980
So we need to generate integers numbers from zero to nine.

15
00:01:44,400 --> 00:01:53,430
For example, we can consider that in these two positions, we have the first flights.

16
00:01:53,790 --> 00:01:56,760
For example, let's take a look here.

17
00:01:56,940 --> 00:01:59,760
That's the first person is Lisbon.

18
00:02:00,000 --> 00:02:10,950
So in these two flights and this number one here means that we are going to take this second flight

19
00:02:10,950 --> 00:02:14,430
of the day from Lisbon to Rome.

20
00:02:14,850 --> 00:02:20,220
We can see here flight zero and fly to one.

21
00:02:20,520 --> 00:02:26,400
It means the costs of that flight will be 200s and 9s thin.

22
00:02:27,000 --> 00:02:35,760
And on the order hands, we will take the third flights from Rome to Lisbon.

23
00:02:35,970 --> 00:02:43,770
We can see here position zero position when and positioned to the cost.

24
00:02:44,130 --> 00:02:47,760
Our price is two hundred and then.

25
00:02:48,390 --> 00:02:52,740
And regarding these odds are bearer of values.

26
00:02:53,520 --> 00:03:02,490
They are related should this second person, which is Madrid's, so we can take a look at the data here.

27
00:03:03,000 --> 00:03:23,580
I will just copy and paste this code here from Madrid to FCO and also from our CEO to Madrid run both

28
00:03:23,580 --> 00:03:26,280
codes to have access to the data.

29
00:03:26,670 --> 00:03:36,200
We will select flight number three, which means the Ford Fly half of the day from Madrid.

30
00:03:36,300 --> 00:03:41,640
Rome position zero one two three four.

31
00:03:41,940 --> 00:03:52,110
We will select these flights and the price is one hundred and thirty four and we will select the third

32
00:03:52,230 --> 00:04:00,740
flights from Rome to Madrid's position zero, position one and position.

33
00:04:00,760 --> 00:04:12,930
Q. The price is one hundred and seventy two, so we need to add both values to have the total price

34
00:04:13,320 --> 00:04:18,720
remembering again that the goal is to select the cheapest flights.

35
00:04:19,170 --> 00:04:30,630
And regarding this number seven and three, we will select flight number eight of the day from Paris

36
00:04:30,630 --> 00:04:43,410
to Rome and on the order hands, we will select the four flights from Rome to Paris, and the order

37
00:04:43,410 --> 00:04:51,270
pairs of values means this same for each one of this series we can type here.

38
00:04:51,660 --> 00:04:59,570
Length schedule There are 12 positions and we can also divide this.

39
00:04:59,670 --> 00:05:02,580
No geggel divided by.

40
00:05:03,840 --> 00:05:05,360
Just correct here.

41
00:05:05,670 --> 00:05:07,500
Length scare you.

42
00:05:08,100 --> 00:05:10,380
The result is six.

43
00:05:10,650 --> 00:05:17,370
We can put an additional bar here because see, that's the value is a float number.

44
00:05:17,670 --> 00:05:22,950
And when we boards two bars, the result is an even bigger number.

45
00:05:23,430 --> 00:05:30,540
So it means we need to create a for loop to go through this list here.

46
00:05:30,840 --> 00:05:35,760
But we don't need to go for all positions.

47
00:05:35,970 --> 00:05:40,260
We need to run the four loop only six times.

48
00:05:40,860 --> 00:05:45,990
The first time is to select the flights for the first person.

49
00:05:46,470 --> 00:05:54,330
This second time, should this second person, this third time, should the third person and so on.

50
00:05:54,810 --> 00:06:04,320
So now will we implement a new function brand's schedule it will receive as a parameter?

51
00:06:04,740 --> 00:06:14,820
This schedule, the first variable will be Flight Aidid, which will be initialized as minus one.

52
00:06:15,120 --> 00:06:19,410
We will keep incrementing this variable during the FA loop.

53
00:06:19,950 --> 00:06:27,090
Let's also create the total price, which will be initialized with zero.

54
00:06:27,660 --> 00:06:33,000
Now let's implement a for loop for I in range.

55
00:06:33,670 --> 00:06:39,150
Let's get you divided by two.

56
00:06:39,960 --> 00:06:42,750
We can create the name variable.

57
00:06:43,050 --> 00:06:52,080
Let's access the people variable position I and zero should Badger understands.

58
00:06:52,560 --> 00:06:55,350
Let's brings the name here.

59
00:06:55,890 --> 00:07:00,720
Let's call the function Brent's schedule, and I will.

60
00:07:00,720 --> 00:07:05,020
Sand's the variable with these positions here.

61
00:07:05,520 --> 00:07:06,750
Run this code.

62
00:07:06,990 --> 00:07:11,940
We can see that we got the name of each one of this series.

63
00:07:12,390 --> 00:07:20,820
We are accessing position number zero because the name of the person is in position zero.

64
00:07:21,030 --> 00:07:25,500
In position one, we can see the name of the airports.

65
00:07:26,280 --> 00:07:35,080
Now we need to get the origin, which is the name of the airports people position.

66
00:07:35,910 --> 00:07:38,550
I call them zero.

67
00:07:38,880 --> 00:07:43,140
We can also brands our engine just to.

68
00:07:43,140 --> 00:07:49,830
Badger understands how we'll skip the line here just to be easier to visualize.

69
00:07:50,430 --> 00:07:51,750
Run this code.

70
00:07:52,080 --> 00:07:59,130
We can see here the name of the person and the name of the airport for each one of them.

71
00:07:59,790 --> 00:08:12,360
Now we can increment flights 18 plus equal when this variable will be used to go through each one of

72
00:08:12,360 --> 00:08:15,860
the indexes at the first execution.

73
00:08:16,170 --> 00:08:20,160
The value is initialized with minus one.

74
00:08:20,460 --> 00:08:23,670
And then we increment to zero.

75
00:08:23,880 --> 00:08:27,990
So it means we will access position zero.

76
00:08:28,650 --> 00:08:36,270
Now we can get the flights from this city to Rome and we will create the variable going.

77
00:08:36,690 --> 00:08:41,610
Let's access flights and our code here.

78
00:08:42,450 --> 00:08:48,630
Our engine and destiny and here schedule.

79
00:08:49,140 --> 00:08:53,010
Let's Booth's flight I.D..

80
00:08:53,580 --> 00:08:54,210
We can.

81
00:08:54,210 --> 00:09:01,620
Brent's going just to see the partial results run this codes.

82
00:09:02,160 --> 00:09:10,410
We can take a look at the flights and we will just put these codes and both here at the.

83
00:09:11,010 --> 00:09:18,780
It will be easier to visualize run these codes and then we can see the corresponding flights for the

84
00:09:18,790 --> 00:09:19,950
order series.

85
00:09:20,640 --> 00:09:31,440
Now let's increment the total price plus equal going position two, because in this position, we can

86
00:09:31,440 --> 00:09:43,080
access the price after increment in the price when needs to increment flights I.D. Plus equal one,

87
00:09:43,440 --> 00:09:45,780
because that's the first is a crucial.

88
00:09:45,990 --> 00:09:55,680
We take this flight from this city to Rome and now we need to access this other flights from Rome to

89
00:09:55,680 --> 00:09:59,480
this city so we can create a model.

90
00:09:59,600 --> 00:10:10,660
Variable returnee, let's access the flight data sets, and we will just change here, destiny and origin

91
00:10:11,120 --> 00:10:23,000
and again scared you, whose initial flights I did, then we can increment the total price plus eco

92
00:10:23,330 --> 00:10:25,620
returning position.

93
00:10:25,680 --> 00:10:35,060
So just to make sure position zero, position one and in position two, we can get the price.

94
00:10:35,360 --> 00:10:39,230
I will put all these brands in comments.

95
00:10:40,820 --> 00:10:44,590
And finally, we can bring to this schedule.

96
00:10:44,870 --> 00:10:56,240
We can both hear the name of the person they are enjoying going position zero, which is the departure

97
00:10:56,240 --> 00:11:07,550
time going position one, which is their arrival time and going position two, which is the price.

98
00:11:07,730 --> 00:11:22,010
Then we can both here returning zero, returning position one and returning position two and after default,

99
00:11:22,340 --> 00:11:30,260
we can brings the total price of the solution, though the price variable.

100
00:11:30,650 --> 00:11:35,930
Now we can run this code's brand disgaggio.

101
00:11:36,320 --> 00:11:41,840
There's one Ihor where a flight idea there is a typo here.

102
00:11:42,290 --> 00:11:54,050
Just change the order room again, and now we can see the final results, for example, from Lisbon

103
00:11:54,050 --> 00:11:54,860
to run.

104
00:11:55,220 --> 00:12:07,490
It is this flight here and from Rome to Lisbon, then from Madrid's Joram and from Rome to Madrid's.

105
00:12:07,820 --> 00:12:15,410
And this value here is this sum of each one of these prices here.

106
00:12:15,860 --> 00:12:25,340
The prices to go from this see the each room and from wrong to each one of this series, and we are

107
00:12:25,340 --> 00:12:28,070
printing these solutions here.

108
00:12:28,280 --> 00:12:34,460
And the goal of the genetic algorithm is to find these numbers here.

109
00:12:34,790 --> 00:12:39,440
For example, we can't write to put zero here.

110
00:12:40,440 --> 00:12:46,890
Let's recreate this variable and quote again, the brain's Kegel function.

111
00:12:47,250 --> 00:12:50,730
See, that's the result is quite a difference.

112
00:12:51,120 --> 00:13:00,540
The goal is to find the best sets of flights in order to minimize the total price.

113
00:13:01,230 --> 00:13:09,540
Now that you understood how to represent the problem, we need to create a defeat in this function,

114
00:13:09,870 --> 00:13:13,290
which will be similar to the brain's schedule.

115
00:13:13,500 --> 00:13:23,190
We will use this function just to show the results, as the codes of the fitness function is quite similar

116
00:13:23,190 --> 00:13:24,030
to this one.

117
00:13:24,030 --> 00:13:29,280
Here are we all just based its fitness function deep.

118
00:13:29,760 --> 00:13:31,990
We were seen as a barometer.

119
00:13:32,040 --> 00:13:35,760
This sketch you'll see that the variables are the same.

120
00:13:36,000 --> 00:13:44,820
We are going through each one of the people getting each one of the flights, and we are adding the

121
00:13:44,820 --> 00:13:49,650
total price and we will just returns total price.

122
00:13:49,680 --> 00:13:58,260
Here we have a function for deep library and then the other function for AM rows.

123
00:13:58,770 --> 00:14:09,150
I will just based the code here because when we work with dip, we need to put this comma here and when

124
00:14:09,150 --> 00:14:12,600
working with arrows, we don't need it.

125
00:14:12,840 --> 00:14:16,920
So we will define social functions to be easier to understand.

126
00:14:17,490 --> 00:14:26,250
Less great both fit in fitness function and in the next lecture, we will implement the genetic algorithm

127
00:14:26,250 --> 00:14:27,930
using deep library.

128
00:14:28,380 --> 00:14:29,070
See you there!
