|
10 | 10 | import pyomo.contrib.piecewise.tests.models as models |
11 | 11 | from pyomo.core import Var |
12 | 12 | from pyomo.core.base import TransformationFactory |
13 | | -from pyomo.environ import value |
| 13 | +from pyomo.core.expr.compare import assertExpressionsEqual |
| 14 | +from pyomo.environ import value, Expression |
14 | 15 | from pyomo.gdp import Disjunct, Disjunction |
15 | 16 |
|
16 | 17 |
|
@@ -85,3 +86,25 @@ def check_descend_into_expressions_objective_target(test, transformation, m=None |
85 | 86 | test.check_pw_log(m) |
86 | 87 | # And check that the paraboloid was *not* transformed. |
87 | 88 | test.assertIsNone(m.pw_paraboloid.get_transformation_var(m.paraboloid_expr)) |
| 89 | + |
| 90 | + |
| 91 | +def check_single_segment_no_disjunction(test, transformation, m=None): |
| 92 | + if m is None: |
| 93 | + m = models.make_single_segment_log_x_model() |
| 94 | + transform = TransformationFactory(transformation) |
| 95 | + transform.apply_to(m) |
| 96 | + |
| 97 | + # A single segment doesn't require making a discrete choice, so this |
| 98 | + # should not have created any GDP components. |
| 99 | + test.assertEqual(len(list(m.component_data_objects(Disjunct))), 0) |
| 100 | + test.assertEqual(len(list(m.component_data_objects(Disjunction))), 0) |
| 101 | + # Nor should it have introduced any new Vars (such as a substitute_var |
| 102 | + # or an indicator_var)--m.x should be the only Var in the model. |
| 103 | + model_vars = list(m.component_data_objects(Var)) |
| 104 | + test.assertEqual(len(model_vars), 1) |
| 105 | + test.assertIs(model_vars[0], m.x) |
| 106 | + |
| 107 | + z = m.pw_log.get_transformation_var(m.log_expr) |
| 108 | + test.assertIsInstance(z, Expression) |
| 109 | + assertExpressionsEqual(test, z.expr, m.f1(m.x), places=7) |
| 110 | + test.assertIs(m.log_expr.expr, z) |
0 commit comments