coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
513 stars 88 forks source link

Constraint creation is not symmetric for combination variable and tensor #371

Open chopin57otu opened 4 months ago

chopin57otu commented 4 months ago

Describe the bug MIP allows to create constraint like mip.LinExprTensor <= mip.Var, but not the opposite way.

To Reproduce

>>> import mip
>>> m = mip.Model()
>>> y = m.add_var_tensor((10,2), 'y')
>>> x = m.add_var('x')
>>> m += y >= x
>>> m += x >= y
Traceback (most recent call last):
  File "python\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "lib\site-packages\mip\entities.py", line 632, in __ge__
    raise TypeError("type {} not supported".format(type(other)))
TypeError: type <class 'mip.ndarray.LinExprTensor'> not supported

Expected behavior Both constraints mip.LinExprTensor <= mip.Var and mip.Var <= mip.LinExprTensor are supported and behave identically.

Desktop (please complete the following information):

Additional context N/A