Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"Example pre-solve evaluated fixed variable" 

2from gpkit import Variable, Model 

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}", lambda c: 24 - c[t_day], "hours") 

8 

9# note that t_night has a function as its value 

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

11sol = m.solve(verbosity=0) 

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

13 

14# call substitutions 

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

16sol = m.solve(verbosity=0) 

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