functions may be used incompatibly or redefined

3 Ansichten (letzte 30 Tage)
SREETHU S
SREETHU S am 26 Mär. 2019
Kommentiert: SREETHU S am 26 Mär. 2019
i am encountering problems such as:
  1. the functions updatepopulation,trimr may be used incompatibly or redefined.
  2. the values of xnew,ynew,fnew may not be used.
how should i solve these problems.
my code is as given below.
function Jaya()
clc;
clear all;
RUNS=20;
runs=0;
while(runs<RUNS)
pop=5; % population size
var=8; % no. of design variables
maxFes=500;
maxGen=floor(maxFes/pop);
mini=[110 110 110 110 110];
maxi=[130 130 130 130 130];
ymini=[135 270 207];
ymaxi=[165 330 253];
% [row,var]=size(mini);
x=[118 118.1 118.2 118.3 188.5;118.6 118.7 118.8 118.89 118.9;119.1 119.2 119.3 119.4 119.5;119.6 119.7 119.8 119.9 120;120.1 120.2 120.3 120.4 120.5];
y=[141 315 222;142 321 213;146 295 212;148 298 209;157 287 248];
for i= 1:5
x(:,i)=min(x(:,i))+(max(x(:,i))-min(x(:,i)))*rand(5,1);
end
a = x;
for i=1:3
y(:,i)=min(y(:,i))+(max(y(:,i))-min(y(:,i)))*rand(5,1);
end
b=y;
g = epanet('network1.inp');
for m = 1:5;
RC = g.getLinkRoughnessCoeff;
RC(1) = a(m,1);
RC(2) = a(m,2);
RC(3) = a(m,3);
RC(4) = a(m,4);
RC(5) = a(m,5);
g.setLinkRoughnessCoeff(RC);
D=g.getNodeBaseDemands;
D{1}(2)=b(m,1);
D{1}(3)=b(m,2);
D{1}(3)=b(m,3);
g.setNodeBaseDemands(D);
g.openHydraulicAnalysis;
g.initializeHydraulicAnalysis;
g.runHydraulicAnalysis;
LF(m) = g.getLinkVelocity(1);
Q = LF';
end
ch=1;
gen=0;
f = Q;
while(gen<maxGen)
xnew=updatepopulation(x,f);
xnew=trimr(mini,maxi,xnew);
ynew=updatepopulation(y,f);
ynew=trimr(ymini,ymaxi,ynew);
g = epanet('network1.inp');
for m = 1:5;
RC = g.getLinkRoughnessCoeff;
RC(1) = xnew(m,1);
RC(2) = xnew(m,2);
RC(3) = xnew(m,3);
RC(4) = xnew(m,4);
RC(5) = xnew(m,5);
g.setLinkRoughnessCoeff(RC);
D=g.getNodeBaseDemands;
D{1}(2)=ynew(m,1);
D{1}(3)=ynew(m,2);
D{1}(3)=ynew(m,3);
g.setNodeBaseDemands(D);
g.openHydraulicAnalysis;
g.initializeHydraulicAnalysis;
g.runHydraulicAnalysis;
LFnew(m) = g.getLinkVelocity(1);
Qnew = LFnew';
end
fnew= Qnew;
for i=1:5
if(fnew(i)>f(i))
x(i,:)=xnew(i,:);
y(i,:)=ynew(i,:);
f(i)=fnew(i);
end
end
disp('%%%%%% Final population%%%%%%%');
disp([x,y,f]);
fnew=[];xnew=[]; ynew=[];
gen=gen+1;
fopt(gen)=max(f(:));
end
runs=runs+1;
[val,ind]=max(fopt);
Fes(runs)=pop*ind;
best(runs)=val;
end
bbest=max(best);
mbest=mean(best);
wbest=min(best);
stdbest=std(best);
mFes=mean(Fes);
for i=1:5
Cmax(i)=max(x(:,i))
end
for i =1:3
qmax(i+1)=max(y(:,i))
end
Fmax = max(Q(:));
fprintf('\n best=%f',bbest);
fprintf('\n mean=%f',mbest);
fprintf('\n worst=%f',wbest);
fprintf('\n std. dev.=%f',stdbest);
fprintf('\n mean Fes=%f',mFes);
for i=1:5
fprintf('\n ROUGHNESS COEFF =%f',Cmax(i));
end
for i =1:3
fprintf('\n NODAL DEMAND = %f',qmax(i+1));
end
fprintf('/n FLOW MAX = %f',Fmax);
end
function[z]=trimr (mini,maxi,x)
[row,col]=size(x);
for i=1:col
x(x(:,i)<mini(i),i)=mini(i);
x(x(:,i)>maxi(i),i)=maxi(i);
end
z=x;
end
function[zy]=trimr(ymini,ymaxi,y)
[row,col]=size(y);
for i=1:col
y(y(:,i)<mini(i),i)=mini(i);
y(y(:,i)>maxi(i),i)=maxi(i);
end
zy=y;
end
function [xnew]= updatepopulation(x,f)
[row,col]=size(x);
[t,tindex]=max(f);
Best=x(tindex,:);
[w,windex]=min(f);
worst=x(windex,:);
xnew=zeros(row,col);
for i=1:row
for j=1:col
r=rand(1,2);
xnew(i,j)=x(i,j)+r(1)*(Best(j)-abs(x(i,j)))-r(2)*(worst(j)-abs(x(i,j)));
end
end
end
function [ynew]= updatepopulation(y,f)
[row,col]=size(y);
[~,tindex]=max(f);
Best=y(tindex,:);
[w,windex]=min(f);
worst=y(windex,:);
ynew=zeros(row,col);
for i=1:row
for j=1:col
r=rand(1,2);
ynew(i,j)=y(i,j)+r(1)*(Best(j)-abs(y(i,j)))-r(2)*(worst(j)-abs(y(i,j)));
end
end
end
  2 Kommentare
Steven Lord
Steven Lord am 26 Mär. 2019
Show the full and exact text of any error (red text) or warning (orange text) messages you receive when you run this code. Don't trim or summarize the messages, copy them verbatim from the Command Window into a comment on this post. The error or warning messages will likely have information that will help in debugging the cause of the error or warning.
SREETHU S
SREETHU S am 26 Mär. 2019
thank you for the response.. infact i do not get any error message while running the program. but the problem is i'm not getting the proper results. i am supposed to find a maximum value, but the code is not returning the maximum value. but on the 'message indicator', these errors are being shown.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Mär. 2019
You have two copies of the definition of trimr and updatepopulation

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by