メインコンテンツへスキップ

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

進行中

コメント

4件のコメント

  • 正式なコメント
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Marika Karbstein
    • 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
    • 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

投稿コメントは受け付けていません。