-
Notifications
You must be signed in to change notification settings - Fork 40
/
boundschecking.py
59 lines (50 loc) · 1.38 KB
/
boundschecking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"verifies that bounds are caught through monomials"
from gpkit import Model, parse_variables
class BoundsChecking(Model):
"""Implements a crazy set of unbounded variables.
Variables
---------
Ap [-] d
D [-] e
F [-] s
mi [-] c
mf [-] r
T [-] i
nu [-] p
Fs 0.9 [-] t
mb 0.4 [-] i
rf 0.01 [-] o
V 300 [-] n
Upper Unbounded
---------------
F
Lower Unbounded
---------------
D
"""
@parse_variables(__doc__, globals())
def setup(self):
self.cost = F
return [
F >= D + T,
D == rf*V**2*Ap,
Ap == nu,
T == mf*V,
mf >= mi + mb,
mf == rf*V,
Fs <= mi
]
m = BoundsChecking()
print(m.str_without(["lineage"]))
try:
m.solve()
except ValueError:
pass
gp = m.gp(allow_missingbounds=True)
str = ", but would gain it from any of these sets of bounds: "
assert gp.missingbounds[(m.D.key, 'lower')] == str + "[(%s, 'lower')]" % m.Ap
assert gp.missingbounds[(m.nu.key, 'lower')] == str + "[(%s, 'lower')]" % m.Ap
# ordering is arbitrary:
assert gp.missingbounds[(m.Ap.key, 'lower')] in (
str + ("[(%s, 'lower')] or [(%s, 'lower')]" % (m.D, m.nu)),
str + ("[(%s, 'lower')] or [(%s, 'lower')]" % (m.nu, m.D)))