• 大小: 12KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2022-05-02
  • 语言: Matlab
  • 标签:

资源简介

杂草优化算法(IWO)是一种受杂草启发而提出的、基于种群的数值优化计算方法,其执行过程是模拟杂草入侵过程的算法。在matlab环境中用m语言编程实现了IWO,并对其收敛性进行了仿真。

资源截图

代码片段和文件信息

%%
%**************************************************************************
%*******************注意,此程序以适应度值最大作为最优***********************
%**************************************************************************
clc
clear all
format long
%% 参数初始化
X_min=-30;                                                   %区间大小
X_max=30;

G_SIZE=5;                                                    %初始杂草个数
P_SIZE=10;                                                   %最大杂草个数

D=2;                                                         %问题的维数
iter_max=350;                                                %迭代次数

stepLength_ini=300;                                          %初始标准差
stepLength_final=0.05;                                       %最终标准差
                        
seed_max=20;                                                 %最大种子数
seed_min=0;                                                  %最小种子数

n=3;                                                         %非线性因子
F=@(x)objectFun(x);                                          %测试函数

test_now=1;                                                  %当前独立运行的次数
test_all=2;                                                 %独立运行的总次数
%% 第一次独立运行
while test_now    %% 初始化
    weed_now=[];                                             %杂草
    weed_next=[];                                            %种子
    for i=1:G_SIZE
%         temp1=[];
%         temp1=chaos(X_minX_maxDrand(1));
%         weed_now(i:)=temp1(2:end);
        weed_now(i:)=X_min+(X_max-X_min).*rand(1D);        %D维空间中随即分布的G_SIZE个可行解
    end
    weed_next=weed_now;
    iter =1 ;                                                %迭代次数初始化为1
    
    %进化
    while iter         weed_now=[];
        weed_now=weed_next;
        N=size(weed_now1);
        fitness=[];
        %% 计算步长,即当前标准差
        stepLength_now=(iter_max-iter)^n*(stepLength_ini-stepLength_final)/(iter_max)^n+stepLength_final;
        %% 计算杂草的适应度值
        for i=1:N
            fitness(i)=-F(weed_now(i:));
        end
        BestFitness=max(fitness);
        WorstFitness=min(fitness);
        %% 计算种子个数并产生种子
        weed_g_new=[];                                         %全部种子
        for i=1:N
            %计算各个杂草所产生的种子个数
            num=(seed_max-seed_min)*(fitness(i)-WorstFitness)/(BestFitness-WorstFitness)+seed_min;
            num=ceil(num);                                     %向上取整
            if num>0
                weed_temp=[];
                weed_change=[];
                weed_temp=repmat(weed_now(i:)num1);         %产生num*1个weed_now(i:)矩阵维数为num*D
                weed_change=normrnd(0stepLength_nownumD);   %产生均值为0,标准差为stepLength_now的正态矩阵,维数为num*D
                weed_new=weed_temp+weed_change;                %某一个杂草的后代种子
                weed_g_new=[weed_g_new;weed_new];              %加入到全部种子中
            end
        end
        weed_now=[weed_now;weed_g_new];
        %% 计算种子的适应度值
        N

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1039  2014-01-06 22:43  objectFun.m

     文件       4960  2014-01-07 12:09  iwo_basic.m

     文件      43669  2014-01-05 23:14  IWO_PD_Optim.mdl

----------- ---------  ---------- -----  ----

                49668                    3


评论

共有 条评论