How to use the cvxpy.expressions.variable.Variable function in cvxpy

To help you get started, we’ve selected a few cvxpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cvxgrp / cvxpy / tests / test_problem.py View on Github external
def setUp(self):
        self.a = Variable(name='a')
        self.b = Variable(name='b')
        self.c = Variable(name='c')

        self.x = Variable(2, name='x')
        self.y = Variable(3, name='y')
        self.z = Variable(2, name='z')

        self.A = Variable(2,2,name='A')
        self.B = Variable(2,2,name='B')
        self.C = Variable(3,2,name='C')
github cvxgrp / cvxpy / tests / test_atoms.py View on Github external
def setUp(self):
        self.x = Variable(2, name='x')
        self.y = Variable(2, name='y')

        self.A = Variable(2,2,name='A')
        self.B = Variable(2,2,name='B')
        self.C = Variable(3,2,name='C')
github cvxgrp / cvxpy / tests / test_atoms.py View on Github external
def setUp(self):
        self.x = Variable(2, name='x')
        self.y = Variable(2, name='y')

        self.A = Variable(2,2,name='A')
        self.B = Variable(2,2,name='B')
        self.C = Variable(3,2,name='C')
github cvxgrp / cvxpy / tests / test_constraints.py View on Github external
def setUp(self):
        self.a = Variable(name='a')
        self.b = Variable(name='b')

        self.x = Variable(2, name='x')
        self.y = Variable(3, name='y')
        self.z = Variable(2, name='z')

        self.A = Variable(2,2,name='A')
        self.B = Variable(2,2,name='B')
        self.C = Variable(3,2,name='C')
github cvxgrp / cvxpy / tests / test_problem.py View on Github external
def setUp(self):
        self.a = Variable(name='a')
        self.b = Variable(name='b')
        self.c = Variable(name='c')

        self.x = Variable(2, name='x')
        self.y = Variable(3, name='y')
        self.z = Variable(2, name='z')

        self.A = Variable(2,2,name='A')
        self.B = Variable(2,2,name='B')
        self.C = Variable(3,2,name='C')
github cvxgrp / dmcp / dmcp / find_set.py View on Github external
def search_conflict_l(expr,stack,V,t):
    '''
    search conflict variables in an expression using lists
    :param expr: an expression
    :param stack: stack of lists
    :param V: a list of id numbers of variables
    :param t: graph corresponding to the variables that can't be optimized together
    :return:
    '''
    if isinstance(expr,Leaf):
        if isinstance(expr,Variable):
            stack.append([expr.id])
        else:
            stack.append([])
    else:
        args_num = 0 # number of arguments
        for arg in expr.args:
            stack,t = search_conflict_l(arg,stack,V,t)
            args_num += 1
        if not is_atom_multiconvex(expr):        # at a convex node
            while args_num>1:
                stack[-2] = stack[-1] + stack[-2] # merge lists of its arguments
                args_num -= 1
                stack = stack[0:-1]
        else:                                     # at a multi-convex node (with two arguments)
            stack[-1] = list(set(stack[-1]))      # remove duplicates
            stack[-2] = list(set(stack[-2]))
github cvxgrp / cvxpy / cvxpy / reductions / dcp2cone / atom_canonicalizers / sigma_max_canon.py View on Github external
def sigma_max_canon(expr, args):
    A = args[0]
    n, m = A.shape
    shape = expr.shape
    if not np.prod(shape) == 1:
        raise RuntimeError('Invalid shape of expr in sigma_max canonicalization.')
    t = Variable(shape)
    tI_n = sp.eye(n) * t
    tI_m = sp.eye(m) * t
    X = bmat([[tI_n, A],
              [A.T, tI_m]])
    constraints = [PSD(X)]
    return t, constraints
github cvxgrp / cvxpy / cvxpy / reductions / complex2real / atom_canonicalizers / variable_canon.py View on Github external
def variable_canon(expr, real_args, imag_args, real2imag):
    if expr.is_real():
        return expr, None

    imag = Variable(expr.shape, var_id=real2imag[expr.id])
    if expr.is_imag():
        return None, imag
    elif expr.is_complex() and expr.is_hermitian():
        return Variable(expr.shape, var_id=expr.id, symmetric=True), (imag - imag.T)/2
    else:  # Complex.
        return Variable(expr.shape, var_id=expr.id), imag
github cvxgrp / cvxpy / cvxpy / transforms / partial_optimize.py View on Github external
opt_vars = [var for var in prob.variables() if not id(var) in ids]
    # If dont_opt_vars is not specified, it's the complement of opt_vars.
    elif dont_opt_vars is None:
        ids = [id(var) for var in opt_vars]
        dont_opt_vars = [var for var in prob.variables() if not id(var) in ids]
    elif opt_vars is not None and dont_opt_vars is not None:
        ids = [id(var) for var in opt_vars + dont_opt_vars]
        for var in prob.variables():
            if id(var) not in ids:
                raise ValueError(
                    ("If opt_vars and new_opt_vars are both specified, "
                     "they must contain all variables in the problem.")
                )

    # Replace the opt_vars in prob with new variables.
    id_to_new_var = {id(var): Variable(var.shape,
                                       **var.attributes) for var in opt_vars}
    new_obj = prob.objective.tree_copy(id_to_new_var)
    new_constrs = [con.tree_copy(id_to_new_var)
                   for con in prob.constraints]
    new_var_prob = Problem(new_obj, new_constrs)
    return PartialProblem(new_var_prob, opt_vars, dont_opt_vars)
github cvxgrp / cvxpy / expressions / containers.py View on Github external
def __init__(self, *args):
        for arg in args:
            # Scalar variable.
            if isinstance(arg, str):
                name = arg
                var = Variable(name=arg)
            # Vector variable.
            elif isinstance(arg, list) and len(arg) == 2:
                name = arg[0]
                var = Variable(name=arg[0],rows=arg[1])
            # Matrix variable.
            elif isinstance(arg, list) and len(arg) == 3:
                name = arg[0]
                var = Variable(name=arg[0],rows=arg[1],cols=arg[2])
            else:
                raise Exception("Invalid argument '%s' to 'Variables'." % arg)
            setattr(self, name, var)