Coverage for docs\source\examples\freeing_fixed_variables.py: 0%

11 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-03 16:57 -0500

1"Example of freeing fixed variables" 

2from gpkit import Variable, Model 

3x = Variable("x") 

4y = Variable("y", 3) # fix value to 3 

5m = Model(x, [x >= 1 + y, y >= 1]) 

6# verbosity is 0 for testing's sake, no need to do that in your code! 

7sol = m.solve(verbosity=0) # optimal cost is 4; y appears in sol["constants"] 

8 

9assert abs(sol["cost"] - 4) <= 1e-4 

10assert y in sol["constants"] 

11 

12del m.substitutions["y"] 

13sol = m.solve(verbosity=0) # optimal cost is 2; y appears in Free Variables 

14assert abs(sol["cost"] - 2) <= 1e-4 

15assert y in sol["freevariables"]