moead多目标进化算法(matlab)

moead多⽬标进化算法(matlab)eval_update    eval字符串调⽤函数
function [idealpoint, subproblems]= eval_update(idealpoint, subproblems, inds)
%EvaluationUpdate Summary of this function goes here
%  Detailed explanation goes here
objs = [inds.objective];
weights = [subproblems.weight];
idealpoint = min(idealpoint, min(objs,[],2));
for i=1:length(inds)
subobjs = subobjective(weights, objs(:,i), idealpoint, 'ws');
%update the values.
C = subobjs<[subproblems.optimal];
if any(C)
ncell = num2cell(subobjs(C));
[subproblems(C).optimal] = ncell{:};
[subproblems(C).optpoint] = deal(inds(i));
end
end
end
evaluate
function [v, x] = evaluate( prob, x )
%EVALUATE function evaluate an individual structure of a vector point with
%the given multiobjective problem.
%  Detailed explanation goes here
%  prob: is the multiobjective problem.
%  x: is a vector point, or a individual structure.
%  v: is the result objectives evaluated by the mop.
%  x: if x is a individual structure, then x's objective field is modified
%  with the evaluated value and pass back.
%  TODO, need to refine it to operate on a vector of points.
if isstruct(x)
v = prob.func(x.parameter);
x.objective=v;
else
v = prob.func(x);
end
gaussian_mutate
function ind = gaussian_mutate( ind, prob, domain)
%GAUSSIAN_MUTATE Summary of this function goes here
%  Detailed explanation goes here
if isstruct(ind)
x = ind.parameter;
else
x  = ind;
end
parDim = length(x);
lowend  = domain(:,1);
highend =domain(:,2);
sigma = (highend-lowend)./20;
newparam = min(max(normrnd(x, sigma), lowend), highend);
C = rand(parDim, 1)<prob;进化标记
x(C) = newparam(C);
if isstruct(ind)
ind.parameter = x;
else
ind = x;
end
genetic_op
function ind=genetic_op(subproblems, index, domain, params)
%GENETICOP function implemented the DE operation to generate a new %individual from a subproblems and its neighbours.
%  subproblems: is all the subproblems.
%  index: the index of the subproblem need to handle.
%  domain: the domain of the origional multiobjective problem.
%  ind: is an individual structure.
neighbourindex = subproblems(index).neighbour;
%The random draw from the neighbours.
nsize = length(neighbourindex);
si = ones(1,3)*index;
si(1)=neighbourindex(ceil(rand*nsize));
while si(1)==index
si(1)=neighbourindex(ceil(rand*nsize));
end
si(2)=neighbourindex(ceil(rand*nsize));
while si(2)==index || si(2)==si(1)
si(2)=neighbourindex(ceil(rand*nsize));
end
si(3)=neighbourindex(ceil(rand*nsize));
while si(3)==index || si(3)==si(2) || si(3)==si(1)
si(3)=neighbourindex(ceil(rand*nsize));
end
%retrieve the individuals.
points = [subproblems(si).curpoint];
selectpoints = [points.parameter];
oldpoint = subproblems(index).curpoint.parameter;
parDim = size(domain, 1);
jrandom = ceil(rand*parDim);
randomarray = rand(parDim, 1);
deselect = randomarray<params.CR;
deselect(jrandom)=true;
newpoint = selectpoints(:,1)+params.F*(selectpoints(:,2)-selectpoints(:,3));
newpoint(~deselect)=oldpoint(~deselect);
%repair the new value.
newpoint=max(newpoint, domain(:,1));
newpoint=min(newpoint, domain(:,2));
ind = struct('parameter',newpoint,'objective',[], 'estimation',[]);
%ind.parameter = newpoint;
%ind = realmutate(ind, domain, 1/parDim);
ind = gaussian_mutate(ind, 1/parDim, domain);
%clear points selectpoints oldpoint randomarray deselect newpoint neighbourindex si; end
get_structure
function str = get_structure( name )
%STRUCTURE Summary of this function goes here
%
% Structure used in this toolbox.
%
% individual structure:
% parameter: the parameter space point of the individual. it's a column-wise
% vector.
% objective: the objective space point of the individual. it's column-wise
% vector. It only have value after evaluate function is called upon the
% individual.
% estimation: Also a structure array of the individual. It's not used in
% MOEA/D but used in MOEA/D/GP. For every objective, the field contains the
% estimation from the GP model.
%
% estimation structure:
% obj: the estimated mean.
% std: the estimated standard deviation for the mean.
%
% subproblem structure:
% weight: the decomposition weight for the subproblem.
% optimal: the current optimal value of the current structure.
% curpoiont: the current individual of the subproblem.
% optpoint: the point that gain the optimal on the subproblem.
%
switch name
case 'individual'
str = struct('parameter',[],'objective'[],'estimation'[]);
case 'subproblem'
str = struct('weight',[],'optimal',[],'curpoint',[],'optpoint',[]);
case 'estimation'
str = struct();
otherwise
init_weights
function subp=init_weights(popsize, niche, objDim)
% init_weights function initialize a pupulation of subproblems structure
% with the generated decomposition weight and the neighbourhood
% relationship.
subp=[];
for i=0:popsize
if objDim==2
p=struct('weight',[],'neighbour',[],'optimal', Inf, 'optpoint',[], 'curpoint', []);            weight=zeros(2,1);
weight(1)=i/popsize;
weight(2)=(popsize-i)/popsize;
p.weight=weight;
subp=[subp p];
elseif objDim==3
%TODO
end
end
% weight = lhsdesign(popsize, objDim, 'criterion','maximin', 'iterations', 1000)'; % p=struct('weight',[],'neighbour',[],'optimal', Inf, 'optpoint',[], 'curpoint', []);
% subp = repmat(p, popsize, 1);
% cells = num2cell(weight);
% [subp.weight]=cells{:};
%Set up the neighbourhood.
leng=length(subp);
distanceMatrix=zeros(leng, leng);
for i=1:leng
for j=i+1:leng
A=subp(i).weight;B=subp(j).weight;
distanceMatrix(i,j)=(A-B)'*(A-B);
distanceMatrix(j,i)=distanceMatrix(i,j);
end
[s,sindex]=sort(distanceMatrix(i,:));
subp(i).neighbour=sindex(1:niche)';
end
end
moead
function pareto = moead( mop, varargin)
%MOEAD runs moea/d algorithms for the given mop.
%  Detailed explanation goes here
%  The mop must to be minimizing.
%  The parameters of the algorithms can be set through varargin. including %  popsize: The subproblem's size.
%  niche: the neighboursize, must less then the popsize.
%  iteration: the total iteration of the moead algorithms before finish.
%  method: the decomposition method, the value can be 'ws' or 'ts'.
%global variable definition.
global params idealpoint objDim parDim itrCounter;
%set the random generator.
rand('state',10);
%Set the algorithms parameters.
paramIn = varargin;
[objDim, parDim, idealpoint, params, subproblems]=init(mop, paramIn);
itrCounter=1;
while ~terminate(itrCounter)
tic;
subproblems = evolve(subproblems, mop, params);
disp(sprintf('iteration %u finished, time used: %u', itrCounter, toc));
itrCounter=itrCounter+1;
end
%display the result.
pareto=[subproblems.curpoint];
pp=[pareto.objective];
scatter(pp(1,:), pp(2,:));
disp(sprintf('total time used %u', etime(clock, starttime)));
end
function [objDim, parDim, idealp, params, subproblems]=init(mop, propertyArgIn) %Set up the initial setting for the MOEA/D.
objDim=mop.od;
parDim=mop.pd;
idealp=ones(objDim,1)*inf;
%the default values for the parameters.
params.popsize=100;params.niche=30;params.iteration=100;
params.dmethod='ts';
params.F = 0.5;
params.CR = 0.5;
%handle the parameters, mainly about the popsize
while length(propertyArgIn)>=2
prop = propertyArgIn{1};
val=propertyArgIn{2};
propertyArgIn=propertyArgIn(3:end);
switch prop
case 'popsize'
params.popsize=val;
case 'niche'
params.niche=val;
case 'iteration'
params.iteration=val;
case 'method'
params.dmethod=val;
otherwise
warning('moea doesnot support the given parameters name');
end

本文发布于:2024-09-21 08:49:10,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/374763.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:进化   字符串   函数   算法   标记
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议