fmincon with multiple OR instead AND nonlinear constrains

3 views (last 30 days)
Hi, I am using fmincon to minimize y = A*x, where y , x and A are matrices. At each iteration estimated x is fed into my nonlinear constraint function [c,ceq] = nonlinfun(x). x is a matrix with 12 elements (3x4). Combination of the elements from x are used to create coefficients of 4th order polynomial, whose roots are used to calculate (using certain function), 6 4x1 vectors: Ax, Ay, Dx, Dy, ADx, ADy (they are pairs on complex plain Ax+1i*Ay, etc). And here is where my problem begins: only 3 elements out of each vector Ax, Ay, Dx, Dy, ADx, ADy have real meaning and I know constrains for them. One of the element of each vector is not constarined, but I can't now a priori which. Pairs of Ax with Ay, and ADx with ADy lie within the circle of radious a, centered at the point (0,0) (in the complex plain). So constrains would look like that:
function [c,ceq] = nonlinfun(x)
% first I calculate coefficients of 4th order polynomial, 2nd roots of the polynomial and that vectors Ax, Ay, Dx, Dy, ADx, ADy. Only here I form constraints:
a = 1;
c(1) = Ax(1)^2/(a^2) + Ay(1)^2/(a^2) - 1; % Point Ax(1)+1i*Ay(1) lies within a circle of radious a centered at (0,0).
c(2) = Ax(2)^2/(a^2) + Ay(2)^2/(a^2) - 1;
c(3) = Ax(3)^2/(a^2) + Ay(3)^2/(a^2) - 1;
c(4) = ADx(1)^2/(a^2) + ADy(1)^2/(a^2) - 1;
c(5) = ADx(2)^2/(a^2) + ADy(2)^2/(a^2) - 1;
c(6) = ADx(3)^2/(a^2) + ADy(3)^2/(a^2) - 1;
c(7) = Dx(1) - 1;
c(8) = Dx(2) - 1;
c(9) = Dx(3) - 1;
c(10) = Dy(1) - 0.5;
c(11) = Dy(2) - 0.5;
c(12) = Dy(3) - 0.5;
ceq = [];
But the problem is I do not know which of, let say Ax(1), Ax(2), Ax(3) or Ax(4) and the same for other vectors, should be discarded. Here I used only 1 to 3 elements of each vector, I didn't use 4th element for the constarins, but maybe I shouldn't use 1st or 2nd ... I would like to make OR statement with constraint 1 (elements 1,2,3 are ok, like above) OR constraint 2 (elements 1,2,4 are ok) OR constraint 3 (elements 1,3,4 are ok) OR constraint 4 (elements 2,3,4 are ok). Than using sugestion from here: http://uk.mathworks.com/help/optim/ug/writing-constraints.html#brhkghv-16, Section: OR instead of AND constraints to get nonlinear inequality constraints c = min(C1,C2,C3,C4). Unfortunately, it does not work, because C1,C2,C3,C4 are matrices, e.g C1 = c from the example above. Does anybody has idea if this sort of multiple OR constarints are posible with fmincon function? Thank you for any suggestions Ina

Accepted Answer

Walter Roberson
Walter Roberson on 30 Sep 2015
For example,
c_to_return =
min( [-all(c([1 2 3])<0), ...
-all(c([1 2 4])<0), ...
] );
each all() lists c values that must simultaneously be met. constraints are met when the c value is negative, and all() tests if they were all negative. all() being true would generate a 1, so the negative of that would be -1, with a negative value indicating that the composite is met. If the all is false then all() returns 0, negative that is 0, and if nothing else turns up satisfied then the min() of the all 0 vector would be 0 and non-compliance with constraints would be noted.
  3 Comments
John D'Errico
John D'Errico on 30 Sep 2015
Note that this may cause a failure to converge, since it generates a non-differentiable constraint.
Walter Roberson
Walter Roberson on 30 Sep 2015
min() can be rewritten in terms of Heaviside, as can be all(x<0). Therefore the result is differentiable if the individual c(:) are differentiable.
What it does lead to is a constraint in which the differentiation is not smooth. But that is the case for a linear constraints as well. A simple x + y <= 5 constraint almost always intercepts the curve at an angle and so is not smoothly differentiable either.

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 29 Sep 2015
Edited: John D'Errico on 29 Sep 2015
I'm sorry, but or between the constraints is simply not an option. Constraints for an optimizer like fmincon must all be satisfied.
I'd suggest that if this must be done, then solve the problem multiple times. I.e., solve it with constraint 1 (and only constraint 1) in place. THEN solve it with only constraint 2, and then with only constraint 3. Take the best of all solutions. The solution will satisfy your goal.

Community Treasure Hunt

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

Start Hunting!