def test_identify_components(self): M = ConcreteModel() M.x = Var() M.y = Var() M.w = Var() e = sin(M.x) + M.x * M.w + 3 v = list(str(v) for v in identify_components(e, set([M.x.__class__]))) self.assertEqual(v, ['x', 'w']) v = list(str(v) for v in identify_components(e, [M.x.__class__])) self.assertEqual(v, ['x', 'w'])
def test_identify_components(self): M = ConcreteModel() M.x = Var() M.y = Var() M.w = Var() e = sin(M.x) + M.x*M.w + 3 v = list(str(v) for v in identify_components(e, set([M.x.__class__]))) self.assertEqual(v, ['x', 'w']) v = list(str(v) for v in identify_components(e, [M.x.__class__])) self.assertEqual(v, ['x', 'w'])
def helper(self, func, param_val): m = pe.ConcreteModel() m.x = pe.Var(bounds=(-1, 1)) m.aux = pe.Var() m.p = pe.Param(mutable=True, initialize=param_val) m.c = pe.Constraint(expr=m.aux == func(m.p) * m.x**2) self.assertIn(m.p, ComponentSet(identify_components(m.c.body, [_ParamData, ScalarParam]))) coramin.relaxations.relax(m, in_place=True) rels = list(coramin.relaxations.relaxation_data_objects(m)) self.assertEqual(len(rels), 1) r = rels[0] self.assertIsInstance(r, coramin.relaxations.PWXSquaredRelaxationData) self.assertIn(m.p, ComponentSet(identify_components(m.aux_cons[1].body, [_ParamData, ScalarParam])))