what does line9 ( Newsol.x=p​op(S).x.*(​1-Cr)+sol.​x.*Cr; ) do?

1 Ansicht (letzte 30 Tage)
hossein moradi
hossein moradi am 25 Okt. 2016
Bearbeitet: Ganesh Hegade am 25 Okt. 2016
1- function sol=CrossOver(Kw_Kgb,gpop,sol,nvar,pop,data) 2- Newsol=sol; 3- Npop=length(pop); 4- C_rate = 0.8 + 0.2*(sol.fit-gpop.fit)/Kw_Kgb; 5- Cr = rand(1,nvar) < C_rate ; 6- % Random selection of Krill No. for Crossover 7- S = randi([1 Npop]); 8- % Crossover scheme 9- Newsol.x=pop(S).x.*(1-Cr)+sol.x.*Cr; 10- Newsol=fitness(Newsol,data);
11- if Newsol.fit<sol.fit 12- sol=Newsol; 13- end
14- end

Antworten (1)

Ganesh Hegade
Ganesh Hegade am 25 Okt. 2016
Bearbeitet: Ganesh Hegade am 25 Okt. 2016
Hi,
Line number 9 just assigns new vales to Newsol.x. It means the output sol.x will have a new value (Newsol.x)
function sol=CrossOver(Kw_Kgb,gpop,sol,nvar,pop,data)
Newsol=sol;
Npop=length(pop);
C_rate = 0.8 + 0.2*(sol.fit-gpop.fit)/Kw_Kgb;
Cr = rand(1,nvar) < C_rate ;
% Random selection of Krill No. for Crossover
S = randi([1 Npop]);
% Crossover scheme
Newsol.x=pop(S).x.*(1-Cr)+sol.x.*Cr;
Newsol=fitness(Newsol,data);
if Newsol.fit<sol.fit
sol=Newsol;
end
end

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by