Skip to main content

cast multiplication of floats to integer

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • 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

Post is closed for comments.