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

Function applied to variable for more flexible domain

回答済み

コメント

8件のコメント

  • 正式なコメント
    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.
  • Simranjit Kaur
    • Gurobi Staff

    You can define x as a semi-continuous variable. A semi-continuous variable has the property that it takes a value of 0 or a value between the specified lower and upper bounds. With the Python API, you can define your x variable as follows:

    x = model.addVar( lb = threshold, vtype = "S", name ="x")
    0
  • Alexander Chen
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you. I'll try it out

    0
  • Alexander Chen
    • Gurobi-versary
    • First Comment
    • First Question

    Have checked that it would work as expected. Would it be possible to mix it with the continuous variable? For example, set x1-x5 to be semi-continuous and the rest to be just continuous

    0
  • Simranjit Kaur
    • Gurobi Staff

    Yes, a model can have both semi-continuous and continuous variables.

    0
  • Alexander Chen
    • Gurobi-versary
    • First Comment
    • First Question

    Sorry I meant mixing semi-continuous and continuous for a variable with length n

    That sounds like just using different ub/lb for each x_i. Could you confirm?

    For example,

    n = 10
    threshold = 0.2
    lb = np.zeros(n)
    lb[0] = threshold
    x = model.addVar(n, lb=lb , ub=1.0, vtype="S", name="x")

    But if want to pin my x_i (ub and lb are the same), can it still by any chance bring it to 0?

    0
  • Simranjit Kaur
    • Gurobi Staff

    One approach to do this would be to set the "vtype" attribute for the variables according to the types you want. In the example below, x[0], x[1], and x[2] will be semi-continuous variables with lower bounds of 1, and x[3] and x[4] will be continuous variables with the default lower bound of zero.

    lb = [1,1,2,0,0]
    x = m.addVars(5, lb=lb, vtype=["S" for _ in range(3)] + ["C" for _ in range(2)], name="x")

    I hope this helps.

    Best regards,
    Simran

    0
  • Alexander Chen
    • Gurobi-versary
    • First Comment
    • First Question

    That's what I'm looking for. Thank you!

    0

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