-
-
Notifications
You must be signed in to change notification settings - Fork 406
TypeError when LpAffineExpressions are Specified Using Decimals #815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@pchtsp this looks like another one I broke, will take a look. |
After some investigation, the reason this happens is that Decimal allows operations with ints but not floats.
@mark92223 a quick fix to try, instead of declaring your constraints as you have can you either do: second_expression = LpAffineExpression(constant=Decimal("0"))
# y = 8.1x - 6
second_expression += x * m2 - 6 - y or # y = 8.1x - 6
second_expression = x * m2 - 6 - y I expect this will not fully solve the issue, as in my tests I get an exception in |
Taking a look GLPK does not use |
The workaround does seem to resolve the crash, thanks (And obviously, it still returns the correct result)! I personally still think that this ought to work as is, but appreciate the help regardless. |
I'm closing as the issue was with Decimals. |
@pchtsp So, are you saying that decimals are not supported in this context? This is not clear in the docs and previously worked successfully. |
I had no idea the Decimal library existed. The error seems pretty explicit: floats and Decimals do not seem to get along. I'm unsure why this worked before.
Option 2 seems easy but then, why would you Decimal if the values are going to be converted to floats under the hood? If you have any suggestion or better want to make a PR, go ahead! |
For this issue, Decimal really will have only worked with a few of the backends. GLPK only works as it does not use One option could be to have a global option which specifies what type the coefficients will be (e.g., int or float/Decimal). |
When a LpAffineExpression is extended using Decimals, as of pulp 2.9.0 (and before), it would work without raising any exception and returning accurate results. Beginning in 3.0.0, it now raises a TypeError in the addInPlace method:
self.constant += other.constant * sign
A reproducing pytest file which can be run, passing in 2.9.0, and failing in 3.0.2(or 3.0.0): https://gist.github.com/mark92223/e590c21df931eda1927ae4230fec118d .
Is using Decimals in this context unsupported in Pulp?
Thank you!
Details for the issue
What did you do?
What did you expect to see?
The test to pass
What did you see instead?
Useful extra information
The info below often helps, please fill it out if you're able to. :)
What operating system are you using?
I'm using python version:
I installed PuLP via:
Did you also
The text was updated successfully, but these errors were encountered: