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?

4 ビュー (過去 30 日間)
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 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 21 日
編集済み: Walter Roberson 2019 年 3 月 21 日
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'
Rikke
Rikke 2019 年 3 月 21 日
Thanks for your respond, ufortunatly I have many more x values.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2019 年 3 月 21 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by