Skip to main content

cast multiplication of floats to integer

Answered

Comments

1 comment

  • Jaromił Najman
    • Gurobi Staff

    Hi Saeid,

    Do you mean to introduce a rounding constraint, e.g., something like \(i = \lfloor x\cdot y \rfloor\), where \(i\) is integer and \(x,y\) are continuous variables?

    This can be achieved by the inequality constraints

    \[\begin{align*}
    i \leq x\cdot y \leq i +1
    \end{align*}\]

    These inequalities would force \(i\) to the rounded down value of \(x\cdot y\). Note that there is a special case when \(x\cdot y\) are indeed integer, e.g., \(=2\). Then the value of \(i\) is not fixed and could be \(1\) or \(2\). To avoid such cases, one could introduce a small constant tolerance \(\epsilon > 0\) and apply it to one of the inequalities.

    Best regards, 
    Jaromił

    0

Please sign in to leave a comment.