MATLAB: How to add some special constraints in ga optimization

gaMATLABmixed-integer programmingnonlinear constraints

Hello everyone, I am currently solving an Integer optimization problem, which involves some special constraints that I have no idea how to deal with them:
Suppose I need to minimize a function f(X), where X is an integer vector only contains "0"s and "1"s, i.e. X=[x1, x2 … xn];
Constraint 1: for any (2 to n)-th entries of vector X, if the X(i-1) entry is 0 and the sum of (1-X(i-5:i-1))<5, then the X(i) must be 0 (of course, if i<=5, the X(i) must be 0).
Constraint 2: for any (2 to n)-th entries of vector X, if the X(i-1) entry is 1 and the sum of X(i-8:i-1)<8, then the X(i) must be 1 (of course, if i<=8, the X(i) must be 1).
There also is known vector S=[s1,s2 … sn] in the objective function f(X), each one depends on the corresponding entry of the vector X, and such that:
Constraint 3: suppose s1 is given, for any (2 to n)-th entries of vector S, if X(i-1) is 1, then S(i)=0. If X(i-N+1:i-1) are all '0's and X(i-N) is 1, if N<=6 S(i)=1000; if N>6 S(i)=2000.
P.S. Can I use if-else conditions in the nonlinear constraint function file?
Thank you very much!!
Ying

Best Answer

The answer to your specific question is yes, of course, you can use if-else or any other MATLAB statement in a nonlinear constraint function.
As far as your constraints, it seems to me that constraint 1 states that for any i >= 5, x(i) can be 1 only if all previous x(j) = 1 for j < i. Is this true? My statement depends on all x(j) = 0 or 1. So the first x(i-1) that = 0 causes the sum x(i-5:i-1) to be 4, and makes x(i) = 0, and this continues.
If this is true, then constraint 2 is superfluous.
In your constraint 3, it seems to me impossible that "the sum of X(i-6:i-1)>6" because all the x(i) are either 0 or 1, so the sum is bounded above by 6.
Alan Weiss
MATLAB mathematical toolbox documentation