Skip to content

Commit

Permalink
Merge pull request #1 from carldlaird/squared_lin_exp
Browse files Browse the repository at this point in the history
Squared lin exp
  • Loading branch information
johwiebe committed Jun 16, 2020
2 parents cdd8f97 + d2c560e commit 529766f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pyomo/repn/standard_repn.py
Expand Up @@ -743,12 +743,19 @@ def _collect_pow(exp, multiplier, idMap, compute_values, verbose, quadratic):
or res.constant != 0)
if has_constant:
ans.constant = multiplier*res.constant*res.constant
while len(res.linear) > 0:
key1, coef1 = res.linear.popitem()

# this is reversed since we want to pop off the end for efficiency
# and the quadratic terms have a convention that the indexing tuple
# of key1, key2 is such that key1 <= key2
keys = sorted(res.linear.keys(), reverse=True)
while len(keys) > 0:
key1 = keys.pop()
coef1 = res.linear[key1]
if has_constant:
ans.linear[key1] = 2*multiplier*coef1*res.constant
ans.quadratic[key1,key1] = multiplier*coef1*coef1
for key2, coef2 in res.linear.items():
for key2 in keys:
coef2 = res.linear[key2]
ans.quadratic[key1,key2] = 2*multiplier*coef1*coef2
return ans

Expand Down

0 comments on commit 529766f

Please sign in to comment.