Skip to content
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

LpConstraint name is not set on initialisation #805

Closed
5 of 15 tasks
christiansegercrantz opened this issue Feb 25, 2025 · 1 comment · Fixed by #806
Closed
5 of 15 tasks

LpConstraint name is not set on initialisation #805

christiansegercrantz opened this issue Feb 25, 2025 · 1 comment · Fixed by #806

Comments

@christiansegercrantz
Copy link
Contributor

Details for the issue

Somewhere in #750 it seems the ability to set the name for LpConstraints has been lost. It's also obvious from the code that the name for the constraint is not set, it's at maximum set for the LpAffineExpression. @MBradbury I assume this wasn't intentional, or? If it wasn't, we should probably add back the possibility to give the constraint a name. I'm happy to do it as long as I get some guidance on how to do it. I'd assume, we'd always use the name given as the LpConstraint name and only, as currently, use the same name for the expression if it wasn't a LpAffineExpression to start with.

What did you do?

from pulp import (
    LpAffineExpression,
    LpConstraint,
)

test = LpAffineExpression(1)
print(f"{test.name=}")

test2 = LpConstraint(test, name="Test2")
print(f"{test2.name=}")

print(f"{test2.expr.name=}")

What did you expect to see?

test.name=None
test2.name="Test2"
test2.expr.name=None

What did you see instead?

test.name=None
test2.name=None
test2.expr.name=None

Additionally

from pulp import (
    LpAffineExpression,
    LpConstraint,
)

test = LpAffineExpression(1, name="Test1")
print(f"{test.name=}")

test2 = LpConstraint(test, name="Test2")
print(f"{test2.name=}")

print(f"{test2.expr.name=}")

produces

from pulp import (
    LpAffineExpression,
    LpConstraint,
)

test = LpAffineExpression(1, name="Test1")
print(f"{test.name=}")

test2 = LpConstraint(test, name="Test2")
print(f"{test2.name=}")

print(f"{test2.expr.name=}")

Useful extra information

What operating system are you using?

  • Windows: ( version: ___ )
  • Linux: ( distro: ___ )
  • Mac OS: macOS Sequoia 15.3 (24D60)
  • Other: ___

I'm using python version:

I installed PuLP via:

  • pypi (python -m pip install pulp)
  • github (python -m pip install -U git+https://github.com/coin-or/pulp)
  • Other: rye add pulp --git https://github.com/coin-or/pulp

Did you also

@MBradbury
Copy link
Contributor

MBradbury commented Feb 25, 2025

I have a fix for this on another branch (https://github.com/MBradbury/pulp/tree/typehints), have extracted it out and made #806.

For your test I now get:

test.name=None
test2.name='Test2'
test2.expr.name=None

test.name='Test1'
test2.name='Test2'
test2.expr.name='Test1'

MBradbury added a commit to MBradbury/pulp that referenced this issue Feb 26, 2025
pchtsp pushed a commit that referenced this issue Feb 26, 2025
* LpConstraint should have its own name

* Add name to LpConstraint

* Add test for #805
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

Successfully merging a pull request may close this issue.

2 participants