pulp
pulp copied to clipboard
Incompatible LpConstraint with LHS as numpy value
Details for the issue
What did you do?
What I think is a bug, consists in writing a LpConstraint from LpVariables the following way: LHS == RHS
Case 1: using Python int/float alone on RHS
>> LpVariable(name='X1') == 1
Case 2: using Numpy int/float alone on RHS
>> LpVariable(name='X1') == numpy.float_(1)
Case 3: using Python int/float alone on LHS
>> 1 == LpVariable(name='X1')
Case 4 (Does not work): using Numpy int/float alone on LHS
>> numpy.float_(1) == LpVariable(name='X1')
Note: the issue is the same with any operator (==, >=, <=) and any constant (as numpy float or integer)
Note: original use is to automatically perform lots of optimization problems, using values extracted from numpy matrices. Some equations of the problem are so that, for some values, we end up with a numpy float on the LHS of equations. Above is the most simplified version of the problem.
What did you expect to see?
In cases 1, 2 and 3, the result is a LpConstraint object for the equation 1*X1 + -1 = 0
So it is expected for case 4 to also return a LpConstraint object for the equation 1*X1 + -1 = 0.
What did you see instead?
Instead, in case 4, the result is True of type numpy.bool_, which makes the constraint vanish from an actual problem.
Useful extra information
The info below often helps, please fill it out if you're able to. :)
What operating system are you using?
- [ ] Windows: ( version: ___ )
- [X] Linux: ( distro: Ubuntu 20.04 )
- [ ] Mac OS: ( version: ___ )
- [ ] Other: ___
I'm using python version:
- [ ] 2.7
- [ ] 3.4
- [ ] 3.5
- [X] 3.6
- [X] Other: 3.8.10
I installed PuLP via:
- [X] pypi (python -m pip install pulp)
- [ ] github (python -m pip install -U git+https://github.com/coin-or/pulp)
- [ ] Other: ___ (conda?)
Did you also
- [X] Tried out the latest github version: https://github.com/coin-or/pulp
- [X] Searched for an existing similar issue: https://github.com/coin-or/pulp/issues?utf8=%E2%9C%93&q=is%3Aissue%20