⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createpop.m

📁 基本遗传算法的matlab源程序
💻 M
字号:
function [gene,genek_bitnum]=createPop(bounds,sizePop,accuracy)
%  to create a population at the starting point
%  syntax:[gene,genek_bitnum]=createPop(bounds,sizePop,accuracy)
%
%  Output Arguments:
%      gene         ---- the gene string of all individual
%      genek_bitnum ---- length of gene string
%  Input Arguments:
%      bounds       ---- a matrix of upper and lower bounds on the variables
%      sizePop      ---- the population size
%      accuracy     ---- the calculation accuracy
%
%  Author:Yan Anxin
%  ID number:081810
%  Date:finished on 2008.11.29
%  Yax235 DreamWorks, SEE, SEU, 2# Sipailou Nanjing, 210096, P.R.China 

[n,]=size(bounds);gene='';
genek_bitnum=ones();
for k=1:n              %to get the length of every gene string 
    a=bounds(k,1);b=bounds(k,2);
    genek_bitnum(k)=1;
    while  (2^genek_bitnum(k)-1)<((b-a)/accuracy)
        genek_bitnum(k)=genek_bitnum(k)+1;
    end
end

for ki=1:sizePop
    gene_str='';
    for kj=1:n
        clear str;      %to randomly generat initial population
        str=num2str(dec2bin((unidrnd(2^genek_bitnum(kj))-1),genek_bitnum(kj)));
        gene_str=[gene_str str];
    end
    gene=[gene;gene_str];  
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -