📄 mohureal.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
clear all
close all
global rin yout timef ntt mtt nmtol kk ts u P a b et Tdelay x1 x2 AA;
NIND =50; % Number of individuals per subpopulations
MAXGEN = 50; % maximum Number of generations
GGAP = .9; % Generation gap, how many new individuals are created
%%%%%%%%%%%%%%%%修正模型的参数及采样周期%%%%%%%%%%%%%%%
ts=10; %采样周期
rin=1;
P=100; %影响参数的变化速率
% Build field descriptor
FieldD1 = rep([-2;2],[1,12]);
FieldD2 = rep([-1;1],[1,1]);
% FieldD3 = rep([0;1],[1,5]);
FieldD1 = rep([0;1],[1,]);
FieldD2 = rep([-1;1],[1,1]);
% FieldD1 = rep([0;1],[1,7]);
% FieldD2 = rep([-1;1],[1,1]);
FieldD=[FieldD1 FieldD2];
% FieldD=[FieldD1 FieldD2 FieldD3];
A=[];
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 = mohupidobj(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 = mohupidobj(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;
[OderJi,IndexJi]=sort(ObjV);
BestJ=IndexJi(1);
AA=[AA; Chrom(BestJ,:)]
end
[OderJi,IndexJi]=sort(ObjV);
BestJ=IndexJi(1);
A=Chrom(BestJ,:)
% yaa=[];
% for i=1:100
% a=mohupidobj(AA(i,:))
% yaa=[yaa;yout];
% end
ObjVSel = mohupidobj(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 + -