How to specify the variables to be integers in fmincon function.
3 次查看(过去 30 天)
显示 更早的评论
I need to solve a quadratically constrained program by fmincon with all variables restricted in integers. Is it possible to specify variable types in fmincon? If not, is there another way to solve this problem?
0 个评论
回答(2 个)
John D'Errico
2016-10-27
You cannot do so. Period. fmincon does not allow integer constraints. To solve that class of problem, you need a integer programming tool, in this case, a nonlinear one. But NOT fmincon.
I believe the genetic optimization tools can allow integer constraints.
2 个评论
Walter Roberson
2016-10-27
ga() allows integer constraints, but when you have an integer constraint it does not allow nonlinear constraints.
Abdolkarim Mohammadi
2019-8-14
When you have integer variables in ga(), you can have linear and/or nonlinear inequality constraints. Integer ga() only prohibits linear and/or nonlinear equality constraints.
Math Works
2022-7-28
Is there an equivalent integer one that doesn't define f as vectors?
13 个评论
Walter Roberson
2022-7-29
Yes, you generate a set of integers, and then you treat those as locally constant and optimize over the other values. You get a best result for varying the other variables relative to that particular list of integers, and then you move on to the next list of integers, and repeat, keeping track of the best result as you go.
Math Works
2022-7-29
Yes, that's exactly what I did.
Basically, every for-chain iteration step treats all the integer variables as constants, then do the local continuous constrained optimization problem. With some global tracker variables and helper functions, this can be implemented with some effort.
I still don't understand why MATLAB can't abstract this process though. Just ask for the boundries for the integer variables. Formulating the problem becomes harder when you need to think about the lower level implementations. At that point, I'm better off doing it in C++ directly.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!