【单目标优化求解】基于matlab混沌生物地理算法求解单目标问题【含Matlab源码 1411期】

999 阅读4分钟

一、生物地理算法简介

1 基本思路 BBO 算法起源于生物地理学,它通过模拟多物种在不同栖息地的分布、迁移、突变等规律求解寻优问题,在多目标规划领域有广泛应用. 栖息地被认为是独立的区域,不同的栖息地拥有不同的适宜指数HSI(Habitat suitability index)。 HSI较高的栖息地物种丰富度较高,随着种群趋于饱和,其迁出率增高,迁入率减少,而HIS较低的栖息地与之相反,迁入率增高,迁出率减少. 当栖息地遭遇灾害或瘟疫等突发事件时,HIS将随之突变,打破动态平衡,为低HIS的栖息地添加了不可预见性,增大了搜索目标解的几率2.2 迁移和突变操作物种的迁移有其具体的物理模型,最常的有线性模型、二次模型、余弦模型等 . 以图 3线性模型为例,当某栖息地物种数目为 0 时迁入率最高,此刻 λ = I,随着迁入物种数目不断增加,受阳光、水、食物等资源限制,迁入率不断降低,迁出率不断增高 . 当栖息地物种数目为 S0时,恰好达到动态平衡,此时迁出率与迁入率相同 . 而栖息地达到饱和状态时,物种数量达到最大值Smax ,此刻不再有物种迁入,迁出率 μ = E.突变操作基于生物地理学统计公式完成: 在这里插入图片描述 在这里插入图片描述 式中:ms为栖息地发生突变的概率,mmax为最大突变率,用户可自行设定 . ps为栖息地容纳s种物种的概率, pmax代表容纳最大种群的概率。

二、部分源代码



clear all
clc

nMonte = 100; % Number of Monte Carlo runs
DisplayFlag = true; % Whether or not to display results during run
GenFlag = true; % whether or not to exit BBO after population becomes uniform
PopSize = 30; % Population sizes for which to run SBBO

% Choose the test function

% ProblemFunction=@Sphere;
% ProblemFunction=@Ackley;
% ProblemFunction=@Fletcher;
% ProblemFunction=@Griewank;
% ProblemFunction=@Penalty1;
% ProblemFunction=@Penalty2;
 ProblemFunction=@Quartic;
% ProblemFunction=@Rastrigin;
% ProblemFunction=@Rosenbrock;
% ProblemFunction=@Schwefel;

% or you objective function
% ProblemFunction=@YourObjectiveFunction;

%Chaotic_map_no=1; %Chebyshev
%Chaotic_map_no=2; %Circle
Chaotic_map_no=3; %Gauss/mouse
%Chaotic_map_no=4; %Iterative
%Chaotic_map_no=5; %Logistic
%Chaotic_map_no=6; %Piecewise
%Chaotic_map_no=7; %Sine
%Chaotic_map_no=8; %Singer
%Chaotic_map_no=9; %Sinusoidal
%Chaotic_map_no=10; %Tent

%You can define the number of search agents and iterations in the Init.m file
Max_iterations=10000;% This should be equal or greater than OPTIONS.Maxgen in Init.m file

ChaosVec=zeros(10,Max_iterations);
%Calculate chaos vector
for i=1:10
    ChaosVec(i,:)=chaos(i,Max_iterations,1);
end

% BBO algorithm
[cg_curve0] = BBO(ProblemFunction, DisplayFlag, PopSize, GenFlag);

% BBO with chaotic selection operator
[cg_curve1] = CBBO1_10(ProblemFunction, DisplayFlag, PopSize, GenFlag,ChaosVec(Chaotic_map_no,:));           

% BBO with chaotic migration operator
[cg_curve2] = CBBO11_20(ProblemFunction, DisplayFlag, PopSize, GenFlag,ChaosVec(Chaotic_map_no,:));           

% BBO with chaotic mutation operator
[cg_curve3] = CBBO21_30(ProblemFunction, DisplayFlag, PopSize, GenFlag,ChaosVec(Chaotic_map_no,:));           

% BBO with chaotic selection/migration operators combined
[cg_curve4] = CBBO31_40(ProblemFunction, DisplayFlag, PopSize, GenFlag,ChaosVec(Chaotic_map_no,:));           

% BBO with chaotic selection/migration/mutation operators combined
[cg_curve5] = CBBO41_50(ProblemFunction, DisplayFlag, PopSize, GenFlag,ChaosVec(Chaotic_map_no,:)); 

semilogy(cg_curve0,'Color','y')
hold on
semilogy(cg_curve1,'Color','k')
semilogy(cg_curve2,'Color','b')
semilogy(cg_curve3,'Color','g')
semilogy(cg_curve4,'Color','r')
semilogy(cg_curve5,'Color','c')

