Borrar filtros
Borrar filtros

Help with fmincon, non-linear constraints and binary variables

7 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Torsten
Torsten el 20 de Feb. de 2023
Editada: Torsten el 20 de Feb. de 2023
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 comentario
Giosuè Basso
Giosuè Basso el 21 de Feb. de 2023
The nonlinear constraints are just there to try and make y1 and y2 integers, but I'll try what you said, thanks a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by