Ejemplo n.º 1
0
    def __init__(self, *args, **kwds):
        super(piecewise_sos2, self).__init__(*args, **kwds)

        # create vars
        y = self.v = variable_tuple(
            variable(lb=0) for i in xrange(len(self.breakpoints)))
        y_tuple = tuple(y)

        # create piecewise constraints
        self.c = constraint_list()

        self.c.append(linear_constraint(
            variables=y_tuple + (self.input,),
            coefficients=self.breakpoints + (-1,),
            rhs=0))

        self.c.append(linear_constraint(
            variables=y_tuple + (self.output,),
            coefficients=self.values + (-1,)))
        if self.bound == 'ub':
            self.c[-1].lb = 0
        elif self.bound == 'lb':
            self.c[-1].ub = 0
        else:
            assert self.bound == 'eq'
            self.c[-1].rhs = 0

        self.c.append(linear_constraint(variables=y_tuple,
                                        coefficients=(1,)*len(y),
                                        rhs=1))

        self.s = sos2(y)
Ejemplo n.º 2
0
    def test_type(self):
        s = sos([])
        self.assertTrue(isinstance(s, ICategorizedObject))
        self.assertTrue(isinstance(s, IComponent))
        self.assertTrue(isinstance(s, _ActiveComponentMixin))
        self.assertTrue(isinstance(s, ISOS))

        s = sos1([])
        self.assertTrue(isinstance(s, ICategorizedObject))
        self.assertTrue(isinstance(s, IComponent))
        self.assertTrue(isinstance(s, _ActiveComponentMixin))
        self.assertTrue(isinstance(s, ISOS))

        s = sos2([])
        self.assertTrue(isinstance(s, ICategorizedObject))
        self.assertTrue(isinstance(s, IComponent))
        self.assertTrue(isinstance(s, _ActiveComponentMixin))
        self.assertTrue(isinstance(s, ISOS))