Skip to content

Commit

Permalink
Testing duplicate in ParameterizedLinearRepn, changing the string rep…
Browse files Browse the repository at this point in the history
…resentation to not be the same as LinearRepn
  • Loading branch information
emma58 committed May 21, 2024
1 parent 794a3bf commit 2c4a1cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pyomo/repn/parameterized_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def to_expression(visitor, arg):


class ParameterizedLinearRepn(LinearRepn):
def __str__(self):
return (
f"ParameterizedLinearRepn(mult={self.multiplier}, const={self.constant}, "
f"linear={self.linear}, nonlinear={self.nonlinear})"
)

def walker_exitNode(self):
if self.nonlinear is not None:
return _GENERAL, self
Expand Down
14 changes: 14 additions & 0 deletions pyomo/repn/tests/test_parameterized_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,20 @@ def test_division_ANY_pseudo_constant(self):
self.assertEqual(repn.constant, 0)
self.assertIsNone(repn.nonlinear)

def test_duplicate(self):
m = self.make_model()
e = (1 + m.x) ** 2 + m.y

cfg = VisitorConfig()
visitor = ParameterizedLinearRepnVisitor(*cfg, wrt=[m.y])
visitor.max_exponential_expansion = 2
repn = visitor.walk_expression(e)

self.assertEqual(len(repn.linear), 0)
self.assertEqual(repn.multiplier, 1)
self.assertIs(repn.constant, m.y)
assertExpressionsEqual(self, repn.nonlinear, (m.x + 1) * (m.x + 1))

def test_pow_ANY_pseudo_constant(self):
m = self.make_model()
e = (m.x**2 + 3 * m.z) ** m.y
Expand Down

0 comments on commit 2c4a1cb

Please sign in to comment.