Skip to main content

How can I restrict a variable that can only take value in a list?

Ongoing

Comments

3 comments

  • Marika Karbstein
    Gurobi Staff Gurobi Staff

    It is not possible to give an arbitrary list that indicates the allowed values of a variable.
    If your variable is only allowed to take a value 1,2,3, or 4, you could define an integer variable with lower bound 1 and upper bound 4.

    0
  • Jonasz Staszek
    Community Moderator Community Moderator
    Gurobi-versary
    Thought Leader
    First Question

    Dear Marika, dear Morris,

    as a workaround, one can try to use indicator variables and constraints to model the desired behaviour (have a look here for an example). This will most likely not scale well though.

    Best regards
    Jonasz

    0
  • Morris Lin
    Gurobi-versary
    First Comment
    First Question

    Thank for Jonasz's help.

    I have a idea to achieve it. Using indicator variables and limiting x like (0.9999<=x<=1.0001)&(1.9999<=x<=2.0001)...

    There's a similar problem that bothers me. I post it below.

    x only can equal 1 or 2 or 3 or 4

    y only can equal 2 or 3 or 4 or 5,y is related to x. 

    for example, x==1, y==2 or x==2, y==3 or ...

    And I usually code in matlab, it is hard to express the above by martix.

     

     

    0

Please sign in to leave a comment.