Help with fmincon, non-linear constraints and binary variables
Show older comments
Hello, I'm working on a problem that requires me to find the solution of a system subject to several inequalities so I decided to use fmincon to solve it.
One of the kinds of constraint is
x = min{c1, c2}
x is a variable part of a set of variables and c1 and c2 are dependent on the same set.
To implement this constraint I added the additional constraints:
x <= c1
x <= c2
x >= c1 + M*y1
x >= c2 + M*y2
y1 + y2 = 1
Where M is an adequately big number and y1 and y2 are additional binary variables (I know i could have used one, it seems to be working better with 2).
To impose y1 and y2 to be binary i used as lower bound 0 and as upper bound 1 in addition to the non linear condition mod([y1 y2],1) = [0 0].
Trying to figure out why it isn't working I tested it with the following code:
A = [1;1];
B = [5;1.6];
M = 10e5;
A_en = [A, [0 0;0 0];
-A,[M 0;0 M]];
B_en = [B;-B];
Aeq = [0 1 1];
Beq = 1;
obj = @(x) [-1 0 0]*x';
nf = [0 1 1];
nonlcon = @con;
OPTIONS = optimoptions('fmincon','Algorithm','interior-point');
fmincon(obj,[0 0 0],A_en,B_en,Aeq,Beq,[0 0 0],[Inf 1 1],nonlcon,OPTIONS)
where con is
function [c, ceq] = con(x)
c = [];
ceq = mod([x(2) x(3)],1);
end
I tried removing the non linear constraints too but the result never satisfies all the constraints.
Why shouldn't it work?
Accepted Answer
More Answers (0)
Categories
Find more on Write Constraints in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!