Bug Report: MVar with multiple leading 1's in the shape does not accept lb, ub or obj
Currently, it is not possible to add an MVar whose shape has multiple leading 1s with a lower bound of the same shape:
import gurobipy as gp
import numpy as np
shape = (1, 1, 2)
m = gp.Model()
mv1 = m.addMVar(shape, lb=np.ones(shape))
The last line fails with
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "src\gurobipy\model.pxi", line 2903, in gurobipy.Model.addMVar
File "src\gurobipy\model.pxi", line 2793, in gurobipy.Model.addVars
File "src\gurobipy\model.pxi", line 280, in gurobipy.__listify.listify
File "src\gurobipy\model.pxi", line 266, in gurobipy.__listify.flatten
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
It is possible to flatten the array, however, I think this is pretty unintuitive.
mv1 = m.addMVar(shape, lb=np.ones(shape).flatten())
The same goes for the upper bound and the objective coefficients.
I am using Python 3.7 and Gurobi 9.1.1 on Windows 10
0
-
Hi Florian,
Thank you for bringing this up. We added this issue to our future roadmap and it will be hopefully fixed in a future version of Gurobi.
For now, using \(\texttt{flatten()}\) is a valid workaround.
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
1 comment