Skip to main content

Non-Zero test for summation of variables

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three 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 why not try our AI Gurobot?.
  • Greg Glockner
    • Gurobi Staff

    What are the bounds on these variables? Are they continuous, integer or binary?

    0
  • Xiangfeng Zhu
    • Gurobi-versary
    • First Question
    • Conversationalist

     

    Thanks for your prompt reply! They are GRB.INTEGER and I set the lower bound to zero.

     

     

    0
  • Tobias Achterberg
    • Gurobi Staff

    In order to count the number of non-zeros, you would typically introduce binary variables that indicate whether a given variable is 0 or not. So, if you have integer variables x1,...,xn, then you would introduce binary variables z1,...,zn and add an indicator constraint

    zi = 0 -> xi = 0

    for each i = 1,...,n that says that if the binary variable is zero, then the integer variable must be zero as well. Then, if you want to restrict the number of non-zero xi variables to, say, k, you would add the constraint

    z1 + ... + zn <= k.


    Regards,

    Tobias

    0
  • Xiangfeng Zhu
    • Gurobi-versary
    • First Question
    • Conversationalist

    It worked! Thanks so much! 

    0

Post is closed for comments.