I am working on Constrained Minimisation using ga tool. When i input the non linear constraint function that accepts x as the input i get an error stating:Attempted to access x(1); index out of bounds because numel(x)=0.

1 view (last 30 days)
The problem has 60 variables and i am using the bitstring population type. When i input the non linear constraint function i get an error saying: Attempted to access x(1); index out of bounds because numel(x)=0.
I then took up a simple basic problem in optimization with the following criteria: 1. fitness function
function op = samfun(x)
op=x(1)^2+x(2)^2-2*x(1)*x(2);
end
2. Constraint function
function [ c,ceq ] = samcon(x)
ceq(1)=x(1)^2+x(2)-100; ceq(2)=x(1)-x(2)^2-20;
c=[];
end
*3. Number of variables:3
*4. Population type:bitstring (I need 0 or 1 only in my original problem) 5. Selection: Roulette 6. Default initial population:creation function is uniform
When i input the above in the ga tool (Note: the input syntax is correct)I still get the message that i got in my original problem:
Attempted to access x(1); index out of bounds because numel(x)=0.
Since it says x(1) does it mean that x does not exist and it is trying to access x?? This does not make sense as i followed the same syntax as given in the matlab help tutorial??? Does it have anything to do with bitstring population type??? Pls help. Thanks in advance.

Answers (1)

Alan Weiss
Alan Weiss on 23 Oct 2013
According to the documentation for bitstring type, for members of a bitstring population "You cannot use a Hybrid function, and ga ignores all constraints, including bounds, linear constraints, and nonlinear constraints."
I suggest that you use mixed integer optimization instead of bitstring. However, mixed integer optimization requires that you have no equality constraints, only inequality constraints. There is an example showing how to attempt to get around this restriction.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Community Treasure Hunt

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

Start Hunting!