Opened 8 years ago
Closed 5 years ago
#15583 closed enhancement (wontfix)
sage.numerical.linear_functions.LinearConstraint is not a hashable type
Reported by: | cbowen | Owned by: | |
---|---|---|---|
Priority: | trivial | Milestone: | sage-duplicate/invalid/wontfix |
Component: | linear programming | Keywords: | linear constraint, mixed integer linear program |
Cc: | ncohen, vbraun, dimpase | Merged in: | |
Authors: | Reviewers: | Dima Pasechnik | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
I'd like to have sage.numerical.linear_functions.LinearConstraint
to be a hashable type.
Currently it is not:
sage: p = MixedIntegerLinearProgram() sage: b = p.new_variable() sage: b[0] <= b[1] <= 2 x_0 <= x_1 <= 2 sage: hash(b[0] <= b[1] <= 2) ... TypeError: unhashable type: 'sage.numerical.linear_functions.LinearConstraint'
This is for the following reasons:
1) When adding constraints to an instance of a MixedIntegerLinearProgram
, it is not necessary to add the same or equivalent constraint multiple times. A hash could be used to determine distinct linear constraints that are added into a MILP instance.
2) By having hashable linear constraints, one could allow for linear constraints to be added into sets (http://docs.python.org/2/library/sets.html) or used as keys in dictionaries.
Thanks, Clinton
Change History (10)
comment:1 Changed 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:2 Changed 8 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:3 Changed 8 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:4 Changed 6 years ago by
- Type changed from PLEASE CHANGE to enhancement
comment:5 Changed 6 years ago by
- Description modified (diff)
comment:6 Changed 6 years ago by
- Milestone changed from sage-6.4 to sage-wishlist
comment:7 Changed 5 years ago by
sage.numerical.linear_functions.LinearConstraint
is now a hashable type.
sage: p = MixedIntegerLinearProgram() sage: b = p.new_variable() sage: c = (b[0] <= b[1] <= 2) sage: c.__hash__() 8748240900236 sage: c.__hash__ <method-wrapper '__hash__' of sage.numerical.linear_functions.LinearConstraint object at 0x7f4dbca908c0>
I think we have https://git.sagemath.org/sage.git/commit/?h=682ba3e7b8aaf84ba181ac16b8630aefb695c940 to thank for the update.
comment:8 Changed 5 years ago by
- Milestone changed from sage-wishlist to sage-duplicate/invalid/wontfix
- Status changed from new to needs_review
comment:9 Changed 5 years ago by
- Reviewers set to Dima Pasechnik
- Status changed from needs_review to positive_review
IMHO, typically solvers are able to deal with multiple constraints, etc.
Also, constraints are really held in the backend, and in fact they can get modified once they are processed.
comment:10 Changed 5 years ago by
- Resolution set to wontfix
- Status changed from positive_review to closed
Closing tickets in the sage-duplicate/invalid/wontfix module with positive_review (i.e. someone has confirmed they should be closed).
Added example to the description.