Path: blob/main/Lessons/Lesson 05 - Local Optimization/extras/Lesson_05_Pyomo_Mutable_Parameters.ipynb
871 views
Kernel: Python 3 (system-wide)
Pyomo Mutable Parameters
Sometimes when you are coding a model, you want to be able to run it multiple times with some slight changes. For example, you might want to vary a constraint. Lesson 4 homework has a problem that requires this. There are two ways to do that:
Wrap the model in a function, using the bit you want to change as a parameter to the function, and re-instantiate the entire model for each value you want to test.
Use a mutable parameter.
Mutable just means that it's a paramter value that can change, instead of being a fixed constant. Let's see a quick example of each. We'll use our old standby - the Wyndor model. We'll vary the constant in the constraint, so that instead of just using 18, we'll try the model with 18, 20, and 22.
Wrapping in a function
In [2]:
Out[2]:
Using Constraint 18
Profit = $36,000.00
Batches of Doors = 2.0
Batches of Windows = 6.0
-------------------------------------------------
Using Constraint 20
Profit = $38,000.00
Batches of Doors = 2.66666666666667
Batches of Windows = 6.0
-------------------------------------------------
Using Constraint 22
Profit = $40,000.00
Batches of Doors = 3.33333333333333
Batches of Windows = 6.0
-------------------------------------------------
Mutable Parameter
In [4]:
Out[4]:
Using Constraint 18
Profit = $36,000.00
Batches of Doors = 2.0
Batches of Windows = 6.0
-------------------------------------------------
Using Constraint 20
Profit = $38,000.00
Batches of Doors = 2.66666666666667
Batches of Windows = 6.0
-------------------------------------------------
Using Constraint 22
Profit = $40,000.00
Batches of Doors = 3.33333333333333
Batches of Windows = 6.0
-------------------------------------------------