Is it possible to dynamically alter the constraints in MILP?
18:37 08 Jul 2026

I'm working in Sage Math, and trying to code up some polytopes using Mixed Integer Linear Programming (MILP).

The issue I've run into, is that whenever I change the settings I'm using, I also have to go into the functions I've written and manually rework the constraints to account for the different numbers of terms.

I know that the "linear_function" argument of the ".add_constraint()" method does accept linear functions, but I don't believe there's a way to dynamically alter those either.

Am I wrong, and is it possible to create a function that can dynamically generate my constraints?

If so, how?

If not, are there any other alternatives I might use?

If anything is unclear, please ask! Otherwise, thank you for reading! (and hopefully responding)

python arguments sage