Opened 6 years ago

Closed 2 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 mkoeppe)

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 6 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:2 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:3 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:4 Changed 4 years ago by mkoeppe

  • Type changed from PLEASE CHANGE to enhancement

comment:5 Changed 4 years ago by mkoeppe

  • Description modified (diff)

Added example to the description.

comment:6 Changed 4 years ago by dimpase

  • Milestone changed from sage-6.4 to sage-wishlist

comment:7 Changed 3 years ago by brown

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 3 years ago by chapoton

  • Milestone changed from sage-wishlist to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_review

comment:9 Changed 3 years ago by dimpase

  • 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 2 years ago by embray

  • 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).

Note: See TracTickets for help on using tickets.