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 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"]
9assert abs(sol["cost"] - 4) <= 1e-4
10assert y in sol["constants"]
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"]