📄 initializega.sci
字号:
function [pop] = initializega(num, bounds, options)
numVars = size(bounds,1); //Number of variables
rng = (bounds(:,2)-bounds(:,1))'; //The variable ranges'
if options(1)==1 //Float GA
xZomeLength = numVars+1; //Length of string is numVar + fit
pop = zeros(num,xZomeLength); //Allocate the new population
pop(:,1:numVars)=(ones(num,1)*rng).*(rand(num,numVars))+...
(ones(num,1)*bounds(:,1)');
elseif (options(1)==0) //Binary GA
bits=calcbits(bounds);
xZomeLength = sum(bits)+1; //Length of string is numVar + fit
pop = round(rand(num,sum(bits)+1));
elseif (options(1)==2) //Arrange GA
numArranges = rng + 1; //Number of each arrages
cumArranges = cumsum([0 numArranges]);
xZomeLength = sum(numArranges)+1; //Length of string is numVar + fit
pop = zeros(num,xZomeLength); //Allocate the new population
for i= 1:size(numArranges,2)
[a,b]=sort(rand(numArranges(i),num),'r');
pop(:,(cumArranges(i)+1):cumArranges(i+1))=b'+bounds(i,1)-1;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -