From: koichan on 9 Jan 2010 09:34 Hi everyone! I really need you to help me with this error. I am trying to use GA for warehousing location problem for my project. I have been trying to solve it for many days but couldn't find the way. I would be very very appreciate if you can help me. My inputs are: x0=[0 0 0 0]; y0=[0 0]; x0=[x0 y0]; ct = [2 3 4 5]; w = [3 4 5 6]; p = [4 4 4 4]; f = [3 5]; ct_w_p=ct.*w.*p; ct_w_p_f=[ct_w_p f]; Var=size(x0); Dim_con=size(f); Dim_con_n=Dim_con(2); fn=@(x)Fitness(x,ct_w_p_f); Nvar=Var(1)*Var(2); NonCon=@(x)fnCon(x,Dim_con_n); options=gaoptimset('Vectorized','on'); [x,fval,exitflag] = ga(fn,Nvar,[],[],[],[],[],[],NonCon,options) My objective function is: function OBJ = Fitness(x,ct_w_p_f) OBJ=sum(x(:,:).*ct_w_p_f(:,:))%>>>>>>>>>>>>>>>>>>>this is a summation of all element end My constraints are: function [c,ceq] = fnCon(x,Dim_con_n) int8(x) Transac=reshape(x,Dim_con_n,[]);%>>>>Here, I am trying to make sure that summation of x1&x3<=Transac_size(2)*x5,sum x2&x4<=Transac_size(2)*x6 Transac=Transac'; for i=[1:Dim_con_n] for j=[1:Dim_con_n] Cust_tran(i,j)=Transac(i,j); end end Sum_cust=sum(Cust_tran); Transac_size=size(Transac); for j=[1:Transac_size(2)] WH_tran(j)=Transac(Transac_size(1),j); c(:,j)=[ Sum_cust(j)-(Transac_size(2)*WH_tran(j))] end %To assign binary%x>=0,x<=1 ForCdim=size(x);%>>>>>>>>>>>>>Here, I am trying to make sure that all x(j)<=1 for j=[1:ForCdim(1,2)] AssignC=size(c); c(:,AssignC(1,2)+1) = [x(j)-1] end for j=[1:ForCdim(1,2)]%>>>>>>>Here, I am trying to make sure that all x(j)>=0 AssignC=size(c); c(:,AssignC(1,2)+1)= [-x(j)] end Customer=sum(reshape(x,Dim_con_n,[]));>>>>>>>Here, I am trying to make sure that sum x1&x2,x3&x4,x5&x6 are all equal to 1 for j=[1:Dim_con_n+1] ceq(:,j)= [Customer(j)-1] end end The problems are: 1. I am trying to vectorized obj fn and constraint but I always get the error stated that : ??? Attempted to access cin(:,15); index out of bounds because size(cin)=[1,14]. Error in ==> augLagFun at 115 shiftedConstr(:,i) = augLagStruct.shift - cin(:,i) + tolcon; Error in ==> gacon>@(x)augLagFun(x,FitnessFcn,NonconFcn,1,GenomeLength,gaAugParam,numNonlinIneqcstr,numNonlinEqcstr,numNonlinCstr,options.TolCon,options.FitnessFcnArgs,options.NonconFcnArgs) at 33 SubFitness = @(x) augLagFun(x,FitnessFcn,NonconFcn,1,GenomeLength, ... Error in ==> makeState at 61 Score = FitnessFcn(state.Population(initScoreProvided+1:end,:)); Error in ==> gacon at 40 state = makeState(GenomeLength,SubFitness,Iterate,subtype,options); Error in ==> ga at 285 [x,fval,exitFlag,output,population,scores] = gacon(FitnessFcn,nvars, ... Error in ==> Main at 30 [x,fval,exitflag] = ga(fn,Nvar,[],[],[],[],[],[],NonCon,options) Caused by: Failure in initial user-supplied fitness function evaluation. GA cannot continue. 2. I don't under stand why I still get -x(j) for the first loop of the results and also the other constraints are not satisfied. Thank you
|
Pages: 1 Prev: Bluetooth and MATLAB Next: fasted way to calcluate min value in A(:,2)for every possibleA(1,:) |