Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Mar 4, 2020
1 parent d8bf702 commit 983a92e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gpkit/constraints/costed.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, cost, constraints, substitutions=None):
self.cost = maybe_flatten(cost)
if isinstance(self.cost, np.ndarray): # if it's still a vector
raise ValueError("Cost must be scalar, not the vector %s." % cost)
subs = dict(self.cost.varkeyvalues())
subs = dict({k: k.value for k in cost.varkeys if "value" in k.descr})
if substitutions:
subs.update(substitutions)
ConstraintSet.__init__(self, constraints, subs)
Expand Down
4 changes: 2 additions & 2 deletions gpkit/constraints/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def __init__(self, constraints, substitutions=None): # pylint: disable=too-many
if hasattr(self[i], "substitutions"):
self.substitutions.update(self[i].substitutions)
else:
self.substitutions.update({k: k.value for k in self[i].varkeys
if "value" in k.descr})
self.substitutions.update({k: k.value \
for k in self[i].varkeys if "value" in k.descr})
self.bounded.update(self[i].bounded)
for bound, solutionset in self[i].meq_bounded.items():
self.meq_bounded[bound].update(solutionset)
Expand Down
2 changes: 1 addition & 1 deletion gpkit/nomials/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def value(self):
"""
if isinstance(self, FixedScalar):
return self.cs[0]
p = self.sub(self.varkeyvalues()) # pylint: disable=not-callable
p = self.sub({k: k.value for k in self.vks if "value" in k.descr}) # pylint: disable=not-callable
return p.cs[0] if isinstance(p, FixedScalar) else p

def __eq__(self, other):
Expand Down
4 changes: 0 additions & 4 deletions gpkit/nomials/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ def varkeys(self):
self._varkeys = KeySet(self.vks)
return self._varkeys

def varkeyvalues(self):
"Returns the NomialData's keys' values"
return {k: k.descr["value"] for k in self.vks if "value" in k.descr}

def __eq__(self, other):
"Equality test"
if not hasattr(other, "hmap"):
Expand Down
18 changes: 8 additions & 10 deletions gpkit/nomials/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,14 @@ def __init__(self, left, oper, right):
def relaxed(self, relaxvar):
"Returns the relaxation of the constraint in a list."
if self.oper == ">=":
relaxed = [relaxvar*self.left >= self.right]
elif self.oper == "<=":
relaxed = [self.left <= relaxvar*self.right]
elif self.oper == "=":
relaxed = [self.left <= relaxvar*self.right,
relaxvar*self.left >= self.right]
else:
raise ValueError(
"Constraint %s had unknown operator %s." % self.oper, self)
return relaxed
return [relaxvar*self.left >= self.right]
if self.oper == "<=":
return [self.left <= relaxvar*self.right]
if self.oper == "=":
return [self.left <= relaxvar*self.right,
relaxvar*self.left >= self.right]
raise ValueError(
"Constraint %s had unknown operator %s." % self.oper, self)


# pylint: disable=too-many-instance-attributes, invalid-unary-operand-type
Expand Down

0 comments on commit 983a92e

Please sign in to comment.