Why Does a Bilinear Term Get Infinite Upper Bound After Presolve?
回答済みI tested the code from the this forum and have question about upper bound of presolved model (the code block and results are shown below). Why is the upper bound of the bilinear term (r =x*y) becomes infinity after presolve, while the upper bound for the trilinear term (u = x*y*t) is not infinity? What is the threshold for the presolve to consider it as infinity?
model = gp.Model()
model.Params.OutputFlag = 0
x = model.addVar(lb=-2, ub=1e4, name="x")
y = model.addVar(lb=1, ub=1e4, name="y")
t = model.addVar(lb=1, ub=1e2, name="t")
u = model.addVar(name="u") # Default: [0, inf]
r = model.addVar(name="r") # Default: [0, inf]
model.addConstr(u == x * y * t)
model.addConstr(r == x * y)
# Prevent presolve from eliminating the variables.
model.addConstr(u + r >= 2)
model.setObjective(u * y + r*t + x, GRB.MINIMIZE)
model.update()
print("ORIGINAL MODEL:")
print(f" u: [{u.LB}, {u.UB}]")
print(f" r: [{r.LB}, {r.UB}]")
presolved = model.presolve()
print(f"\nPRESOLVED MODEL:")
for var in presolved.getVars():
ub = f"{var.UB:.1f}" if var.UB < 1e20 else "inf"
print(f" {var.VarName}: [{var.LB:.1f}, {ub}]")
Result after running:
ORIGINAL MODEL:
u: [0.0, inf]
r: [0.0, inf]
PRESOLVED MODEL:
x: [0.0, 10000.0]
y: [1.0, 10000.0]
t: [1.0, 100.0]
u: [0.0, 10000000000.0]
r: [0.0, inf]
-
Hi Perapat,
Did you get an answer to this question? I recall seeing you ask it (or a very similar question) on another one of your posts that I think may have now been deleted?
- Riley
0 -
Hello Riley,
I haven't received the answer to the question yet. I only post it once in this forum.
- Perapat
0 -
Hi Perapat,
This constraint:
model.addConstr(r == x * y)will be handled by our quadratic constraint code. An upper bound for r will be added provided it is not too large. If you set the upper bounds for x and y to be 100, for example, you will see it is given an upper bound. When the upper bound is so large that it might cause numerical issues for our solver then we will not add it.
This constraint:
model.addConstr(u == x * y * t)will be handled by our nonlinear constraint code. If you had instead used
u == r*tthen u will also have not been given a bound in your example. Currently the nonlinear code adds a bound. This may change in the future - this nonlinear API is still relatively new.In general it is a very good idea to keep bounds small on variables which are inputs to nonlinear constraints (which includes quadratic constraints). This may require scaling the variable by choosing a different unit for whatever quantity it represents.
- Riley
0 -
Apologies Perapat for the confusion around asking an earlier question. It looks like you and Huan Nguyen are working on the same assignment and asking very similar questions.
https://support.gurobi.com/hc/en-us/community/posts/46065096664337
Maybe it is useful for you to collaborate.- Riley
0
サインインしてコメントを残してください。
コメント
4件のコメント