Nonlinear constraints in genetic algorithm are not fulfilled
7 views (last 30 days)
I'm trying to use a genetic algorithm for finding the global minimise of a non-analytic function. The ga() calls a function, which starts a extern simulation, which returns the value to minimise. In my simple example I use 2 variables. Both variables must be unsigned integers. The first one has predefined lower and upper limits. The second one has also lower and upper limits which are dependent on the actual value of the first variable:
x(1)_min <= x(1) <= x(1)_max (1)
x(1)^2 <= x(2) <= 2*x(1)^2 (2)
The first condition is defined in lower and upper values. The second one is defined as nonlinear constraint. Because x(1)_min and x(1)_max are positive values, x(2) should also be positive.
My problem is, that the defined nonlinear constraints are partially not fulfilled, when I take a look at the population after calculating. Some of the values of x(2) are negative, some are higher than 2*x(1)^2
Does anyone know, why this happens? Why are the cnstraints not fulfilled?
Best regards; J
% limits for x(1)
l = ; % lower limit for x(1)
u = ; % upper limit for x(1)
% Nonlinear constraint for x(2)
c = @(x)[x(1)^2-x(2); %x(1)^2 <= x(2)
x(2)-2*x(1)^2]; %x(2) <= 2*x(1)^2
ceq = @(x) ;
nonlinfcn = @(x)deal(c(x),ceq(x));
% Function to call extern simulation; actually for test cases a test-function which
% returns the value of f(x) = 2x(1)^2+0.5*x(2)
n=2; % number of variables
[x,fval,exitflag,output,population,scores] = ga(Fitness_function,n,,,,,...
Matt J on 28 Jan 2022
There is nothing ensuring that arbitrary population members in an arbitrary generation will satisfy nonlinear constraints. The final output x should satisfy constraints within the tolerances set by optimoptions if the solver was successful. The exitflag will indicate whether ga() felt that it was successful or not.