1 内容介绍

蜂群算法作为一种较为新颖的启 发式算法已经在多种类型的优化问题求解过程中表现了优秀的性能.针对蜂群算法在项目调度问题中的模型求解资源受限的问题,提出对求解方法进行改进,采用人 工蜂群算法和蜂群优化算法两类典型的蜂群算法,对资源受限项目调度问题进行优化设计. 实验结果表明,新设计的两类蜂群算法在调度成功率和收敛速度方面均有更好表现,人工蜂群算法求解的质量方面更优,蜂群算法在收敛速度上更具有优势.

2 部分代码

% Resource Constrained Project Scheduling Problem (RCPSP) using Bees

% Algorithm (BA) or BARCPSP

clc;

clear;

close all;

global NFE;

NFE=0;

% Problem

model=CreateModel2();

CostFunction=@(x) MyCost(x,model);        % Cost Function

nVar=model.N;             % Number of Decision Variables

VarSize=[1 nVar];   % Size of Decision Variables Matrix

VarMin=0;         % Lower Bound of Variables

VarMax=1;         % Upper Bound of Variables

%% Bees Algorithm Parameters

MaxIt = 100;          % Maximum Number of Iterations

nScoutBee = 20;                           % Number of Scout Bees

nSelectedSite = round(0.5*nScoutBee);     % Number of Selected Sites

nEliteSite = round(0.4*nSelectedSite);    % Number of Selected Elite Sites

nSelectedSiteBee = round(0.5*nScoutBee);  % Number of Recruited Bees for Selected Sites

nEliteSiteBee = 2*nSelectedSiteBee;       % Number of Recruited Bees for Elite Sites

r = 0.1*(VarMax-VarMin); % Neighborhood Radius

rdamp = 0.95;             % Neighborhood Radius Damp Rate

%% Start

% Empty Bee Structure

empty_bee.Position = [];

empty_bee.Cost = [];

empty_bee.Sol = [];

% Initialize Bees Array

bee = repmat(empty_bee, nScoutBee, 1);

% Create New Solutions

for i = 1:nScoutBee

bee(i).Position = unifrnd(VarMin, VarMax, VarSize);

[bee(i).Cost bee(i).Sol] = CostFunction(bee(i).Position);

end

% Sort

[~, SortOrder] = sort([bee.Cost]);

bee = bee(SortOrder);

% Update Best Solution Ever Found

BestSol = bee(1);

% Array to Hold Best Cost Values

BestCost = zeros(MaxIt, 1);

%% Bees Algorithm Main Loop

for it = 1:MaxIt

% Elite Sites

for i = 1:nEliteSite

bestnewbee.Cost = inf;

for j = 1:nEliteSiteBee

newbee.Position = Dance(bee(i).Position, r);

[newbee.Cost newbee.Sol] = CostFunction(newbee.Position);

if newbee.Cost<bestnewbee.Cost

bestnewbee = newbee;

end

end

if bestnewbee.Cost<bee(i).Cost

bee(i) = bestnewbee;

end

end

% Selected Non-Elite Sites

for i = nEliteSite+1:nSelectedSite

bestnewbee.Cost = inf;

for j = 1:nSelectedSiteBee

newbee.Position = Dance(bee(i).Position, r);

[newbee.Cost newbee.Sol] = CostFunction(newbee.Position);

if newbee.Cost<bestnewbee.Cost

bestnewbee = newbee;

end

end

if bestnewbee.Cost<bee(i).Cost

bee(i) = bestnewbee;

end

end

% Non-Selected Sites

for i = nSelectedSite+1:nScoutBee

bee(i).Position = unifrnd(VarMin, VarMax, VarSize);

[bee(i).Cost bee(i).Sol] = CostFunction(bee(i).Position);

end

% Sort

[~, SortOrder] = sort([bee.Cost]);

bee = bee(SortOrder);

% Update Best Solution Ever Found

BestSol = bee(1);

% Store Best Cost Ever Found

BestCost(it) = BestSol.Cost;

nfe(it)=NFE;

% Display Iteration Information

disp(['Iteration ' num2str(it) ': BA Best Cost = ' num2str(BestCost(it))]);

% Damp Neighborhood Radius

r = r*rdamp;

end

% Plot

plot(nfe,BestCost,'-og','linewidth',1,'MarkerSize',4,'MarkerFaceColor',[0.9,0.1,0.1]);

title(' Train','FontSize', 17);

%xlabel(' Iteration Number','FontSize', 17);

ylabel(' Best Cost Value','FontSize', 17);

xlim([0 inf])

xlim([0 inf])

ax = gca; 

ax.FontSize = 17; 

set(gca,'Color','k')

legend({'BARCPSP'},'FontSize',12,'TextColor','yellow');

3 运行结果

【优化调度】基于蜜蜂和差分进化算法求解资源受限项目调度问题附matlab代码_调度问题

4 参考文献

[1]刘美宁. 差分进化算法求解资源投资问题[D]. 西安电子科技大学, 2015.

[1]董晓蓉. 蜂群算法求解资源受限项目调度问题及仿真[J]. 计算机仿真, 2013, 30(7):4.

部分理论引用网络文献,若有侵权联系博主删除。