Example #1
0
    def _pm_expand(self, constr):

        # Get objects
        v = constr.left
        v = vstack([v[i, 0] for i in range(0, v.shape[0])])
        n = v.shape[0] - 1
        x = vstack([v[0:n, 0]])
        y = v[n, 0]
        z = variable()

        # One element
        if n == 1:
            return cvxpy_list([greater_equals(x, 0), greater_equals(x, y)])

        # Get power of 2 size
        m = 0
        while np.log2(n + m) % 1 != 0:
            m += 1

        # Copy elements of x on a list and restrict them
        constr_list = []
        el_list = []
        for i in range(0, n, 1):
            el_list += [x[i, 0]]
            if (not np.isscalar(x[i, 0]) and type(x[i, 0]) is not cvxpy_obj):
                constr_list += [greater_equals(x[i, 0], 0)]

        # Construct expansion
        for i in range(0, m, 1):
            el_list += [z]
        while len(el_list) > 2:
            new_list = []
            for i in range(0, int(len(el_list) / 2)):
                x1 = el_list[2 * i]
                x2 = el_list[2 * i + 1]
                w = variable()
                constr_list += [
                    belongs(vstack((hstack((x1, w)), hstack((w, x2)))),
                            semidefinite_cone)
                ]
                new_list += [w]
            el_list = new_list
        x1 = el_list[0]
        x2 = el_list[1]
        constr_list += [
            belongs(vstack((hstack((x1, z)), hstack((z, x2)))),
                    semidefinite_cone)
        ]
        constr_list += [greater_equals(z, 0), greater_equals(z, y)]
        return cvxpy_list(constr_list)
    def _pm_expand(self,constr):
        
        # Get objects
        v = constr.left
        v = vstack([v[i,0] for i in range(0,v.shape[0])])
        n = v.shape[0]-1
        x = vstack([v[0:n,0]])
        y = v[n,0]
        z = variable()

        # One element
        if n==1:
            return cvxpy_list([greater_equals(x,0),
                               greater_equals(x,y)])

        # Get power of 2 size
        m = 0
        while np.log2(n+m) % 1 != 0:
            m += 1

        # Copy elements of x on a list and restrict them
        constr_list = []
        el_list = []
        for i in range(0,n,1):
            el_list+=[x[i,0]]
            if (not np.isscalar(x[i,0]) and
                type(x[i,0]) is not cvxpy_obj):
                constr_list += [greater_equals(x[i,0],0)]

        # Construct expansion
        for i in range(0,m,1):
            el_list += [z]
        while len(el_list) > 2:
            new_list = []
            for i in range(0,int(len(el_list)/2)):
                x1 = el_list[2*i]
                x2 = el_list[2*i+1]
                w = variable()
                constr_list += [belongs(vstack((hstack((x1,w)),
                                                hstack((w,x2)))),
                                        semidefinite_cone)]
                new_list += [w]
            el_list = new_list
        x1 = el_list[0]
        x2 = el_list[1]
        constr_list += [belongs(vstack((hstack((x1,z)),
                                        hstack((z,x2)))),
                                semidefinite_cone)]
        constr_list += [greater_equals(z,0),greater_equals(z,y)]
        return cvxpy_list(constr_list)
Example #3
0
    def __call__(self, *arg):

        # Check number of arguments
        if len(arg) != 1:
            raise ValueError("Invalid number of arguments")

        # Extract argument
        if type(arg[0]) is list:
            x = hstack(arg[0])
        else:
            x = arg[0]

        # Process
        if type(x).__name__ in SCALAR_OBJS:
            return x
        elif type(x).__name__ in ARRAY_OBJS:
            (m, n) = x.shape
            if m != 1 and n != 1:
                raise ValueError("Argument must be 1-Dimensional")
            children = []
            for i in range(0, m, 1):
                for j in range(0, n, 1):
                    if np.isscalar(x[i, j]):
                        children += [cvxpy_obj(CONSTANT, x[i, j], str(x[i, j]))]
                    else:
                        children += [x[i, j]]
            return cvxpy_tree(self, children)
        else:
            return np.max(x)
