Пример #1
0
def convert_constraint(constraint):
    if isinstance(constraint, EqConstraint):
        return expression.eq_constraint(convert_expression(constraint.args[0]),
                                        convert_expression(constraint.args[1]))
    elif isinstance(constraint, PSDConstraint):
        return expression.psd_constraint(
            convert_expression(constraint.args[0]),
            convert_expression(constraint.args[1]))
    elif isinstance(constraint, LeqConstraint):
        return expression.leq_constraint(
            convert_expression(constraint.args[0]),
            convert_expression(constraint.args[1]))
    elif isinstance(constraint, SOC_Elemwise):
        return expression.soc_elemwise_constraint(
            convert_expression(constraint.t),
            *[convert_expression(x) for x in constraint.x_elems])
    elif isinstance(constraint, SOC):
        return expression.soc_contraint(
            convert_expression(constraint.t),
            expression.vstack(
                *[convert_expression(x) for x in constraint.x_elems]))

    raise RuntimeError("Unknown constraint: %s" % type(constraint))
Пример #2
0
def convert_constraint(constraint):
    if isinstance(constraint, EqConstraint):
        return expression.eq_constraint(
            convert_expression(constraint.args[0]),
            convert_expression(constraint.args[1]))
    elif isinstance(constraint, PSDConstraint):
        return expression.psd_constraint(
            convert_expression(constraint.args[0]),
            convert_expression(constraint.args[1]))
    elif isinstance(constraint, LeqConstraint):
        return expression.leq_constraint(
            convert_expression(constraint.args[0]),
            convert_expression(constraint.args[1]))
    elif isinstance(constraint, SOC_Elemwise):
        return expression.soc_elemwise_constraint(
            convert_expression(constraint.t),
            *[convert_expression(x) for x in constraint.x_elems])
    elif isinstance(constraint, SOC):
        return expression.soc_contraint(
            convert_expression(constraint.t),
            expression.vstack(
                *[convert_expression(x) for x in constraint.x_elems]))

    raise RuntimeError("Unknown constraint: %s" % type(constraint))
Пример #3
0
def transform_norm_2_elementwise(expr):
    t = epi_var(expr, "norm_2_elementwise")
    return t, [expression.soc_elemwise_constraint(t, *expr.arg)]
Пример #4
0
def gm(t, x, y):
    return expression.soc_elemwise_constraint(
        expression.add(x, y), expression.add(x, expression.negate(y)),
        expression.multiply(expression.scalar_constant(2), t))
Пример #5
0
def gm(t, x, y):
    return expression.soc_elemwise_constraint(
        expression.add(x, y),
        expression.add(x, expression.negate(y)),
        expression.multiply(expression.scalar_constant(2), t))
Пример #6
0
def transform_norm_2_elementwise(expr):
    t = epi_var(expr, "norm_2_elementwise")
    return t, [expression.soc_elemwise_constraint(t, *expr.arg)]