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

sage.numerical.linear_functions.LinearConstraint is not a hashable type #15583

Closed
sagetrac-cbowen mannequin opened this issue Dec 24, 2013 · 6 comments
Closed

sage.numerical.linear_functions.LinearConstraint is not a hashable type #15583

sagetrac-cbowen mannequin opened this issue Dec 24, 2013 · 6 comments

Comments

@sagetrac-cbowen
Copy link
Mannequin

sagetrac-cbowen mannequin commented Dec 24, 2013

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

CC: @nathanncohen @vbraun @dimpase

Component: linear programming

Keywords: linear constraint, mixed integer linear program

Reviewer: Dima Pasechnik

Issue created by migration from https://trac.sagemath.org/ticket/15583

@sagetrac-cbowen sagetrac-cbowen mannequin added this to the sage-6.1 milestone Dec 24, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 3, 2016

comment:5

Added example to the description.

@mkoeppe

This comment has been minimized.

@dimpase dimpase removed this from the sage-6.4 milestone Apr 5, 2016
@sagetrac-brown
Copy link
Mannequin

sagetrac-brown mannequin commented Apr 6, 2017

comment:7

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://github.com/sagemath/sagetrac-mirror/commits/682ba3e7b8aaf84ba181ac16b8630aefb695c940 to thank for the update.

@dimpase
Copy link
Member

dimpase commented Apr 6, 2017

Reviewer: Dima Pasechnik

@dimpase
Copy link
Member

dimpase commented Apr 6, 2017

comment:9

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.

@embray
Copy link
Contributor

embray commented Jul 13, 2017

comment:10

Closing tickets in the sage-duplicate/invalid/wontfix module with positive_review (i.e. someone has confirmed they should be closed).

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

No branches or pull requests

4 participants