Hello and welcome to this lecture, where you are going to understand the theory and also implement
the evaluation or defeat the mis function, which is a measure of quality to is how goods each chromosome
is or how well the chromosome solves the problem.
Remembering that the chromosome is this sets off ones and zeros.
That's indicates whether you will load the products on the truck, and we need to evaluate whether it
is an acceptable solution and if it can be used in the future or in the next two generations.
You can see this here much again, in which we have the indication of the products that we are going
to load on truck.
Zero indicates that we are not going to load the product and one indicates that we are going to load
the product.
The question is how are we going to evaluate this individual?
Are these chromosome as we have a maximization problem?
The goal is to maximize the profits based on the price of the products.
So we need to load products that this some of their prices is as high as possible, making the best
possible use of the space available in the truck, selecting all these products here.
The total value is ten thousand eight hundred fifty six dollars and 48 cents, and the total space occupied
by Dan is one point seventy six.
It is not a very good solution because the capacity of the truck is three and we are only using one
point seventy six, so we could load more products and have higher values.
In short, the evaluation function will go through each of the products, adding up the prices and space
is occupied by each one Indians.
The solutions that have the highest prices and that do not exceed the space limits will be see, they
are the best and we got the total value by adding each one of the prices of the selected products.
Now let's go back to the Google CoLab file and we will implement a new function inside the individual
class, their fitness.
It wont receive any parameter.
I will create a new variable squared equals zero and some spaces equals zero.
This car variable will start this number here and this.
Some spaces will start, though, though cubic meters.
Now we need to go through each one of the products.
For I in range length Cell Dot's chromosome, we are going through each one of these zeros and ones
I will implement and if statement if self Dot's chromosome was issue, I equals one.
It means we selected the products.
Then we can access this core variable plus equal self thoughts crisis position i.e. we are accessing
these attributes here and we are doing the values.
This core value will start this sum of all prices of this select its products.
We will do something very similar should this order variable some spaces, plus equal cell spaces positioned
high.
It is these parameter that we are sending when we create the individual.
When we finish executing this far loop, we will have four.
These values, the total price and the total cubic meters, but the truck has a limited space, which
is three in this case study, so we need to input and if statements, if some space is greater than
self space limits, it means that it won't be possible to load the products regarding this solution
since there is lots available space in the truck.
If it happens, this car will be reduced to only one.
So it means that if we are not able to load the products of this solution, this car will be very bad,
very small number.
So we want to use this solution in the other generations.
For example, this solution here, the sense exceeds the maximum capacity and the total value is 10000.
And if we exceeds the capacity of the truck, this told no value will be equal to one.
This is a way to discard this solution because the products cannot be loaded on the truck.
And though we need to store both values on the objects, and in order to do that, we can create two
new attributes self bots score evaluation equals zero.
The initialization of the object and also sells used space equals zero.
Now we can just view these attributes here.
According to the calculations, self scoring evaluation equals score, and self use space equals some
space.
Now we can create again the individual glass.
We can go to this part here and let's perform some tests after creating the individual.
We can call the fitness function individual thoughts, fitness.
Let's run the scalds.
See that one air was returns because we need to put self here the default parameter in Python.
Let's recreate the function.
Call it it's again, we can see another error.
Some space is not defined because the name of the variable is some spaces correct?
Here, create the function again.
Run the codes, and now we can see this same results.
Let's take a look at the values of the new attributes of the glass.
I will print this card off the social card, though no price.
Let's access in this video score evaluation.
The new attributes we can also prints the users space individual one dots use space.
Let's run this set of codes.
Take a look here.
That's this card is eleven thousand dollars and they used space is two point forty.
Let's run again.
Then thousands.
Seventeen thousand.
See, that's it's also used all the space available in the truck.
Let's run more times.
We can see the values here.
Every time we run this code, we will have different values.
Take a look at these solutions here.
If we load refrigerator, a TV 55 ventilator, microwaves B and C, refrigerator C and Notebook C,
they used space is three point thirteen.
So it's greater than the limits of the truck.
So it is impossible to load all these products together.
So it is a bad solution.
And this car of its is only one because of these if state we implement as before.
And that's how we can evaluate each one of these solutions.
And in the next lecture, we will continue the implementation.
See you there.