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

How to replace coefficients and constant terms in the model

回答済み

コメント

7件のコメント

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

    Hi Wenjia,

    I think the following post may help.

    https://support.gurobi.com/hc/en-us/community/posts/26483086080273-Quadratic-Constraint-Modification

    Can you have a read and see if any questions remain?

    - Riley

    0
  • Wenjia Shen
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi Riley,

    Thank you so much for your response. I now understand how to change the coefficients. However, if I want to change the value of “omega” in my SOC1, I can only do so by removing the entire constraint and re-adding it using addConstr(). Is that correct?

    Best,

    Wenjia

    0
  • Riley Clement
    • Gurobi Staff

    Hi Wenjia,

    Not quite.  Essentially you want to reformulate (with auxiliary variables and constraints) so that the omega coefficient appears in a linear constraint as that is the only constraint type that permits coefficients to be changed with the Model.chgCoeff method.

    - Riley

    0
  • Wenjia Shen
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi Riley,

    I think you mean adding a new variable  u (with its lb=1, ub=1) and a new variable v, and rewriting SOC1 as:

    v + quicksum(aa[h, i] ** 2 for h in range(H)) + bb[i] ** 2 <= cc[i] ** 2
    v == 4 * omega[I, t, k] * u

    then using Model.chgCoeff() to change the coefficient of u?

    Best,

    Wenjia

    0
  • Riley Clement
    • Gurobi Staff

    Actually, if these omega values are not coefficients and just constants then you can adjust with the RHS property:

    c = model.addConstr(v ==  4* omega[i, t, k])
    model.addQConstr(v + quicksum(aa[h, i] ** 2 for h in range(H)) + bb[i] ** 2 <= cc[i] ** 2, "SOC1")

    then you can modify c.RHS to 4*(new value of omega)

    and also

    c2 = model.addConstr(v2 == omega[i, t, k] - omega[i, t, k] * r[h])
    model.addConstr(aa[h, i] == 2 * np.sqrt(v2 * w[i, h]) * x[h], "Constr_aa")

    then change the value of c2.RHS to a new value

    0
  • Wenjia Shen
    • Gurobi-versary
    • Conversationalist
    • First Question

    Thank you so much. I really appreciate the time and effort you put into assisting me. Wish you have a great day!

    Best,

    Wenjia

    0

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