%-----------------------------------------------------------------------------------------------------------------%
% Multi-Objective Jellyfish Search (MOJS) source codes demo version 1.0 Developed in MATLAB R2016a %%-----------------------------------------------------------------------------------------------------------------%
%% Main MOJS optimizer
function ARCH = MOJS(params,MultiObj)
% Parameters
Np = params.Np;
Nr = params.Nr;
MaxIt = params.maxiter;
ngrid = params.ngrid;
fun = MultiObj.fun;
nVar = MultiObj.nVar;
var_min = MultiObj.var_min(:);
var_max = MultiObj.var_max(:);
it=1;
% Initialization by Eq. 25
POS=initialchaos(7,Np,nVar,var_max',var_min');
POS_fit = fun(POS);
ELI_POS = POS;
ELI_POS_fit = POS_fit;
DOMINATED = checkDomination(POS_fit);
ARCH.pos = POS(~DOMINATED,:);
ARCH.pos_fit = POS_fit(~DOMINATED,:);
ARCH = updateGrid(ARCH,ngrid);
display(['Iteration #0 - Archive size: ' num2str(size(ARCH.pos,1))]);
%% Main MOJS loop
stopCondition = false;
while ~stopCondition
% Select leader by Eq. 16
h = selectLeader(ARCH);
% Calculate time control by Eq. 15
Ct=abs((1-it*((1)/MaxIt))*(2*rand-1));
if Ct>=0.5
Meanvl=mean(ELI_POS);
for i=1:Np
% The new position is determined by Eq.19 and Eq.20
POS(i,:) = ELI_POS(i,:) + Levy(nVar).*(ARCH.pos(h,:) - 3*rand([1 nVar]).*Meanvl);
end
else
for i=1:Np
if rand<(1-Ct)
% Jellyfish follow type B
% Determine the direction by Eq. 24
j=i;
while j==i
j=randperm(Np,1);
end
Step = ELI_POS(i,:) - ELI_POS(j,:);
if dominates(ELI_POS_fit(j,:),ELI_POS_fit(i,:))
Step = -Step;
end
% The new position is determined by Eq. 22
POS(i,:) =ARCH.pos(h,:) + rand([1 nVar]).*Step;
else
% Jellyfish follow type A
% The new position is determined by Eq. 21
POS(i,:)=ARCH.pos(h,:)+Levy(nVar).*(ELI_POS(i,:)-ARCH.pos(h,:));
end
end
end
%% Update new position by opposition-based jumping using Eq. 26
if rand <(it/MaxIt)
[POS] = OPPOS(POS,var_max,var_min);
end
%% Check boundaries
if rand>=0.5
POS=checksimplebounds(POS,var_min',var_max');
else
POS = checkBoundaries(POS,var_max,var_min);
end
%% Evaluate the population
POS_fit = fun(POS);
pos_best = dominates(POS_fit, ELI_POS_fit);
best_pos = ~dominates(ELI_POS_fit, POS_fit);
best_pos(rand(Np,1)>=0.5) = 0;
if(sum(pos_best)>1)
ELI_POS_fit(pos_best,:) = POS_fit(pos_best,:);
ELI_POS(pos_best,:) = POS(pos_best,:);
end
if(sum(best_pos)>1)
ELI_POS_fit(best_pos,:) = POS_fit(best_pos,:);
ELI_POS(best_pos,:) = POS(best_pos,:);
end
%% Update the archive
if size(ARCH.pos,1)==1
ARCH.pos= POS;
ARCH.pos_fit= POS_fit;
ARCH = updateArchive(ARCH,ELI_POS,ELI_POS_fit,ngrid);
else
ARCH = updateArchive(ARCH,ELI_POS,ELI_POS_fit,ngrid);
if size(ARCH.pos,1)==1
ARCH.pos= ELI_POS;
ARCH.pos_fit= ELI_POS_fit;
end
end
if(size(ARCH.pos,1)>Nr)
% Delete the worst members from archive by Eq. 18
ARCH = deleteFromArchive(ARCH,size(ARCH.pos,1)-Nr,ngrid);
end
display(['Iteration #' num2str(it) ' - Archive size: ' num2str(size(ARCH.pos,1))]);
it=it+1;
if(it>MaxIt), stopCondition = true; end
end
%% Plotting paretofront
if(size(ARCH.pos_fit,2)==2)
plot(ARCH.pos_fit(:,1),ARCH.pos_fit(:,2),'or'); hold on;
grid on; xlabel('f1'); ylabel('f2');
end
if(size(ARCH.pos_fit,2)==3)
plot3(ARCH.pos_fit(:,1),ARCH.pos_fit(:,2),ARCH.pos_fit(:,3),'or'); hold on;
grid on; xlabel('f1'); ylabel('f2'); zlabel('f3');
end
end
%% This function calucates the leader performance by a roulette wheel selection
% based on the quality of each hypercube
function selected = selectLeader(ARCH)
% Roulette wheel
prob = cumsum(ARCH.quality(:,2)); % Cumulated probs
sel_hyp = ARCH.quality(find(rand(1,1)*max(prob)<=prob,1,'first'),1); % Selected hypercube
% Select the index leader as a random selection inside that hypercube
idx = 1:1:length(ARCH.grid_idx);
selected = idx(ARCH.grid_idx==sel_hyp);
selected = selected(randi(length(selected)));
end
%% This function returns 1 if x dominates y and 0 otherwise
function d = dominates(x,y)
d = all(x<=y,2) & any(x<y,2);
end
%% This function checks the domination inside the population.
function domi_vector = checkDomination(fitness)
Np = size(fitness,1);
if Np>2
domi_vector = zeros(Np,1);
all_perm = nchoosek(1:Np,2); % Possible permutations
all_perm = [all_perm; [all_perm(:,2) all_perm(:,1)]];
d = dominates(fitness(all_perm(:,1),:),fitness(all_perm(:,2),:));
dominated_particles = unique(all_perm(d==1,2));
domi_vector(dominated_particles) = 1;
else
domi_vector=ones(Np,1);
end
end
%% This function updates the archive given a new population
function ARCH = updateArchive(ARCH,POS,POS_fit,ngrid)
% Domination between jellyfish
DOMINATED = checkDomination(POS_fit);
ARCH.pos = [ARCH.pos; POS(~DOMINATED,:)];
ARCH.pos_fit= [ARCH.pos_fit; POS_fit(~DOMINATED,:)];
% Domination between nondominated jellyfish and the last archive
DOMINATED = checkDomination(ARCH.pos_fit);
ARCH.pos_fit= ARCH.pos_fit(~DOMINATED,:);
ARCH.pos = ARCH.pos(~DOMINATED,:);
% Updating the grid
ARCH = updateGrid(ARCH,ngrid);
end
%% Function that updates the hypercube grid, the hypercube where belongs
function ARCH = updateGrid(ARCH,ngrid)
% Computing the hypercube limitation
ndim = size(ARCH.pos_fit,2);
ARCH.hypercube_limits = zeros(ngrid+1,ndim);
for dim = 1:1:ndim
ARCH.hypercube_limits(:,dim) = linspace(min(ARCH.pos_fit(:,dim)),max(ARCH.pos_fit(:,dim)),ngrid+1)';
end
% Computing where belongs each jellyfish
npar = size(ARCH.pos_fit,1);
ARCH.grid_idx = zeros(npar,1);
ARCH.grid_subidx = zeros(npar,ndim);
for n = 1:1:npar
idnames = [];
for d = 1:1:ndim
ARCH.grid_subidx(n,d) = find(ARCH.pos_fit(n,d)<=ARCH.hypercube_limits(:,d)',1,'first')-1;
if(ARCH.grid_subidx(n,d)==0), ARCH.grid_subidx(n,d) = 1; end
idnames = [idnames ',' num2str(ARCH.grid_subidx(n,d))];
end
ARCH.grid_idx(n) = eval(['sub2ind(ngrid.*ones(1,ndim)' idnames ');']);
end
% Quality based on the number of jellyfish in each hypercube
ARCH.quality = zeros(ngrid,2);
ids = unique(ARCH.grid_idx);
for i = 1:length(ids)
ARCH.quality(i,1) = ids(i);
ARCH.quality(i,2) = 10/sum(ARCH.grid_idx==ids(i));
end
end
%% This function deletes an excess of jellyfish inside the archive using crowding distances
function ARCH = deleteFromArchive(ARCH,n_extra,ngrid)
% Compute the crowding distances
crowding = zeros(size(ARCH.pos,1),1);
for m = 1:1:size(ARCH.pos_fit,2)
[m_fit,idx] = sort(ARCH.pos_fit(:,m),'ascend');
m_up = [m_fit(2:end); Inf];
m_down = [Inf; m_fit(1:end-1)];
distance = (m_up-m_down)./(max(m_fit)-min(m_fit));
[~,idx] = sort(idx,'ascend');
crowding = crowding + distance(idx);
end
crowding(isnan(crowding)) = Inf;
% This function deletes the extra jellyfish with the smallest crowding distances
[~,del_idx] = sort(crowding,'ascend');
del_idx = del_idx(1:n_extra);
ARCH.pos(del_idx,:) = [];
ARCH.pos_fit(del_idx,:) = [];
ARCH = updateGrid(ARCH,ngrid);
end
%% This function checks the boundary of jellyfish search space
function [POS] = checkBoundaries(POS,var_max,var_min)
% Useful matrices
Np = size(POS,1);
MAXLIM = repmat(var_max(:)',Np,1);
MINLIM = repmat(var_min(:)',Np,1);
POS(POS>MAXLIM) = MAXLIM(POS>MAXLIM);
POS(POS<MINLIM) = MINLIM(POS<MINLIM);
end
function POS=checksimplebounds(POS,Lb,Ub)
for i=1:size(POS,1)
ns_tmp=POS(i,:);
I=ns_tmp<Lb;
while sum(I)~=
没有合适的资源?快使用搜索试试~ 我知道了~
多目标水母搜索(MOJS)算法Matlab代码.zip
共8个文件
m:5个
png:1个
zip:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 98 浏览量
2022-12-28
10:32:22
上传
评论
收藏 151KB ZIP 举报
温馨提示
多目标水母搜索(MOJS)算法Matlab代码.zip
资源推荐
资源详情
资源评论
收起资源包目录
多目标水母搜索(MOJS)算法Matlab代码.zip (8个子文件)
多目标水母搜索(MOJS)算法Matlab代码
OPPOS.m 835B
MOJS.m 8KB
BenchmarkFunctionsTest.m 2KB
Levy.m 805B
Matlab【智能优化算法-水母搜索优化器算法】基于水母搜索优化器算法求解多目标优化问题(Jellyfish Search Optimizer ,JSO).zip 75KB
result.mat 3KB
img.png 120KB
initialchaos.m 5KB
共 8 条
- 1
资源评论
天天Matlab科研工作室
- 粉丝: 3w+
- 资源: 7249
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功