Skip to content

Commit

Permalink
values are used as substitutions only in their first constraintset (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd authored Mar 21, 2018
1 parent 8709bb2 commit 526be08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
14 changes: 5 additions & 9 deletions docs/source/examples/performance_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AircraftP(Model):
Upper Unbounded
---------------
Wburn, aircraft.c
Wburn, aircraft.wing.c, aircraft.wing.A
Lower Unbounded
---------------
Expand All @@ -29,8 +29,6 @@ def setup(self, aircraft, state):
self.perf_models = [self.wing_aero]

W = aircraft.W
self.c = aircraft.wing.c
self.A = aircraft.wing.A
S = aircraft.wing.S

V = state.V
Expand All @@ -56,15 +54,13 @@ class Aircraft(Model):
Lower Unbounded
---------------
c, S
wing.c, wing.S
"""
def setup(self):
exec parse_variables(Aircraft.__doc__)
self.fuse = Fuselage()
self.wing = Wing()
self.components = [self.fuse, self.wing]
self.c = self.wing.c
self.S = self.wing.S

return self.components, W >= sum(c.W for c in self.components)

Expand All @@ -90,7 +86,7 @@ class FlightSegment(Model):
Upper Unbounded
---------------
Wburn, aircraft.c
Wburn, aircraft.wing.c, aircraft.wing.A
Lower Unbounded
---------------
Expand All @@ -114,7 +110,7 @@ class Mission(Model):
Upper Unbounded
---------------
aircraft.c
aircraft.wing.c, aircraft.wing.A
Lower Unbounded
---------------
Expand Down Expand Up @@ -147,7 +143,7 @@ class WingAero(Model):
Upper Unbounded
---------------
D, wing.c
D, wing.c, wing.A
Lower Unbounded
---------------
Expand Down
7 changes: 3 additions & 4 deletions gpkit/constraints/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ def __init__(self, constraints, substitutions=None): # pylint: disable=too-many
if "value" in k.descr})
if substitutions:
self.substitutions.update(substitutions)
# TODO: UNCOMMENT THE BELOW TO START POPPING SUBSTITUTIONS
# for key in self.substitutions:
# if not key.constant:
# key.descr.pop("value", None)
for key in self.substitutions:
if not key.constant:
key.descr.pop("value", None)
# TODO: the loop above and below have to be separate...for vectors?
for key in self.varkeys:
if key in self.substitutions:
Expand Down
9 changes: 4 additions & 5 deletions gpkit/tests/t_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,11 @@ def test_persistence(self):
m = gpkit.Model(x, [x >= 1-y, y <= ymax])
m.substitutions[ymax] = 0.2
self.assertAlmostEqual(m.localsolve(verbosity=0)["cost"], 0.8, 3)
# uncomment the lines below if values don't persist
# m = gpkit.Model(x, [x >= 1-y, y <= ymax])
# with self.assertRaises(ValueError): # from unbounded ymax
# m.localsolve(verbosity=0)
m = gpkit.Model(x, [x >= 1-y, y <= ymax])
# m.substitutions[ymax] = 0.1
with self.assertRaises(ValueError): # from unbounded ymax
m.localsolve(verbosity=0)
m = gpkit.Model(x, [x >= 1-y, y <= ymax])
m.substitutions[ymax] = 0.1
self.assertAlmostEqual(m.localsolve(verbosity=0)["cost"], 0.9, 3)

def test_united_sub_sweep(self):
Expand Down

0 comments on commit 526be08

Please sign in to comment.