예제 #1
0
    def test_1(self):
        '''
        The simplest case that the black box has only two inputs and there is only one black block involved
        '''
        def blackbox(a, b):
            return sin(a - b)

        m = self.m
        bb = ExternalFunction(blackbox)
        m.eflist = [bb]
        m.c1 = Constraint(expr=m.x[0] * m.z[0]**2 + bb(m.x[0], m.x[1]) == 2 *
                          sqrt(2.0))
        pI = PyomoInterface(m, [bb])
        self.assertEqual(pI.lx, 2)
        self.assertEqual(pI.ly, 1)
        self.assertEqual(pI.lz, 3)
        self.assertEqual(len(list(identify_variables(m.c1.body))), 3)
        self.assertEqual(len(list(identify_variables(m.c2.body))), 2)
예제 #2
0
    def test_2(self):
        '''
        The simplest case that the black box has only one inputs and there is only a formula
        '''
        def blackbox(a):
            return sin(a)

        m = self.m
        bb = ExternalFunction(blackbox)
        m.eflist = [bb]
        m.c1 = Constraint(expr=m.x[0] * m.z[0]**2 + bb(m.x[0] - m.x[1]) == 2 *
                          sqrt(2.0))
        pI = PyomoInterface(m, [bb])
        self.assertEqual(pI.lx, 1)
        self.assertEqual(pI.ly, 1)
        self.assertEqual(pI.lz, 5)
        self.assertEqual(len(list(identify_variables(m.c1.body))), 3)
        self.assertEqual(len(list(identify_variables(m.c2.body))), 2)
        self.assertEqual(len(m.tR.conset), 1)
        self.assertEqual(len(list(identify_variables(m.tR.conset[1].body))), 3)