Although the keyword “binary” is mentioned and I put a boundary constraint that the binary variable should not violate 0 and 1, the result contains some errors especially the very small numbers approaching 0 from the negative direction, which causes the problem to violate the DCP rules of CVX causing the problem stop unexpectedly …
Is this a bug in CVX not to result in accurate 0 or 1? or it depends on some accuracy?
Note: I use Mosek with cvx
Solvers allow integrality and feasibility tolerances. Therefore, even at declared optimality, binary variables may differ slightly from 0 or 1. You can post-process (adjust) these to be exactly 0 or 1 if that is what you need for use of the results.
cvx_begin
variable b binary
...
cvx_end
adjusted_b = round(b);
If you are using a solver which can handle binary variables, you should just declare variables binary without also adding bound constraints.
1 Like