Suggestion for Improvement: Default bounds not displayed
AnsweredI've just spent over an hour on the following problem:
I had the following two models (which I thought should behave equivalently):
A = np.array([[-1., 1],
[-1., 0],
[ 0., -1],
[ 1., 0],
[ 0., 1]])
b = np.array([0., 1, 1, 1, 1])
obj = np.array([0., 1])
model = grb.Model('matrices')
x = model.addMVar(2, name='x')
model.addConstr(A @ x <= b)
model.setObjective(obj @ x, grb.GRB.MINIMIZE)
model.optimize()
and
model2 = grb.Model('hand-built')
x = model2.addMVar(2, name="x", lb=[-1, 1], ub=[1, 1])
model2.addConstr(x[0] >= x[1], name='x0 is max')
model2.setObjective(x[1], grb.GRB.MINIMIZE)
model2.optimize()
The optimal value of `model` is `0.`, while the optimal output of `model2` is `-1`.
The output of `model.display()` is:
```
Minimize x[1] Subject To R0: -1.0 x[0] + x[1] <= -0 R1: -1.0 x[0] <= 1 R2: -1.0 x[1] <= 1 R3: x[0] <= 1 R4: x[1] <= 1
```
the output of `model2.display()` is:
```
Minimize x[1] Subject To x0 is max: x[0] + -1.0 x[1] >= -0 Bounds -1 <= x[0] <= 1 -1 <= x[1] <= 1
```
I could not conclude from this output, that `model` implicitly constrains `x >= 0`, and therefore the solutions to the two formulations are different.
Are there plans to include the bounds of the variables in the `.display()` method by default?
That would have been very helpful to me.
-
Hi Philipp,
We would not consider changing display() because it is an old undocumented method that is not intended to be used. It will likely be removed in a future release.
The preferred method to inspect the model like this is to write to a LP file. It also exhibits the same behavior. Not printing the lower bound when it is 0 is a common convention among solvers and modelling frameworks. This is motivated by the fact it is not uncommon for the vast majority of variables in a model to have a lower bound of 0 and this would potentially mean hundreds of thousands of extra lines added to the LP file, so it is unlikely that this would be adopted.
- Riley
0 -
Of course, you wouldn't want to print an additional `x_i >= 0` line for every variable that uses the default bounds.
But how about adding just one line, `other_vars >= 0`? This would have been sufficient for me to track down the error I made.
0 -
Adding `other_vars >= 0` would be problematic, especially for other solvers unaware of this convention, but I'll suggest to the dev team that we could add a comment to the LP file such as:
" \ Note, lower bound is 0 unless specified otherwise"
0
Please sign in to leave a comment.
Comments
3 comments