xlabel('Iteration');
ylabel('Best score obtained so far');

axis tight
grid on
box on
legend('BBO' , ['CBBO' num2str(Chaotic_map_no)] , ['CBBO' num2str(Chaotic_map_no+10)] ,['CBBO' num2str(Chaotic_map_no+20)] ,['CBBO' num2str(Chaotic_map_no+30)] ,['CBBO' num2str(Chaotic_map_no+40)] )

function [OPTIONS, MinCost, AvgCost, InitFunction, CostFunction, FeasibleFunction, ...
    MaxParValue, MinParValue, Population] = Init(DisplayFlag, ProblemFunction, RandSeed)

% Initialize population-based optimization software.

% WARNING: some of the optimization routines will not work if population size is odd.
OPTIONS.popsize = 30; % total population size
OPTIONS.Maxgen = 499; % generation count limit
OPTIONS.numVar = 30; % number of genes in each population member
OPTIONS.pmutate = 0; % mutation probability

if ~exist('RandSeed', 'var')
    RandSeed = round(sum(100*clock));
end
%rand('state', RandSeed); % initialize random number generator
if DisplayFlag
    disp(['random # seed = ', num2str(RandSeed)]);
end

% Get the addresses of the initialization, cost, and feasibility functions.
[InitFunction, CostFunction, FeasibleFunction] = ProblemFunction();
% Initialize the population.
[MaxParValue, MinParValue, Population, OPTIONS] = InitFunction(OPTIONS);
% Make sure the population does not have duplicates. 
Population = ClearDups(Population, MaxParValue, MinParValue);
% Compute cost of each individual  
Population = CostFunction(OPTIONS, Population);
% Sort the population from most fit to least fit
Population = PopSort(Population);
% Compute the average cost
AverageCost = ComputeAveCost(Population);
% Display info to screen
MinCost = [Population(1).cost];
AvgCost = [AverageCost];
if DisplayFlag
    disp(['The best and mean of Generation # 0 are ', num2str(MinCost(end)), ' and ', num2str(AvgCost(end))]);
end

return;
function O=chaos(index,max_iter,Value)

O=zeros(1,max_iter);
x(1)=0.7;
switch index
%Chebyshev map
    case 1
for i=1:max_iter
    x(i+1)=cos(i*acos(x(i)));
    G(i)=((x(i)+1)*Value)/2;
end
    case 2
%Circle map
a=0.5;
b=0.2;
for i=1:max_iter
    x(i+1)=mod(x(i)+b-(a/(2*pi))*sin(2*pi*x(i)),1);
    G(i)=x(i)*Value;
end
    case 3
%Gauss/mouse map
for i=1:max_iter
    if x(i)==0
        x(i+1)=0;
    else
        x(i+1)=mod(1/x(i),1);
    end
    G(i)=x(i)*Value;
end

    case 4
%Iterative map
a=0.7;
for i=1:max_iter
    x(i+1)=sin((a*pi)/x(i));
    G(i)=((x(i)+1)*Value)/2;
end

    case 5
%Logistic map
a=4;
for i=1:max_iter
    x(i+1)=a*x(i)*(1-x(i));
    G(i)=x(i)*Value;
end
    case 6
%Piecewise map
P=0.4;
for i=1:max_iter
    if x(i)>=0 && x(i)<P
        x(i+1)=x(i)/P;
    end
    if x(i)>=P && x(i)<0.5
        x(i+1)=(x(i)-P)/(0.5-P);
    end
    if x(i)>=0.5 && x(i)<1-P
        x(i+1)=(1-P-x(i))/(0.5-P);
    end
    if x(i)>=1-P && x(i)<1
        x(i+1)=(1-x(i))/P;
    end    
    G(i)=x(i)*Value;
end

    case 7
%Sine map
for i=1:max_iter
     x(i+1) = sin(pi*x(i));
     G(i)=(x(i))*Value;
 end
    case 8
 %Singer map 
 u=1.07;
 for i=1:max_iter
     x(i+1) = u*(7.86*x(i)-23.31*(x(i)^2)+28.75*(x(i)^3)-13.302875*(x(i)^4));
     G(i)=(x(i))*Value;
 end
    case 9
%Sinusoidal map
 for i=1:max_iter
     x(i+1) = 2.3*x(i)^2*sin(pi*x(i));
     G(i)=(x(i))*Value;
 end
 
    case 10
 %Tent map
 x(1)=0.6;
 for i=1:max_iter
     if x(i)<0.7
         x(i+1)=x(i)/0.7;
     end
     if x(i)>=0.7
         x(i+1)=(10/3)*(1-x(i));
     end
     G(i)=(x(i))*Value;
 end

end
O=G;


三、运行结果

在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本 2014a

2 参考文献 [1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016. [2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.