Using GA can I put a condition on Population?
1 view (last 30 days)
I am using GA, with nvars=32 and IntCon=1:32, so 32 integers
I want the first 16 elements be ascending and the last 16 elements no matter the order, and both of them respect the lb and ub.
Is there any way to obligate the population be between 0-60 with ascending order for the first 16 elements? (this 16 elements represent time so I can't have one value greater than the next value).
Alan Weiss on 4 May 2022
Sure, that is a simple linear inequality constraint. Probably easiest to represent using the problem-based formulation, but do what you like. In solver-based:
A = zeros(15,32);
for i = 1:15
A(i,i) = 1;
A(i,i+1) = -1; % means x(i) - x(i+1) <= 0
b = zeros(15,1);
You can use sparse matrices and MATLAB constructs to make this matrix, but this is fast enough.
MATLAB mathematical toolbox documentation