-
Notifications
You must be signed in to change notification settings - Fork 40
/
boundschecking.py
65 lines (55 loc) · 1.55 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
60
61
62
63
64
65
"Verifies that bounds are caught through monomials"
from gpkit import Model, parse_variables
from gpkit.exceptions import UnboundedGP, UnknownInfeasible
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 UnboundedGP:
gp = m.gp(checkbounds=False)
missingbounds = gp.check_bounds()
try:
sol = gp.solve(verbosity=0) # Errors on mosek_cli
except UnknownInfeasible: # pragma: no cover
pass
bpl = ", but would gain it from any of these sets: "
assert missingbounds[(m.D.key, 'lower')] == bpl + "[(%s, 'lower')]" % m.Ap
assert missingbounds[(m.nu.key, 'lower')] == bpl + "[(%s, 'lower')]" % m.Ap
# ordering is arbitrary:
assert missingbounds[(m.Ap.key, 'lower')] in (
bpl + ("[(%s, 'lower')] or [(%s, 'lower')]" % (m.D, m.nu)),
bpl + ("[(%s, 'lower')] or [(%s, 'lower')]" % (m.nu, m.D)))