Subscripted assignment dimension mismatch in Genetic Algorithm

12 次查看(过去 30 天)
I'm getting the following error when trying to use the GA optimizer:
Subscripted assignment dimension mismatch.
Error in C:\Program
Files\MATLAB\R2012b\toolbox\globaloptim\globaloptim\private\gaminlppenaltyfcn.p>i_convectorizer
(line 135)
Error in C:\Program
Files\MATLAB\R2012b\toolbox\globaloptim\globaloptim\private\gaminlppenaltyfcn.p>gaminlppenaltyfcn
(line 57)
Error in C:\Program
Files\MATLAB\R2012b\toolbox\globaloptim\globaloptim\private\gaminlpengine.p>@(x)gaminlppenaltyfcn(x,problem,conScale)
(line 73)
Error in makeState (line 65)
Score = FitnessFcn(state.Population(initScoreProvided+1:end,:));
Error in galincon (line 18)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in C:\Program
Files\MATLAB\R2012b\toolbox\globaloptim\globaloptim\private\gaminlpengine.p>gaminlpengine
(line 37)
Error in C:\Program
Files\MATLAB\R2012b\toolbox\globaloptim\globaloptim\private\gaminlp.p>gaminlp (line 37)
Error in ga (line 342)
[x,fval,exitFlag,output,population,scores] = gaminlp(FitnessFcn,nvars, ...
Error in denemeC3PO (line 12)
[x, fval] = ga(@minusProfit, nVars,[],[],[],[], LB, UB, @constr, IntCon);
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
Since at the end of the error message it says the problem is with the fitness function, I've tested it by itself, without using it in GA, and it works without any error...
I can also share my code for fitness and constraint functions if that would help.

回答(2 个)

Jan
Jan 2013-5-4
To be exact, the error message tells you:
Failure in initial user-supplied fitness function evaluation.
This does not mean, that there is a bug in the fitness function itself. You can test this using the debugger by setting a breakpoint in the fitness function.
  1 个评论
Sukru
Sukru 2013-5-5
Thanks. I did that, but found nothing wrong with the fitness function. On the other hand, the optimization worked when I commented out lines between 15-41 of my constrint function here: https://gist.github.com/shasdemir/18eaeda95833b6618113
It is weird, because the constraint function works when I call it by itself outside of ga.
I'm puzzled...

请先登录,再进行评论。


Alessandro
Alessandro 2014-7-14
Hi Sukru,
I'm experiencing the same issue as you had and I'm really stuck 'cause, as you said, both fitness function and constraint function work well. Actually, I'm running the genetic algorithm several times inside a loop to test different stuffs and this problem comes quite randomly but never at the first time.
Did you solve your problem without commenting the constraint function? (by the way, the link is no more available, so I don't know how did you figure out the problem with the constraint function)
Thank you for your help.
Alessandro
  3 个评论
Abdelmoumene ARAFI
Abdelmoumene ARAFI 2021-2-18
I have the same problem here, the fitness function and the constraints function work well, whene i run them outside ga (optimtool). I didn't figure out your solution could you please explaine to me more.
Thank you
Walter Roberson
Walter Roberson 2021-2-18
Alessandro had a nonlinear constraints function that looked something like
c(1:5) = x(1:5).^2 - pi %x^2<=pi
if x(6) > x(7)/2
c(6:7) = sin(x(6:7)*5*pi) - 0.3;
else
c(6) = 0;
end
Notice that in some of the cases the computed c is length 6 and in other cases it is length 7. For nonlinear constraints to work, you always need to return the same length.
Also, it is best not to re-use slots for different purposes, so nothing like
if x(6) > x(7)/2
c(1:2) = sin(x(6:7)*5*pi) - 0.3;
c(3:5) = 0;
else
c(1:5) = x(1:5).^2 - pi %x^2<=pi
end
Where the number of slots is consistent, but they mean different things at different times. If you do that, then MATLAB will not be able to figure properly which direction to go to satisfy constraints near the boundaries.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by