• Gurobi Staff

Hi Wenjia,

I think the following post may help.

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

- Riley

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

• 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

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] ** 2v == 4 * omega[I, t, k] * u

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

Best,

Wenjia

• 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

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

Best,

Wenjia