Coverage for docs/source/examples/simple_sp.py: 100%
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
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
1"""Adapted from t_SP in tests/t_geometric_program.py"""
2from gpkit import Model, Variable, SignomialsEnabled
4# Decision variables
5x = Variable('x')
6y = Variable('y')
8# must enable signomials for subtraction
9with SignomialsEnabled():
10 constraints = [x >= 1-y, y <= 0.1]
12# create and solve the SP
13m = Model(x, constraints)
14print(m.localsolve(verbosity=0).summary())
15assert abs(m.solution(x) - 0.9) < 1e-6
17# full interim solutions are available
18print("x values of each GP solve (note convergence)")
19print(", ".join("%.5f" % sol["freevariables"][x] for sol in m.program.results))
21# use x0 to give the solution, reducing number of GPs needed
22m.localsolve(verbosity=0, x0={x: 0.9, y:0.1})
23assert len(m.program.results) == 2