📄 mohureal1117.asv
字号:
% sga
%
% This script implements the Simple Genetic Algorithm described
% in the examples section of the GA Toolbox manual.
%
% Author: Andrew Chipperfield
% History: 23-Mar-94 file created
global rin yout timef
NIND =50; % Number of individuals per subpopulations
MAXGEN = 100; % maximum Number of generations
GGAP = .9; % Generation gap, how many new individuals are created
% Build field descriptor
% FieldD = [0 0 0;1 1 1];
FieldD = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
% Initialise population
Chrom = crtrp(NIND, FieldD);
% Chrom=rep([0.8 0.75 0.6 0.1 0.2 0.2],[NIND,1]);
% Reset counters
Best = NaN*ones(MAXGEN,1); % best in current population
gen = 0; % generational counter
% Evaluate initial population
ObjV = mohupidobj1117(Chrom);
% Track best individual and display convergence
Best(gen+1) = min(ObjV);
plot(log10(Best),'r');xlabel('generation'); ylabel('log10(f(x))');
text(0.5,0.95,['Best = ', num2str(Best(gen+1))],'Units','normalized');
drawnow;
% Generational loop
while gen < MAXGEN,
% Assign fitness-value to entire population
FitnV = ranking(ObjV);
% Select individuals for breeding
SelCh = select('sus', Chrom, FitnV, GGAP);
% Recombine selected individuals (crossover)
SelCh = recint(SelCh);
% Perform mutation on offspring
SelCh = recmut(SelCh,FieldD);
% Evaluate offspring, call objective function
ObjVSel = mohupidobj1117(SelCh);
% Reinsert offspring into current population
[Chrom ObjV]=reins(Chrom,SelCh,1,1,ObjV,ObjVSel);
% Increment generational counter
gen = gen+1;
% Update display and record current best individual
Best(gen+1) = min(ObjV);
plot(log10(Best),'r'); xlabel('generation'); ylabel('log10(f(x))');
text(0.5,0.95,['Best = ', num2str(Best(gen+1))],'Units','normalized');
drawnow;
end
[OderJi,IndexJi]=sort(ObjV);
BestJ=IndexJi(1);
A=Chrom(BestJ,:)
ObjVSel = mohupidobj1117(Chrom(BestJ,:));
figure(2)
plot(timef,rin,'r',timef,yout,'b');
xlabel('Time(s)');ylabel('rin,yout');
text(0.5,0.95,['Best = ', num2str(Best(gen+1))],'Units','normalized');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -