Hello, friends.
Today I will tell you how to apply algorithm in life.
You.
For that purpose.
I have a problem that in which our function is ten and 2x1 minus one squared plus 20 x two minus two,
all squared plus 30 and 2x3 minus three all squared.
And the objective function used for minimization, I use this so using particle swarm optimization.
I have to.
Optimize this.
Function.
So in this function we use VSO.
That is a meta heuristic algorithm.
All we know that.
In which population based stochastic search.
We can also call it population based stochastic search.
It is based on birds flocking means in which our you can say how the birds fly in a pattern.
To search out food or to go from one place to another place.
Search for optimum value.
And or here.
And so that is particles from optimization.
Swarm means population of moving particles and flock means moving together in a crowd.
In the.
So we also use search space.
The third space is the range in which the algorithm computes the optimal control variable.
So just.
Go to our function.
So let's say over here.
And to solve this problem.
As you see over here, we have three variables x1x2x3.
So a number of variables M is three population size, let's say 58wx is 0.9 and W mean is 0.4 and acceleration
factor.
I just choose C one and C two is equal to two and the maximum iteration size is 50.
Okay.
So how we can implement this function in lab view?
So for that purpose I just create.
Or here.
This is a code.
For MATLAB.
As you see, the lower bound is 000 and upper boundaries and 1010 means.
Using this loop, we can generate a three course five matrix which contains integer values from 0 to
10.
As you see over here, I got 8919613, five, ten, ten, two, ten, ten, five, eight.
So let's just create a variable.
Add a variable or here, just put this value inside this.
So 891 first value is.
Eight nine.
One second value is.
961.
Then over here.
This is my 961.
Right now I'm just using the values of this PDF only.
After that I also tell you how you can compute another values also.
So right now I'm just using these fixed values.
Fixed values.
Three, five, ten.
Then we have three.
Five.
Then after that, I just use 10 to 10.
10 to 10, and my last row is ten, five, eight.
NW five and eight.
So we can generate this function.
Or you can say this.
Five cores, three metrics using the random number in this function or here, as you see around is used
with RAND command around because Rand command is generate values from 0 to 1.
And over here the limit for this Rand command is from 0 to 10 and using round it will round up my values.
Like if I got 8.153 it will generate only eight.
So over here right now in the lab view, as you see over here, I just create visual positions.
After that I wouldn't want to put.
I want to go to next step over here.
Initialize.
Wait.
So to initialize it, we have to right now.
In this function, we require initial population size.
So initial population is Midas 891 the initial matrix and I want to create initial velocity from it
and we can generate initial velocity using this formula we 2.1 into.
This matrix, you can multiply point two, point three on the basis of your requirement.
Okay.
Right now I'm just using these 2.1.
So I just go to my VA.
In the second step.
I already fixed this.
As you see over here, this is my initial position.
Or you can say initial population.
Then I multiply it with point one.
It will generate my metrics, initial velocity or here.
So when I hit on run button, as you see, I got initial velocity then.
When I got initial velocity, as you see in 2.1 with my initial five into three metrics.
And over here this is my variable x1x2x3.
So I want to generate current position and my current position is x one is called to initial position
with initial velocity like eight plus point eight, it will give me 8.8.
So as you see in the lab view, also I got 8.8 over here, my value is nine nine plus point nine.
I got my current position as you see over here.
Next step.
In the next step.
Over here we have initial population and initial velocity.
Then.
We have to.
Apply our objective function that is used for minimization, that is is to turn into x minus x one all
squared plus 20 2x2 minus.
Two.
All square plus 13.
Two x.
Three minus three.
All square.
So just go to our library function or here, as you see.
Here is my x one variable.
I just separated.
So let's check how we can separate it.
So over here, this is my initial velocity.
And over here, I got my.
Final value that is.
Current position.
This is my current position.
And so using index as a function, I just separate from zeroth column.
I got x one from one column I got x two for.
Second column, I got x three.
So as you see over here, this is my x1x2x3.
So right now I want to put this A, b, c.
And these ABC.
Comes from.
Or here.
So let's put.
This ABC and this ABC are 1020 and 30.
These are these are these constants.
So let's say this is ten, 20 and 30 based on these values, I got the fitness value.
So the fitness value is 91964.9.
Let's check for this function as you see.
1.9649.
It is n.
Multiplication of ten factor.
So over here, if you want to change it 1.9 divided by.
1000 only.
So as you see over here, the values are the same.
Second value is 1.3 to 6.
Or here I got one 3 to 6 basically in the MATLAB.
It is this value scores 1.9649 in two.
Ten plus ten.
E as you see or hear.
1.96 49e +03 E +03 means ten res two three.
So when you multiply this ten days to three with this vector, you got this value that is in.
Okay, so this is how we get this vector.
So from here, this step two is completed.
The objective function or here we have to.
Find out the minimum value, because in this case we have to minimize.
So minimum value is 1.3 to 6.
So second particle we want to work with.
So over here, as you see for each particle, calculate the velocity, new velocity and new position.
So new velocity and new position will be calculated using this formula.
Calculate the velocity v one.
De plus one is equal to w max that is rate vector v i d plus c one that is average.
Correction vector into r1x best minus x plus C to r to g best minus x.
Right.
So from here you have to just apply this formula.
So I just go to my code.
So as you see over here, I got x1x2x3.
Then over here this part will be create or will create our objective function.
As you see over here, this x one minus one, all square is multiplied with ax2 minus two, all square
is multiplied with bx3 minus.
Or you can also change this to constant.
It is up to you.
For this particular function.
These values are fixed.
Then you have to find out the minimum of all these three.
The minimum value will be over here.
As you see, the minimum value is this from here, the minimum value is second one and the indexing
for this is one.
So as you see, index function is V one, because in the live view every iteration starts from zero.
So Siberia's my .99.9, 6.6, 1.1 and subway array for this means velocity is .9.6.1.
In the next phase we have to apply this.
Function.
We have to calculate the velocity and position of the particle.
So to calculate the velocity, I just apply this.
So in this case I just go to phase five or here I want to put the value point nine because maximum value
is as you see or here.
This is one nine and C one and Z two is two.
So just.
Put these values inside this function.
See to.
So when I hit on Run button again, I got.
x1x2x3 OC.
So I just increase the size.
So over here, these values are different from these values because in this case we use random number.
Random number will generate any value from 0 to 1.
And in this case, also in the lab view, random number will generate different values.
So.
From here.
Then we have to.
Apply the pollution for each particle and the solution formula is x i t plus one is to the previous
position plus velocity.
That is the same part and or here in the lab view.
So this is my.
Updated position, as you see.
This is my upgraded position.
And over here, I got new.
Variables x1x2x3.
And from here again, we have to find out the fitness value.
And as you see from here, the minimum value is.
One five, six, nine.
But.
If you want to.
Check or if you want to compare this fitness value, the fitness tool and fitness or here I got fitness
one.
This value is less so both from it will compare from fitness one with fitness two and which value is
less because the function is minimization.
It will check best over here.
And my best is this 136 as you see.
And my best is 9.9, 6.61.1.
So using this, my final updated positions are this and initial positions are these as you see.
So this is how you can or if you want to go through the video.
So step by step.
Again, we have to calculate using about our particular formula.
So it will compare new fitness values.
And from here, as you see our fitness value, initial fitness value, it will compare with.
Future fitness value and it will generate best value.
These are the best value as you see from this value and this value, this one is less.
It will take it from this value and this value.
This one is less.
So it will take this from this value and this value it will.
It is less so it will take this one.
So mistakenly it is 7.217.
It is 2.2179.
So as you see which one is less, it will take its position.
So as you see from here, the.
Initial positions are these and updated positions are these initial positions are 8.8, 9.91.1.
But the new fitness value for particular one is updated.
So the positions are 9.8652.
So using this, you can apply the BSO in live view.
So this is how you can apply.
So we just create these functions and lab view.
So this will apply.
Your particle swarm optimisation minimization problem.
And you.
So this is all about.
So leave you.
Thank you.