Coverage for docs\source\examples\evaluated_fixed_variables.py: 0%
10 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 16:57 -0500
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 16:57 -0500
1"Example pre-solve evaluated fixed variable"
2from gpkit import Variable, Model, units
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")
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
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()