Is it possible to constrain the unknown x in an optimization problem to be rounded up to 1 when it originally is a value between 0 and 1?

1 view (last 30 days)
I use the fmincon function and have set the lower bound to be 0 and upper bound to be 1. I want the values that are optimized to be between 0 and 1 to be rounded up to 1. In other words i want the optimization value to be either 0 or 1.
I tried to set a constraint to the function stating that if the unknown values that is to be optimized is set to be between 0 and 1 the unknown value will be rounded up to 1:
for i = 1:length(x) %x is the values that are to be optimized
if x(i)>0
ceq(i)=x(i)-1;
end
end
I also got this message:
Converged to an infeasible point.
fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance but constraints are not
satisfied to within the default value of the constraint tolerance.
The alogrithm option for the optimization is 'active-set'.
  2 Comments
Walter Roberson
Walter Roberson on 21 Mar 2019
Edited: Walter Roberson on 21 Mar 2019
That would not round: that would reject anything other than 0 or 1.
fmincon() is not designed for integer constraints.
If you have no more than about 25-ish x values, then simply generate all possible 0/1 and test them all and take the one that has the lowest output.
dec2bin(0:2^(length(x))-1) - '0'

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 21 Mar 2019
You are trying to use a tool not designed to solve that class of problem. You cannot round the results AFTER fmincon returns a result, because it may not be optimal. In fact, the rounded solution might not even be feasible, satisfying some of the constraints.
Nor can you round the unknowns inside your objective function. That would effectively create a discontinuous objective, something that fmincon is NOT designed to work with.
Problems with one or more variables that must be an integer are called integer programming problems. If only some of them are integer constraints, it still effectively counts as such, though then it would probably be called mixed integer programming. If the variable is constrained to beeither 0 or 1, that is usually called a binary integer programming problem. This is not something that fmincon does. (Though I do recall a tool called fminconset, that was on the file exchange. I'm not sure if it is still there, or if it still works. You might look.)
In MATLAB, look in the Global Optimization toolbox, where you can find GA. It is designed to solve that class of problem.
Finally, if you really have only ONE variable that is binary, then just solve the problem twice. First, with the variable replaced by 0. Then with it replaced by 1. Take the better solution from the two runs, and you are done. As Walter points out, this approach even works if you have a few binary variables, as long as you do not have too many of them.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!