Skip to content

Division broken for LpVariable #826

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

Open
4 of 15 tasks
robertHowlett opened this issue Apr 4, 2025 · 2 comments
Open
4 of 15 tasks

Division broken for LpVariable #826

robertHowlett opened this issue Apr 4, 2025 · 2 comments

Comments

@robertHowlett
Copy link

robertHowlett commented Apr 4, 2025

Details for the issue

What did you do?

import pulp

x = pulp.LpVariable("foo")
y = x * (1 / 3.0)  # works
y = x / 3.0  # fails

What did you expect to see?

The code should run successfully

What did you see instead?

The code failed with

Traceback (most recent call last):
  File "<snip>", line 5, in <module>
    y = x / 3.0  # fails
        ~~^~~~~
TypeError: unsupported operand type(s) for /: 'LpVariable' and 'float'

I think we're just missing

    def __truediv__(self, other):
        return self.__div__(other)

from LpVariable?

Useful extra information

What operating system are you using?

  • Windows: Windows 11 Pro 24H2
  • Linux: ( distro: ___ )
  • Mac OS: ( version: ___ )
  • Other: ___

I'm using python version:

  • 3.7
  • 3.8
  • 3.9
  • 3.10
  • 3.11
  • Other: Python 3.13.2

I installed PuLP via:

Did you also

@pchtsp
Copy link
Collaborator

pchtsp commented Apr 8, 2025

@MBradbury what do you think? I remember you said that the divisions were broken since pulp version 3. But I'm not sure if you meant this.

@MBradbury
Copy link
Contributor

I can't remember what the broken division issue was. In this case it is relatively straightforward that LpVariable only implements __div__ instead of __truediv__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants