1
00:00:00,150 --> 00:00:07,580
Hello and welcome to this lecture, where we are going to solve the flight schedule problem using the

2
00:00:07,710 --> 00:00:08,430
library.

3
00:00:08,610 --> 00:00:18,430
Let's start by defining the toolbox to initialize the library Bayes dots to box.

4
00:00:18,870 --> 00:00:23,400
Then we need to create the fitness function and also the individual.

5
00:00:23,910 --> 00:00:24,770
Let's go.

6
00:00:25,190 --> 00:00:36,750
Greater blots create a yellowing needs to type fitness meme because we have a minimization problem.

7
00:00:37,050 --> 00:00:41,100
We need to get the lowest possible price.

8
00:00:41,580 --> 00:00:47,550
Then we need to type base, but fitness again.

9
00:00:47,970 --> 00:00:57,120
We have with the weights and as we have on minimization problem, we need to put two here minus one

10
00:00:57,510 --> 00:01:02,850
when we have a maximization problem, which puts positive one.

11
00:01:03,870 --> 00:01:14,880
Now let's create the individual's grade through dots, create the name of the class individual.

12
00:01:15,570 --> 00:01:19,620
It will be in the format of a list the next.

13
00:01:21,660 --> 00:01:32,520
Fitness equals greater dot fitness min again because we have a minimization problem.

14
00:01:33,000 --> 00:01:35,760
Now we need to register some objects.

15
00:01:36,660 --> 00:01:43,890
The box dots register before we had a Boolean attributes.

16
00:01:44,250 --> 00:01:56,280
Now we have three composed of integer values because as we can see here in the solution, it is composed

17
00:01:56,310 --> 00:02:07,410
of numbers in the range from zero to nine because that are then available flights for each one of this

18
00:02:07,410 --> 00:02:08,040
series.

19
00:02:08,670 --> 00:02:12,960
So now we need to define an integrate attribute.

20
00:02:13,410 --> 00:02:23,970
Let's go again random wrens eons to generate the random numbers and that are two other parameters a

21
00:02:24,450 --> 00:02:28,020
zero and B equals nine.

22
00:02:28,350 --> 00:02:35,550
It means the generated random numbers will be in this range from zero to nine.

23
00:02:36,150 --> 00:02:40,500
Let's keep registering other objects.

24
00:02:41,040 --> 00:02:51,660
The next one individual those dots init repeat to generate random individuals.

25
00:02:52,170 --> 00:02:55,560
Greater thoughts individual.

26
00:02:56,130 --> 00:02:59,770
Let's call it bluebox dots.

27
00:03:00,650 --> 00:03:04,260
A data are aeons the same.

28
00:03:04,260 --> 00:03:17,430
We defined the year in this last line of code and now an equals 12 because there are 12 options, as

29
00:03:17,430 --> 00:03:18,750
we can see here.

30
00:03:19,410 --> 00:03:24,870
The next step is to register the population.

31
00:03:25,440 --> 00:03:29,300
Let's type population again.

32
00:03:29,880 --> 00:03:33,660
Those in need repeats.

33
00:03:35,080 --> 00:03:45,130
The population will be in the four of a list and it will be a population of individuals, according

34
00:03:45,130 --> 00:03:48,640
to the name given in these line here.

35
00:03:49,000 --> 00:03:58,750
Now we needs to register the order parameter, how we are going to evaluate the algorithm.

36
00:03:59,080 --> 00:04:03,220
Let's just type fitness function deep.

37
00:04:03,490 --> 00:04:13,570
The function we created last lecture that returns the total price of the flights, the next one, the

38
00:04:13,570 --> 00:04:17,260
box registered mate.

39
00:04:17,620 --> 00:04:30,310
The way we will apply the cross over again, we will use cross over one point, the next one, how we

40
00:04:30,310 --> 00:04:35,170
are going to perform the mutation new bait.

41
00:04:35,970 --> 00:04:45,250
Those but most flip bits in this case, here we can just change the values.

42
00:04:45,520 --> 00:04:53,530
For example, if it is three, maybe we can change use to seven two eight two nine.

43
00:04:53,920 --> 00:05:02,110
As we have more options, we can change to any integer value in the range from 029.

44
00:05:02,410 --> 00:05:10,780
And let's specify here the probability of mutation, for example, only one percent.

45
00:05:11,530 --> 00:05:20,350
The next one to box not register how we are going to select the best individuals.

46
00:05:20,770 --> 00:05:33,670
And before we were using this sale roulette, however, this method is used only for maximization problems.

47
00:05:34,030 --> 00:05:39,910
As in this particular case study, we have a minimization problem.

48
00:05:40,150 --> 00:05:49,870
We need to use order type of selection and there is one very famous, which is called star ornaments.

49
00:05:50,230 --> 00:05:54,280
We will use these authors selection technique.

50
00:05:54,700 --> 00:06:07,750
Then let's create the population equals tool box thought population and equals five hundred.

51
00:06:08,080 --> 00:06:15,790
This is the population size, as this problem has more data than the transplants of the products.

52
00:06:16,030 --> 00:06:23,710
We heeds a higher number here, and after executing the algorithm, you can choose other options.

53
00:06:24,370 --> 00:06:29,100
Let's create another variable crossover probability.

54
00:06:29,360 --> 00:06:43,030
I will set it to 70 percent and mutation probability to 30 percent, and the number of generations will

55
00:06:43,030 --> 00:06:45,220
be equal to 100.

56
00:06:45,460 --> 00:06:49,240
You can try other parameters and see the results.

57
00:06:49,690 --> 00:07:00,800
Finally, I will just based a code to hear the definition of the statistics and also these last bards.

58
00:07:00,820 --> 00:07:03,610
That's a short run, the algorithm.

59
00:07:03,910 --> 00:07:09,790
Again, we are calling it a simple and just correct here.

60
00:07:10,180 --> 00:07:12,520
Number of generations.

61
00:07:12,910 --> 00:07:14,800
Let's run this codes.

62
00:07:15,460 --> 00:07:24,280
There is one missing parameter when we are calling the tournaments, which is the dance size.

63
00:07:24,580 --> 00:07:28,390
Let's specify three, which is the default value.

64
00:07:28,900 --> 00:07:30,460
Run this code again.

65
00:07:30,670 --> 00:07:35,090
And finally, we can see the genetic algorithm running.

66
00:07:35,470 --> 00:07:46,570
We can see the first generation see that the minimum price was one thousand nine hundred and fifty six.

67
00:07:46,960 --> 00:07:56,260
And we can see that after the generations after running the genetic algorithms, we could find this

68
00:07:56,260 --> 00:07:57,430
value here.

69
00:07:57,670 --> 00:08:09,340
So the cost of all airline tickets for the round trip for all people would be this one here one thousand

70
00:08:09,430 --> 00:08:12,090
five hundred and sixty six.

71
00:08:12,460 --> 00:08:15,130
Again, this is a minimization problem.

72
00:08:15,400 --> 00:08:18,730
We can select the best individual.

73
00:08:19,180 --> 00:08:20,260
Less great.

74
00:08:20,740 --> 00:08:28,840
Best solution equals those dots sell best population.

75
00:08:29,380 --> 00:08:32,380
I want to select only one individual.

76
00:08:32,770 --> 00:08:34,420
Let's go through this.

77
00:08:34,460 --> 00:08:38,620
Solution and best solution.

78
00:08:39,010 --> 00:08:51,760
Unless friends, the individual and also lets brands individual got fitness here, we can see the flights

79
00:08:51,760 --> 00:08:53,410
that were chosen.

80
00:08:53,890 --> 00:08:56,710
And you see it in a bad way.

81
00:08:56,740 --> 00:09:04,480
We can call brilliance Kegel and let's sans as parameter the individual.

82
00:09:04,810 --> 00:09:06,460
Let's run this code.

83
00:09:06,790 --> 00:09:15,490
You can see here that we have a bad visualization, and it happened because they change the dysfunctional

84
00:09:15,490 --> 00:09:16,630
brain schedule.

85
00:09:16,960 --> 00:09:23,260
I just bought some additional spaces here should be more organized.

86
00:09:23,620 --> 00:09:33,610
We can see the ship flights from Lisbon to Rome and also the cheapest flight from Rome to Liverpool.

87
00:09:33,880 --> 00:09:44,830
And this value here is this sum of all the prices from this series to Rome in this column here and from

88
00:09:44,830 --> 00:09:49,810
Rome to each one of the other cities in this column here.

89
00:09:50,110 --> 00:09:57,640
And again, you can run this code a couple of times to get different results.

90
00:09:58,120 --> 00:10:01,660
Let's check what was the best value.

91
00:10:02,110 --> 00:10:09,790
See that we have exactly the same as before, and in the next lecture, we are going to solve the same

92
00:10:09,790 --> 00:10:13,030
problem using Melrose Library.

93
00:10:13,300 --> 00:10:13,960
See you there!
