Skip to content

Commit

Permalink
Adding a test for cloning a multivariate piecewise linear function too
Browse files Browse the repository at this point in the history
  • Loading branch information
emma58 committed Aug 13, 2024
1 parent ffcffc6 commit defc953
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pyomo/contrib/piecewise/tests/test_nonlinear_to_pwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,36 @@ def test_paraboloid_objective_uniform_grid(self):

self.check_pw_linear_paraboloid(m, pwlf, x1, x2, y1, y2)

@unittest.skipUnless(numpy_available, "Numpy is not available")
@unittest.skipUnless(scipy_available, "Scipy is not available")
def test_multivariate_clone(self):
m = self.make_paraboloid_model()

n_to_pwl = TransformationFactory('contrib.piecewise.nonlinear_to_pwl')
n_to_pwl.apply_to(
m,
num_points=2,
domain_partitioning_method=DomainPartitioningMethod.UNIFORM_GRID,
)

twin = m.clone()

# check obj is transformed
self.assertFalse(twin.obj.active)

pwlf = list(
twin.component_data_objects(PiecewiseLinearFunction, descend_into=True)
)
self.assertEqual(len(pwlf), 1)
pwlf = pwlf[0]

x1 = 0.00030000000000000003
x2 = 2.9997
y1 = 1.0006
y2 = 6.9994

self.check_pw_linear_paraboloid(twin, pwlf, x1, x2, y1, y2)

@unittest.skipUnless(numpy_available, "Numpy is not available")
@unittest.skipUnless(scipy_available, "Scipy is not available")
def test_objective_target(self):
Expand Down

0 comments on commit defc953

Please sign in to comment.