www.pudn.com > GSO_IWO_IGS.rar > IWO.m, change:2015-09-02,size:3627b


function [Plant, Fitness_Max, Fitness_Min] = IWO(Pop_Initial, Dim, Pop, Gen_Max, Gen, Fitness_Max, Fitness_Min)         
%%  参数对应 
%Pop_Initial == n; Dim == m; Gen表示迭代次数 
%Pop是初始种群 
%Plant是计算后新的种群 
%% 开始 
% clear;clc; 
% close all; 
 
%%     初始化参数     %% 
%     Gen=1 
%     Dim=2;%问题的维度 
%     Pop_Initial=10;%初始种群种子数目 
Index = 3;      %非线性调谐指数 
Pop_Size = 3 * Pop_Initial;      %种群最大个体数目 
Seed_Max = round(Pop_Initial / 5);       %单个野草个体能产生的最大种子数目 
Seed_Min = 0;       %单个野草个体能产生的最小种子数目 
%     Gen_Max=500;%最大迭代次数 
Sigma_Initial = 3;      %标准差初始值 
Sigma_Final = 0.1;      %标准差最终值 
Pop_Max = round(0.2 * Pop_Initial);      %种子大小范围上限 
Pop_Min = -round(0.2 * Pop_Initial);     %种子大小范围下限 
 
%%     初始化种群     %% 
 
    %     Pop = Pop_Min + (Pop_Max - Pop_Min) * rand(Pop_Initial, Dim);%种群初始化 
    Plant = Pop;        %初始野草种群 
    Plant_Num = Pop_Initial;        %当前野草个体数目 
    for i = 1 : Plant_Num 
        Fitness(i) = J1(Plant(i, :));       %评估当前野草对应的适应度值 
    end 
%     Fitness_Max = max(Fitness);     %寻找适应度值最大值 
%     Fitness_Min = min(Fitness);      %寻找适应度值最小值 
    %     Trace(Gen) = Fitness_Min;%记录当前代适应度值最小值 
 
 
 
%%     迭代部分     %% 
%    while Gen<=Gen_Max 
%%     繁殖     %%     
    for i = 1 : Plant_Num 
        Seed_Num(i) = (Fitness(i) - Fitness_Min) / (Fitness_Max - Fitness_Min) * (Seed_Max - Seed_Min) + Seed_Min;%计算野草个体能繁殖的种子数目 
        Seed_Num(i) = floor(Seed_Num(i)); 
    end 
 
%%     空间扩散     %% 
    Sigma = ((Gen_Max - Gen)^Index) / (Gen_Max^Index) * (Sigma_Initial - Sigma_Final) + Sigma_Initial;%当前代标准差 
    Seed_Length = 0; 
    for i = 1 : Plant_Num 
        for j = 1 : Dim 
            Seed(Seed_Length + 1 : Seed_Length + Seed_Num(i), j) = normrnd(Plant(i, j), Sigma, [Seed_Num(i), 1]);       %产生新的种子 
        end 
        Seed_Length = Seed_Length + Seed_Num(i);%统计产生的新的种子的数目 
    end 
 
    Pop = [Plant; Seed];        %将野草个体与种子个体合并形成新的种群 
    Pop_Num = Plant_Num + Seed_Length;      %新的种群个体数目 
 
    if Pop_Num <= Pop_Size        %新的种群个体数目小于或等于种群最大个体数目 
        Plant = Pop;        %种子成长为野草后的野草种群 
        Plant_Num = Pop_Num;        %当前野草个体数目更新 
        for i = 1 : Plant_Num 
            Fitness(i) = J1(Plant(i, :));        %评估当前野草所对应的适应度值 
        end 
        Fitness_Max = max(Fitness);     %寻找适应度值最大值 
        Fitness_Min = min(Fitness);     %寻找适应度值最小值 
    else        %新的种群个体数目大于或等于种群最大个体数目 
        for i = 1 : Pop_Num 
            Fitness_New(i) = J1(Pop(i, :));     %评估当前种群所有个体所对应的适应度值 
        end 
        Fitness_Sort = sort(Fitness_New, 'ascend');     %适应度值升序排列 
        Threshold = Fitness_Sort(Pop_Size);     %找出第Pop_Size个适应度值作为临界值 
        j = 1; 
        for i = 1 : Pop_Num 
            if Fitness_New(i) <= Threshold        %适应度值小于临界值 
                Plant(j, :) = Pop(i, :);        %小于临界值的个体被保留在新的野草种群中 
                Fitness(j) = Fitness_New(i);        %提取出保存下来的适应度值 
                j = j + 1; 
            end 
        end 
        Plant_Num = Pop_Size;       %当前野草个体数目更新 
        Fitness_Max = max(Fitness);     %寻找适应度值最大值 
        Fitness_Min = min(Fitness);      %寻找适应度值最小值 
    end 
 
%     Gen = Gen + 1; 
%        Trace(Gen) = Fitness_Min;%记录当前代适应度值最小值 
%    end 
     
end