optimization multiobjective using pso
1 view (last 30 days)
Show older comments
Hi every one,I need help to identify non-dominated points on a Pareto frontier corresponding to this multi-objective problem using epsilon constraint method;
error(Error using obj_eps1 (line 7)
Not enough input arguments.
Error in main1 (line 11).
[gbest]=PSOalgo(n,maxite,lb,ub,dim,obj_eps1,nonlcon_eps1,EpsVal(i))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% constraint function
function [C,Ceq,constraintViolation] = nonlcon_eps1(x,EpsVal)
constraintViolation= 0;
Ceq = [];
Tp=140;Tf= 600;
m=3;n=8000;
s=0;q=1;
H=q*(((x+s)/n).^m);
% %%%%% A is a function varying from 0 to 1
C(1)= EpsVal-(x/(x+Tp+Tf*H));
if C(1) > 0
constraintViolation= constraintViolation+ 1;
end
%%%%%%%%%%%%%%%%%%%%%%%%% objective function
function f = obj_eps1(x,~)
Tp=140 ;Tf= 600;
Cp=5000;Cf=35000;
m=3;etta=8000;
s=0;q=1;
% % % % cost function
f=(Cp+Cf*q*(((x+s)/etta)^m))/(x+Tp+Tf*q*(((x+s)/etta)^m));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%% main.m
x0 = 1; % Starting point
ub = 25000; % Upper bound
lb = 1; % Lower bound
maxite = 1000;
dim = 2;
n = 50; % Number of Pareto points
eps_min = 0.50;
eps_max = 0.95;
EpsVal = eps_min:(eps_max - eps_min)/(n-1):eps_max;
for i=1:n
[gbest]=PSOalgo(n,maxite,lb,ub,dim,obj_eps1,nonlcon_eps1,EpsVal(i));
end
figure(1);
plot(xopt(:,1), xopt(:,2), 'rs');
xlabel('\F')
ylabel('\c')
title('Pareto Front Example - Epsilon Constraint')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [gbest]= PSOalgo(n,maxite,lb,ub,dim,obj_eps1,nonlcon_eps1,EpsVal)
% initialization
% ite= 1000;
wmax=0.9; % inertia weight
wmin=0.4; % inertia weight
c1=2; % acceleration factor
c2=2; % acceleration factor
% pso initialization
X=initialization(n,dim,ub,lb);
v = 0.1*X; % initial velocity
for i=1:n
fitnessX(i,1)= obj_eps1(X(i,:));
end
[fmin0,index0]= min(fitnessX);
pbest= X; % initial pbest
pbestfitness = fitnessX;
gbest= X(index0,:); % initial gbest
gbestfitness = fmin0;
ite=0; % Loop counter
while ite<maxite
w=wmax-(wmax-wmin)*ite/maxite; % update inertial weight
% pso velocity updates
for i=1:N
for j=1:dim
v(i,j)=w*v(i,j)+c1*rand()*(pbest(i,j)- X(i,j)) + c2*rand()*(gbest(1,j)- X(i,j));
end
end
% pso position update
for i=1:N
for j=1:dim
X(i,j)= X(i,j)+v(i,j);
end
% Check boundries
FU=X(i,:)>ub;
FL=X(i,:)<lb;
X(i,:)=(X(i,:).*(~(FU+FL)))+ub.*FU+lb.*FL;
% evaluating fitness
fitnessX(i,1) = fobj(X(i,:));
[~,consentViolation(i,1)] = nonlcon_eps1(X(i,:), EpsVal);
end
% updating pbest and fitness
for i=1:N
if fitnessX(i,1) < pbestfitness(i,1) && constraintViolation(i,1) == 0
pbest(i,:)= X(i,:);
pbestfitness(i,1)= fitnessX(i,1);
end
[~,constraintViolation(i,1)] = nonlcon_eps1(pbest(i,:), EpsVal);
end
% updating gbest and best fitness
for i=1:N
if pbestfitness(i,1)<gbestfitness && constraintViolation(i,1) == 0
gbest=pbest(i,:);
gbestfitness= pbestfitness(i,1);
end
end
ite = ite+1;
end
end
0 Comments
Answers (1)
Walter Roberson
on 8 Dec 2020
function f = obj_eps1(x,~)
That says that obj_eps1 expects to be passed two input arguments.
[gbest]=PSOalgo(n,maxite,lb,ub,dim,obj_eps1,nonlcon_eps1,EpsVal(i))
That line says that obj_eps1 should be invoked with no inputs, and whatever it returns should be passed in as the 6th input to
function [gbest]= PSOalgo(n,maxite,lb,ub,dim,obj_eps1,nonlcon_eps1,EpsVal)
and
[~,constraintViolation(i,1)] = nonlcon_eps1(pbest(i,:), EpsVal);
That says that whatever is passed as the 6th parameter to PSOalgo must be either an array with at least two indices, or else must be a function handle with at least two inputs.
Therefore, when you invoke obj_eps1 in the line
[gbest]=PSOalgo(n,maxite,lb,ub,dim,obj_eps1,nonlcon_eps1,EpsVal(i))
then you need obj_eps1 to return the handle to a function that accepts at least two inputs.
I would suggest to you that what you wanted was
[gbest] = PSOalgo(n, maxite, lb, ub, dim, @obj_eps1, @nonlcon_eps1, EpsVal(i))
0 Comments
See Also
Categories
Find more on Multiobjective Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!