-
-
Notifications
You must be signed in to change notification settings - Fork 656
Description
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