Skip to content

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

@sagetrac-cbowen

Description

@sagetrac-cbowen

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions