PDA

View Full Version : Genetic Algorithm Toolbox


burhan
7 Oct 2008, 02:11pm
Hello all,
I am using matlab genetic algortihm tool to solve a function. I can have a result when I give numbers to my variables but genetic algorithm toolbox can not solve and gives an error message as "Subscripted assignment dimension mismatch."
But if there is any dimension mismatch on my function even it could not give the result when I solve it by giving the numbers isn't it?
I am giving my function here
%Objective Function
function [CT] = objfun(CW,D)
DEW=1000;
SS=4.74;
i=10;
L=100;
j=10;
CE=5;
DP=2;
CW(1:i,1:j)=CW;
CVM(1:i,1:j)=0;
L(1:i,1:j)=L;
D(1:i,1:j)=D;
for a=1:1:i
for b=1:1:j
CV(a,b) = CW(a,b)/(CW(a,b)+SS*(1-CW(a,b)));
DEM(a,b) = 1*(SS*CV(a,b)+(1-CV(a,b)));
CSI(a,b)=0.0039*(CV(a,b)^0.803);
if 0.3 <= CW(a,b) && CW(a,b)< 0.45;
FCW(a,b) = 0.2067*CW(a,b)+1.035;
end
if 0.45 <= CW(a,b) && CW(a,b)< 0.55;
FCW(a,b) = 1.52*CW(a,b)+0.444;
end
if 0.55 <= CW(a,b) && CW(a,b)< 0.70;
FCW(a,b) = 6.1*CW(a,b)-2.075;
end
if CW(a,b) < 0.3;
C2(a,b)=0.75;
CVM(a,b)=1.1;
end
if 0.3 <=CW(a,b) && CW(a,b)< 0.7;
C2(a,b)=2.135;
CVM(a,b)=FCW(a,b)*(DP.^0.75)*0.75*(SS^0.5);
end
if CW(a,b) > 0.7;
fprintf('No economical solution exists');
end;
CQM(a,b)=CVM(a,b)*pi/4;
C1(a,b)=CE*365*24*DEM(a,b)*CQM(a,b)*CSI(a,b)*(CVM(a,b)^1.77)*L(a,b)/101.94;
C3(a,b)= 210.89*L(a,b);
C4(a,b)= 1.3744;
C(a,b)=C1(a,b)*D(a,b)^C2(a,b)+C3(a,b)*D(a,b)^C4(a,b);
CT1= sum(C);
CT=sum(CT1,2)
end
end
end
If anyone could help me I would be very glad.
Thanks...

shwaip
7 Oct 2008, 05:24pm
Hi. Your code is impossible for me to read without the indentations. Please post the code inside
code goes here

code tags.

thanks.

burhan
7 Oct 2008, 08:44pm
%Objective Function
function [CT] = objfun(CW,D)

DEW=1000;
SS=4.74;
i=10;
L=100;
j=10;
CE=5;
DP=2;
CW(1:i,1:j)=CW;
CVM(1:i,1:j)=0;
L(1:i,1:j)=L;
D(1:i,1:j)=D;
for a=1:1:i
for b=1:1:j
CV(a,b) = CW(a,b)/(CW(a,b)+SS*(1-CW(a,b)));
DEM(a,b) = 1*(SS*CV(a,b)+(1-CV(a,b)));
CSI(a,b)=0.0039*(CV(a,b)^0.803);
if 0.3 <= CW(a,b) && CW(a,b)< 0.45;
FCW(a,b) = 0.2067*CW(a,b)+1.035;
end
if 0.45 <= CW(a,b) && CW(a,b)< 0.55;
FCW(a,b) = 1.52*CW(a,b)+0.444;
end
if 0.55 <= CW(a,b) && CW(a,b)< 0.70;
FCW(a,b) = 6.1*CW(a,b)-2.075;
end
if CW(a,b) < 0.3;
C2(a,b)=0.75;
CVM(a,b)=1.1;
end
if 0.3 <=CW(a,b) && CW(a,b)< 0.7;
C2(a,b)=2.135;
CVM(a,b)=FCW(a,b)*(DP.^0.75)*0.75*(SS^0.5);
end
if CW(a,b) > 0.7;
fprintf('No economical solution exists');
end;
CQM(a,b)=CVM(a,b)*pi/4;
C1(a,b)=CE*365*24*DEM(a,b)*CQM(a,b)*CSI(a,b)*(CVM(a,b)^1.77)*L(a,b)/101.94;
C3(a,b)= 210.89*L(a,b);
C4(a,b)= 1.3744;
C(a,b)=C1(a,b)*D(a,b)^C2(a,b)+C3(a,b)*D(a,b)^C4(a,b);
CT1= sum(C);
CT=sum(CT1,2)
end
end