Example #4
0
    def __call__(self, *arg):

        # Check number of arguments
        if (len(arg) != 1):
            raise ValueError('Invalid number of arguments')

        # Extract argument
        if (type(arg[0]) is list):
            x = hstack(arg[0])
        else:
            x = arg[0]

        # Process
        if (type(x).__name__ in SCALAR_OBJS):
            return x
        elif (type(x).__name__ in ARRAY_OBJS):
            (m, n) = x.shape
            if (m != 1 and n != 1):
                raise ValueError('Argument must be 1-Dimensional')
            children = []
            for i in range(0, m, 1):
                for j in range(0, n, 1):
                    if (np.isscalar(x[i, j])):
                        children += [
                            cvxpy_obj(CONSTANT, x[i, j], str(x[i, j]))
                        ]
                    else:
                        children += [x[i, j]]
            return cvxpy_tree(self, children)
        else:
            return np.max(x)
Example #5
0
    def _pm_expand(self,constr):
        
        # Get shape
        v = constr.left
        n = v.shape[0]-1
        x = v[0:n,0]
        y = v[n,0]
        z = var()

        # Get power of 2 size
        m = 0
        while (np.log2(n+m) % 1 != 0):
            m = m + 1

        # Copy elements of x on a list and restrict them
        constr_list = []
        el_list = []
        for i in range(0,n,1):
            el_list+=[x[i,0]]
            if(not np.isscalar(x[i,0]) and
               type(x[i,0]) is not cvxpy_obj):
                constr_list += [greater(x[i,0],0)]

        # Construct expansion
        z = var()
        for i in range(0,m,1):
            el_list += [z]
        while(len(el_list) > 2):
            new_list = []
            for i in range(0,len(el_list)/2):
                x1 = el_list[2*i]
                x2 = el_list[2*i+1]
                w = var()
                constr_list += [belongs(vstack((hstack((x1,w)),
                                                hstack((w,x2)))),
                                        sdc(2))]
                new_list += [w]
            el_list = new_list
        x1 = el_list[0]
        x2 = el_list[1]
        constr_list += [belongs(vstack((hstack((x1,z)),
                                        hstack((z,x2)))),
                                sdc(2))]
        constr_list += [greater(z,0),greater(z,y)]
        return cvxpy_list(constr_list)
Example #6
0
    def _pm_expand(self, constr):

        # Get shape
        v = constr.left
        n = v.shape[0] - 1
        x = v[0:n, 0]
        y = v[n, 0]
        z = var()

        # Get power of 2 size
        m = 0
        while np.log2(n + m) % 1 != 0:
            m = m + 1

        # Copy elements of x on a list and restrict them
        constr_list = []
        el_list = []
        for i in range(0, n, 1):
            el_list += [x[i, 0]]
            if not np.isscalar(x[i, 0]) and type(x[i, 0]) is not cvxpy_obj:
                constr_list += [greater(x[i, 0], 0)]

        # Construct expansion
        z = var()
        for i in range(0, m, 1):
            el_list += [z]
        while len(el_list) > 2:
            new_list = []
            for i in range(0, len(el_list) / 2):
                x1 = el_list[2 * i]
                x2 = el_list[2 * i + 1]
                w = var()
                constr_list += [belongs(vstack((hstack((x1, w)), hstack((w, x2)))), sdc(2))]
                new_list += [w]
            el_list = new_list
        x1 = el_list[0]
        x2 = el_list[1]
        constr_list += [belongs(vstack((hstack((x1, z)), hstack((z, x2)))), sdc(2))]
        constr_list += [greater(z, 0), greater(z, y)]
        return cvxpy_list(constr_list)
Example #7
0
 def link_tt_heuristic(link):
   ff = link.l / link.fd.v
   q_max = (link.l / link.fd.q_max) * link.v_dens
   rho_hat = link.fd.rho_max - link.v_dens
   cong = link.l / link.fd.w * (link.fd.rho_max * quad_over_lin(1.0 , rho_hat) - 1)
   return cvx_max(hstack([ff, q_max, cong]))