Nonlinear Optimization problem ( If statement)

Hello everyone,
I'm tryng to solve a nonlinear optimization problem (constrained) using fmincon with 2232 variables (three vectors x,y,z of 744 elements).
I would like to add an "if condition" to the costraints, something like this:
for i=1:744
if x(i)>=650
y(i)<100
else
y(i)<50
end
end
it gives me the following error message :
"Conversion to logical from optim.problemdef.OptimizationInequality is not possible."
How can I add that kind of constraint?Is it possible with fmincon? If not, what solver would be the best choice?

3 comentarios

Ameer Hamza
Ameer Hamza el 24 de Abr. de 2020
This for loop is part of which function?
X and Y are vectors of 744 elements. The for and the if loops,together, set the constraint of each element of X. If the element Y(i) is above 650, the constraint on X(i) is X(i)<100; if y(i) is less than 650, the constraint is X(i) <50
You mentioned that you get this error
"Conversion to logical from optim.problemdef.OptimizationInequality is not possible."
Can you show the code which cause this error?

Iniciar sesión para comentar.

 Respuesta aceptada

Matt J
Matt J el 24 de Abr. de 2020
Editada: Matt J el 24 de Abr. de 2020
To do that, each x(i) must have finite upper and lower bounds L(i)<=x(i)<=U(i). You also need to introduce additional unknown binary variables b(i) and express your constraints with the following linear inequalities,
b(i)>=(x(i)-650)/(U(i)-650) + eps %Forces b(i)=1 when x(i)>=650
b(i)<=(x(i)-L(i))/(650-L(i))-eps %Forces b(i)=0 when x(i)<650
y(i)<=50+50*b(i)
Since fmincon does not allow integer variables, you will need to use ga or intlinprog instead.

9 comentarios

Thanks for the answer. I will try ga algorithm.
(the number of variables is quite high.Isn't it a problem?)
Walter Roberson
Walter Roberson el 27 de Abr. de 2020
You will probably need to permit a large number of iterations in order to get a good solution with so many variables.
Matt J
Matt J el 27 de Abr. de 2020
In the case of ga(), increasing the population size might also be necessary.
I've tried both (intlinprog e ga), but I still have some doubts:
intlinprog performs well, but I need non linear constraints so the only possible choice is ga (I think).
Genetic Algorithm seems very slow and it doesn't converge to a global minimum. Do you have any advice on how to set population size, number of generations, pareto fraction etc. ?
Matt J
Matt J el 27 de Abr. de 2020
How do you know it doesn't converge to a global minimum?
I've made a mistake...it doesn't converge at all in 4 hours, even if I use 72 variables instead of 2232. Maybe I don't set the options properly (it's the first time that I use ga). I've set pupulation=100 while pareto fraction is still at its default value
Matt J
Matt J el 27 de Abr. de 2020
Again, how do you know it's not converging? The Pareto parameters should be irrelevant to ga.
Walter Roberson
Walter Roberson el 28 de Abr. de 2020
Logically speaking, you cannot know that you have found the minima unless you have tested both sides of each discontinuity. With 774 variables each with a discontinuity, then logically speaking you cannot know that you have found the minima without at least 2^774 function calculations.
This number could potentially be drastically reduced if you could partition the system into linear combinations of subproblems that you can minimize independently.
Ok, so there is no way to make it faster. I got it.
If no other solver can handle this kind of problem (many variables, integer and continuous variables, non-linear constraints), I'll try to change it a little bit to make it easier.
Thank you for the answers!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by