情况是这样的,我下载了一篇文献的代码,是动态多目标问题的,连接放这里,有兴趣的老哥可以看看
第一个,基于历史的,问题是他给的代码是函数,如何在platemo平台上跑呢,我试着处理了一下,报错,原来代码是这样的
- function [PopX,Pareto,POF_iter,POS_iter]=NSGAII22( Problem,popSize,MaxIt,t,T_parameter,group,Mp,hisPareto,Mm,ni,bi,ci,numi,init_pop)
- %% Generate random population
- % Population = Global.Initialization();
- CostFunction=Problem.FObj; % Cost Function
- nVar=size(Problem.XLow,1); % Number of Decision Variables
- VarSize=[nVar 1]; % Decision Variables Matrix Size
- detect_py=0;
- VarMin=Problem.XLow;
- VarMax=Problem.XUpp;
- T=size(hisPareto,2)+1;
-
- nObj=Problem.NObj;
- nPop=popSize; % Population Size (Number of Sub-Problems)
- nArchive=100;
- Lower = repmat(VarMin,1,nPop);
- Upper = repmat(VarMax,1,nPop);
- crossover_params.gamma=0.5;
- crossover_params.VarMin=VarMin;
- crossover_params.VarMax=VarMax;
- empty_individual.Position=[];
- empty_individual.Cost=[];
- pop=repmat(empty_individual,nPop,1);
- Off=repmat(empty_individual,nPop,1);
- Offspring=repmat(empty_individual,nPop,1);
- gailv=0.5;
- gailv2=0.1;
- zhixing1=1;
- zhixing2=1;
- traindata=[];
- testdata=[];
- if nargin == 6
- MaxIt=50;
- % MaxIt=1000;
- for i=1:nPop
- pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
- pop(i).Cost=CostFunction(pop(i).Position',t,T_parameter,group);
- end
复制代码
然后在 platemo 上是这样的:
- classdef NSGAII_HEL < ALGORITHM
- % <multi> <real/integer/label/binary/permutation> <constrained/none><dynamic>
- % Nondominated sorting genetic algorithm II
- %------------------------------- Reference --------------------------------
- % K. Deb, A. Pratap, S. Agarwal, and T. Meyarivan, A fast and elitist
- % multiobjective genetic algorithm: NSGA-II, IEEE Transactions on
- % Evolutionary Computation, 2002, 6(2): 182-197.
- %------------------------------- Copyright --------------------------------
- % Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for
- % research purposes. All publications which use this platform or any code
- % in the platform should acknowledge the use of "PlatEMO" and reference "Ye
- % Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
- % for evolutionary multi-objective optimization [educational forum], IEEE
- % Computational Intelligence Magazine, 2017, 12(4): 73-87".
- %--------------------------------------------------------------------------
- methods
- function main(Algorithm,Problem)
- %% Generate random population
- % Population = Global.Initialization();
- CostFunction=Problem.FObj; % Cost Function
- nVar=size(Problem.XLow,1); % Number of Decision Variables
- VarSize=[nVar 1]; % Decision Variables Matrix Size
- detect_py=0;
- VarMin=Problem.XLow;
- VarMax=Problem.XUpp;
- T=size(hisPareto,2)+1;
-
- nObj=Problem.NObj;
- nPop=popSize; % Population Size (Number of Sub-Problems)
- nArchive=100;
- Lower = repmat(VarMin,1,nPop);
- Upper = repmat(VarMax,1,nPop);
- crossover_params.gamma=0.5;
- crossover_params.VarMin=VarMin;
- crossover_params.VarMax=VarMax;
- empty_individual.Position=[];
- empty_individual.Cost=[];
- pop=repmat(empty_individual,nPop,1);
- Off=repmat(empty_individual,nPop,1);
- Offspring=repmat(empty_individual,nPop,1);
- gailv=0.5;
- gailv2=0.1;
- zhixing1=1;
- zhixing2=1;
- traindata=[];
- testdata=[];
- if nargin == 6
- MaxIt=50;
- % MaxIt=1000;
- for i=1:nPop
- pop(i).Position=unifrnd(VarMin,VarMax,VarSize);
- pop(i).Cost=CostFunction(pop(i).Position',t,T_parameter,group);
- end
- elseif nargin > 6
- if size(init_pop,1)< popSize
- newpop = addNoise(init_pop, popSize, size(init_pop,2));
- init_pop = [init_pop' newpop'];
- else
- init_pop = init_pop';
- end
- init_pop = max(min(init_pop,Upper),Lower);
- for i=1:size(init_pop,2)
- pop(i).Position=init_pop(:,i);
- pop(i).Cost=CostFunction(pop(i).Position',t,T_parameter,group);
- end
- end
复制代码 这可咋办
补充内容 (2023-11-4 17:58):
报错图片没出来,这里补上
未识别类 'FDA1' 的方法、属性或字段 'FObj'。
出错 NSGAII_HEL/main (第 22 行)
CostFunction=Problem.FObj; % Cost Function
出错 ALGORITHM/Sol... |