(Edit: Please read answers/comments before pointing out code mistakes.)
I am trying to run a GA where the solutions are an array of integer values that are either 0 or 1. The inequalities are not dependent only on the solution variable(s), but also additional variables that I pass along.
Simplyfing things a bit, the setup is:
Each solution "x" contains 100 values. "y" contains two structs. The first 50 values of "x" refer to y(1).data and the other 50 refer to y(2).data. Therefore, when checking the inequalities, the same constraints are applied to each part of "x" (in this case, two parts of 50 values each).
The solutions are subject to ga_constraints function below, where non-linear inequalities are set.
constraints.var1 = 60;
constraints.var2 = 30;
ObjectiveFunction = @(x) ga_fitness(x,y,z);
ConstraintFunction = @(x) ga_constraints(x,y,constraints);
nvars = 100;
lb = zeros(1,nvars);
ub = ones(1,nvars);
IntCon = linspace(1,nvars,nvars);
x = ga(ObjectiveFunction,nvars,,,,,lb,ub,ConstraintFunction,IntCon);
And the constraint function is something like this:
function c = ga_constraints(x,y,constraints)
for i = 1:length(y)
c(i) = - aux_min_val + constraints.var1;
c(i + length(y)) = sum(x_segment) - constraints.var2;
For an example of having only y(1) and y(2), the output "c" will be a vector of 4 values.
The error is:
Error using ga (line 393)
Too many output arguments.
Error in ga_main (line 62)
x = ga(ObjectiveFunction,nvars,...
Failure in initial user-supplied nonlinear constraint function evaluation.
Could someone point me to the right direction to investigate what's wrong? I don't know what to do with the error since it doesn't give me any more information than that.