📄 initpop.m
字号:
function [pop] = initpop(num,bounds,evalFN)
% pop - the initial, evaluated, random population
% num - the size of the population, i.e. the number to create
% variableBounds - a matrix which contains the bounds of each variable, i.e.
% [var1_high var1_low; var2_high var2_low; ....]
% evalFN - the evaluation fn, usually the name of the .m file for
% evaluation
% evalOps - any options to be passed to the eval function defaults []
% options - options to the initialize function, ie.
% [type prec] where eps is the epsilon value
% and the second option is 1 for float and 0 for binary,
% prec is the precision of the variables defaults [1e-6 1]
% SGA_selection Begin
%num=10;
%bounds=[0 9];
%evalFN='gademo1eval';
%a=nargin;
%% check input & error protect
opts=[1e-6 1];
% Let's create a random starting popluation of size
if any(evalFN<48) %Not a .m file
%Binary GA
estr=['x=b2f(pop(i,:),bounds,bits); pop(i,xZomeLength)=', evalFN ';'];
else %A .m file
%Binary GA
estr=['x=b2f(pop(i,:),bounds,bits);[x v]=' evalFN ...
'(x,[ ]); pop(i,:)=[f2b(x,bounds,bits) v];'];
end
%Binary GA
bits=ceil(log2((bounds(:,2)-bounds(:,1))' ./ opts(1)));
xZomeLength = sum(bits)+1; %Length of string is numVar + fit
pop = round(rand(num,sum(bits)+1));
for i=1:num
eval(estr);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -