Clear Filters
Clear Filters

How to specify the variables to be integers in fmincon function.

11 views (last 30 days)
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?

Answers (2)

John D'Errico
John D'Errico on 27 Oct 2016
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 Comments
Walter Roberson
Walter Roberson on 27 Oct 2016
ga() allows integer constraints, but when you have an integer constraint it does not allow nonlinear constraints.
Abdolkarim Mohammadi
Abdolkarim Mohammadi on 14 Aug 2019
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.

Sign in to comment.


Math Works
Math Works on 28 Jul 2022
Is there an equivalent integer one that doesn't define f as vectors?
  13 Comments
Walter Roberson
Walter Roberson on 29 Jul 2022
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
Math Works on 29 Jul 2022
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!