How to set specific variables in fmincon to be integers only?

58 Ansichten (letzte 30 Tage)
Dear all,
I am interested in finding the maximum of a function with three variables and two inequality constraints using fmincon.
One of the variable is an integer and another variables is an angle, which can only vary by half a degree. I would really appreciate if anyone can help me to set specific variables to vary as integers and/ by 0.5.
Thanks

Akzeptierte Antwort

Matt J
Matt J am 25 Feb. 2020
Bearbeitet: Matt J am 25 Feb. 2020
fmincon doesn't allow integer constraints, but intlinprog and ga do.
Failing, that, you could just run a loop that tests all combinations of the discrete variables. Since you only have two discrete variables, there shouldn't be an unmanageable number of combinations.

Weitere Antworten (2)

Martijn Kortenhoeven
Martijn Kortenhoeven am 29 Mär. 2021
Very late answer but someone else might benefit from it. You might want to give surrogate modelling a go, see the solver surrogateopt. This allows to find a global minimum of a nonlinear objective function and you can specify which variables you would like to be integers.
I liked Giuseppe's suggestion, but unfortunately I could not get it to work for a very simple example.

Giuseppe Inghilterra
Giuseppe Inghilterra am 25 Feb. 2020
Bearbeitet: Giuseppe Inghilterra am 25 Feb. 2020
Hi,
another solution could be adding non linear equality constraints: for example remainder of division between first variable and 1 is zero and remainder between second variable (angle) and 0.5 is zero by using mod function (e.g mod(variable1,1) = 0 and mod(variable2,0.5) = 0).
In this way variable1 will be an interger and variable2 will be a multiple of 0.5.
Another non linear equality constraint could be by using sine or cosine function, e.g sin(k*pi) = 0. This constraint is satisfied only if k is an integer number.
You should be able to add these non-linear equality constraints to fmincon function. (see: https://www.mathworks.com/help/optim/ug/fmincon.html#busog7r-nonlcon).
  4 Kommentare
Giuseppe Inghilterra
Giuseppe Inghilterra am 25 Feb. 2020
I see now limitations on fmincon:
"fmincon is a gradient-based method that is designed to work on problems where the objective and constraint functions are both continuous and have continuous first derivatives".
Thus my proposed solutions will not work or better the result will be bad because fmincon is a function that works well only for some problems, as demonstrated by Matt.
Thank you Matt, learned something new on fmincon.
Budhyant Venepalli
Budhyant Venepalli am 25 Feb. 2020
Thank you very much for clear explanation. I will implement a different approach.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by