Genetic Algorithm Toolbox

edited December 2009 in Science & Tech
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...

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited October 2008
    Hi. Your code is impossible for me to read without the indentations. Please post the code inside
    [php]
    code goes here
    
    [/php]

    code tags.

    thanks.
  • edited October 2008
    %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
    
  • edited October 2008
    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...
  • edited October 2008
    [SIZE=2][FONT=Courier New][COLOR=#228b22]%Objective Function[/COLOR][/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]function[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] [CT] = objfun(CW,D)[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]DEW=1000;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]SS=4.74;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]i=10;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]L=100;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]j=10;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]CE=5;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]DP=2;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]CVM(1:i,1:j)=0;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]L(1:i,1:j)=L;[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] a=1:1:i [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] b=1:1:j[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]CV(a,b) = CW(a,b)/(CW(a,b)+SS*(1-CW(a,b)));[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]DEM(a,b) = 1*(SS*CV(a,b)+(1-CV(a,b)));[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]CSI(a,b)=0.0039*(CV(a,b)^0.803);[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] 0.3 <= CW(a,b) && CW(a,b)< 0.45;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]FCW(a,b) = 0.2067*CW(a,b)+1.035;[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] 0.45 <= CW(a,b) && CW(a,b)< 0.55;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]FCW(a,b) = 1.52*CW(a,b)+0.444;[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] 0.55 <= CW(a,b) && CW(a,b)< 0.70;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]FCW(a,b) = 6.1*CW(a,b)-2.075;[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] CW(a,b) < 0.3;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]C2(a,b)=0.75;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]CVM(a,b)=1.1;[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] 0.3 <=CW(a,b) && CW(a,b)< 0.7;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]C2(a,b)=2.135;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]CVM(a,b)=FCW(a,b)*(DP.^0.75)*0.75*(SS^0.5);[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] CW(a,b) > 0.7;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]fprintf([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#a020f0]'No economical solution exists'[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]CQM(a,b)=CVM(a,b)*pi/4;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]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;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]C3(a,b)= 210.89*L(a,b);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]C4(a,b)= 1.3744;[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]C(a,b)=C1(a,b)*D(a,b)^C2(a,b)+C3(a,b)*D(a,b)^C4(a,b);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]CT1= sum(C);[/FONT][/SIZE]
    [SIZE=2][FONT=Courier New]CT=sum(CT1,2)[/FONT][/SIZE]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT]
    [SIZE=2][FONT=Courier New][COLOR=#0000ff]end[/COLOR][/FONT][/SIZE]
    [SIZE=2][FONT=Courier New][COLOR=#0000ff]end[/COLOR][/FONT][/SIZE]
    
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited October 2008
    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?
  • edited October 2008
    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.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited October 2008
    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.
  • edited October 2008
    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
  • edited December 2009
    gatool ara yüzünü nasıl kullanıcagımı bilmiyorum, senin bilgin varsa yardımcı olurmusun veya tavsiye edebilecegin bir kaynak var mı dökümanın ingilizce olması sorun degil.
    simdiden tesekkürler
  • primesuspectprimesuspect Beepin n' Boopin Detroit, MI Icrontian
    edited December 2009
    Deniz wrote:
    gatool ara yüzünü nasıl kullanıcagımı bilmiyorum, senin bilgin varsa yardımcı olurmusun veya tavsiye edebilecegin bir kaynak var mı dökümanın ingilizce olması sorun degil.
    simdiden tesekkürler

    Siz çok daha İngilizce olarak eğer sonrası yardım almak için muhtemeldir. Hoşgeldiniz icrontic :)
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited December 2009
    Get your moonspeak out of my moonspeak thread.
  • primesuspectprimesuspect Beepin n' Boopin Detroit, MI Icrontian
    edited December 2009
    DEM(a,b) = 1*(SS*CV(a,b)+(1-CV(a,b)));
    CSI(a,b)=0.0039*(CV(a,b)^0.803);
  • edited December 2009
    Deniz wrote:
    gatool ara yüzünü nasıl kullanıcagımı bilmiyorum, senin bilgin varsa yardımcı olurmusun veya tavsiye edebilecegin bir kaynak var mı dökümanın ingilizce olması sorun degil.
    simdiden tesekkürler

    Merhabalar,
    Ben matlabdaki gatoolla biraz uğraştım, buralarada yazdım bir şeyler ama geri dönen bir şey olmadı. Bende çözemedim vazgeçtim.
    Sonra, C'de bi kod bulup onunla GA işlemini yaptırdım. Kalyanmoy Debin yazdıgı bir kod. benim işimi gördü sende kullanmak istersen bu ismi aratırsan, kendi sitesi var zaten ordaki kodu kullanabilirsin.
    Kolay gelsin
Sign In or Register to comment.