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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

1"Example pre-solve evaluated fixed variable" 

2from gpkit import Variable, Model, units 

3 

4# code from t_GPSubs.test_calcconst in tests/t_sub.py 

5x = Variable("x", "hours") 

6t_day = Variable("t_{day}", 12, "hours") 

7t_night = Variable("t_{night}", 

8 lambda c: 1*units.day - c(t_day), "hours") 

9 

10# note that t_night has a function as its value 

11m = Model(x, [x >= t_day, x >= t_night]) 

12sol = m.solve(verbosity=0) 

13assert sol["variables"][t_night] == 12 

14 

15# call substitutions 

16m.substitutions.update({t_day: ("sweep", [8, 12, 16])}) 

17sol = m.solve(verbosity=0) 

18assert (sol["variables"][t_night] == [16, 12, 8]).all()