end

burhan
8 Oct 2008, 12:03pm
Hi shwaip,
First of all thanks for your interest, I wrote this on my previous message but it is not seen.
Anyway, I think I solved my problem on my dimension mismatch. I erased the lines
CW(1:i,1:j)=CW;
and
D(1:i,1:j)=D;
and the error disappearded.
But there is a new error disapperad now and I now want your help for the new error
now the toolbox says D is undefined, but it is my variable. Do you think I do any mistake by defining my variables.
I am posting my new function on the next message,
Thanks for your kind helps...

burhan
8 Oct 2008, 12:04pm
%Objective Function
function [CT] = objfun(CW,D)
DEW=1000;
SS=4.74;
i=10;
L=100;
j=10;
CE=5;
DP=2;
CVM(1:i,1:j)=0;
L(1:i,1:j)=L;
for a=1:1:i
for b=1:1:j
CV(a,b) = CW(a,b)/(CW(a,b)+SS*(1-CW(a,b)));
DEM(a,b) = 1*(SS*CV(a,b)+(1-CV(a,b)));
CSI(a,b)=0.0039*(CV(a,b)^0.803);
if 0.3 <= CW(a,b) && CW(a,b)< 0.45;
FCW(a,b) = 0.2067*CW(a,b)+1.035;
end
if 0.45 <= CW(a,b) && CW(a,b)< 0.55;
FCW(a,b) = 1.52*CW(a,b)+0.444;
end
if 0.55 <= CW(a,b) && CW(a,b)< 0.70;
FCW(a,b) = 6.1*CW(a,b)-2.075;
end
if CW(a,b) < 0.3;
C2(a,b)=0.75;
CVM(a,b)=1.1;
end
if 0.3 <=CW(a,b) && CW(a,b)< 0.7;
C2(a,b)=2.135;
CVM(a,b)=FCW(a,b)*(DP.^0.75)*0.75*(SS^0.5);
end
if CW(a,b) > 0.7;
fprintf('No economical solution exists');
end;
CQM(a,b)=CVM(a,b)*pi/4;
C1(a,b)=CE*365*24*DEM(a,b)*CQM(a,b)*CSI(a,b)*(CVM(a,b)^1.77)*L(a,b)/101.94;
C3(a,b)= 210.89*L(a,b);
C4(a,b)= 1.3744;
C(a,b)=C1(a,b)*D(a,b)^C2(a,b)+C3(a,b)*D(a,b)^C4(a,b);
CT1= sum(C);
CT=sum(CT1,2)
end
end
end

shwaip
8 Oct 2008, 12:49pm
I'm not really that familiar with the genetic algorithm toolbox, but can you include all the code that you've written? Not just the objective function?

burhan
8 Oct 2008, 01:40pm
That's all for my code, I'm solving this function on genetic algortihm toolbox by just writing the code's name and the number of variables as 2.

shwaip
13 Oct 2008, 07:51pm
Hi.

I'm sorry I've not been responding to this...i've been driving across the country with no access to 'net or matlab.

How are you calling this function with the genetic algorithm toolbox? I can't really troubleshoot without being able to replicate the exact error.

burhan
14 Oct 2008, 10:06am
No problem, you helped me a lot already,
And genetic algortihm toolbox is easy to use, I just write my function name and number of variables on the blanks, I solved some examples by hand and with it and it works but it gives error to my function, I couldnt understand