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

98 次查看(过去 30 天)
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

采纳的回答

Matt J
Matt J 2020-2-25
编辑:Matt J 2020-2-25
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.

更多回答(2 个)

Martijn Kortenhoeven
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 2020-2-25
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 个评论
Giuseppe Inghilterra
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 2020-2-25
Thank you very much for clear explanation. I will implement a different approach.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by