필터 지우기
필터 지우기

Help with fmincon, non-linear constraints and binary variables

조회 수: 7 (최근 30일)
Giosuè Basso
Giosuè Basso 2023년 2월 20일
댓글: Giosuè Basso 2023년 2월 21일
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?

채택된 답변

Torsten
Torsten 2023년 2월 20일
편집: Torsten 2023년 2월 20일
It doesn't work because fmincon only handles continuous variables and functions.
Use "intlinprog" instead. Here you can define variables to be binary.
Another option is to run your code twice: Once with x = c1 and once with x = c2 and see which run gives the better value for the objective function. This is most probably the way to go because you seem to have nonlinear constraints in a function "con" that intlinprog cannot handle.
As a last option, use "ga".
  댓글 수: 1
Giosuè Basso
Giosuè Basso 2023년 2월 21일
The nonlinear constraints are just there to try and make y1 and y2 integers, but I'll try what you said, thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by