Skip to content

MixedIntegerLinearProgram.new_variable could optionally take a "static" list of component indices #20773

@mkoeppe

Description

@mkoeppe

Currently, new_variable allocates backend indices to MIP variable component indices very dynamically.

sage: p = MixedIntegerLinearProgram()
sage: x = p.new_variable()
sage: x[7]
x_0
sage: x[2]
x_1

Sometimes it could be nice to have a predictable order in the backend; for example, when .polyhedron() is to be called. And sometimes it could be nice to declare ahead of time which component indices are valid, making accesses to other indices an error (rather than creating a new backend variable); this could help debug MIP models.

This could look like this:

sage: p = MixedIntegerLinearProgram()
sage: x = p.new_variable(indices=range(7))
sage: p.number_of_variables()
7
sage: x[3]
x_3
sage: x[11]
IndexError: 11 does not index a component of MIPVariable of dimension 1

(This is optional; if no indices argument is passed, it keeps the fully dynamic current behavior.)

CC: @dimpase @videlec @jdemeyer @nbruin @fchapoton @sagetrac-tmonteil @dcoudert @tscrim

Component: numerical

Author: Matthias Koeppe

Branch/Commit: 23689dd

Reviewer: Travis Scrimshaw

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions