示例#1
0
    def graph_implementation(arg_objs, shape, data=None):
        """Reduces the atom to an affine expression and list of constraints.

        Parameters
        ----------
        arg_objs : list
            LinExpr for each argument.
        shape : tuple
            The shape of the resulting expression.
        data :
            Additional data required by the atom.

        Returns
        -------
        tuple
            (LinOp for objective, list of constraints)
        """
        x = arg_objs[0]
        y = arg_objs[1]  # Known to be a scalar.
        v = lu.create_var((1, 1))
        two = lu.create_const(2, (1, 1))
        t = lu.sum_expr([y, v])
        X_shape = (y.shape[0] + x.shape[0], 1)
        X = lu.vstack([lu.sub_expr(y, v), lu.mul_expr(two, x, x.shape)], X_shape)
        constraints = [SOC(t, X), lu.create_geq(y)]
        return (v, constraints)
示例#2
0
def gm(t, x, y):
    length = t.size[0] * t.size[1]
    return SOC_Axis(
        lu.reshape(lu.sum_expr([x, y]), (length, 1)),
        lu.vstack([
            lu.reshape(lu.sub_expr(x, y), (1, length)),
            lu.reshape(lu.mul_expr(two, t, t.size), (1, length))
        ], (2, length)), 0)
示例#3
0
def gm(t, x, y):
    length = t.size[0]*t.size[1]
    return SOC_Axis(lu.reshape(lu.sum_expr([x, y]), (length, 1)),
                    lu.vstack([
                        lu.reshape(lu.sub_expr(x, y), (1, length)),
                        lu.reshape(lu.mul_expr(two, t, t.size), (1, length))
                        ], (2, length)),
                    0)
示例#4
0
    def graph_implementation(arg_objs, size, data=None):
        """Stack the expressions vertically.

        Parameters
        ----------
        arg_objs : list
            LinExpr for each argument.
        size : tuple
            The size of the resulting expression.
        data :
            Additional data required by the atom.

        Returns
        -------
        tuple
            (LinOp for objective, list of constraints)
        """
        return (lu.vstack(arg_objs, size), [])
示例#5
0
    def graph_implementation(arg_objs, size, data=None):
        """Stack the expressions vertically.

        Parameters
        ----------
        arg_objs : list
            LinExpr for each argument.
        size : tuple
            The size of the resulting expression.
        data :
            Additional data required by the atom.

        Returns
        -------
        tuple
            (LinOp for objective, list of constraints)
        """
        return (lu.vstack(arg_objs, size), [])
示例#6
0
    def graph_implementation(self,
                             arg_objs,
                             shape: Tuple[int, ...],
                             data=None) -> Tuple[lo.LinOp, List[Constraint]]:
        """Stack the expressions vertically.

        Parameters
        ----------
        arg_objs : list
            LinExpr for each argument.
        shape : tuple
            The shape of the resulting expression.
        data :
            Additional data required by the atom.

        Returns
        -------
        tuple
            (LinOp for objective, list of constraints)
        """
        return (lu.vstack(arg_objs, shape), [])
示例#7
0
def combine_lin_ops(operators):
    """Combines the LinOps by stacking their output into a vector.

    Parameters
    ----------
    operators : list
        A list of LinOps.

    Returns
    -------
    LinOp
        The combined LinOp.
    """
    # First vectorize all the LinOp outputs.
    vect_lin_ops = []
    total_length = 0
    for lin_op in operators:
        if lin_op.size[1] != 1:
            new_size = (lin_op.size[0] * lin_op.size[1], 1)
            lin_op = lu.reshape(lin_op, new_size)
        vect_lin_ops.append(lin_op)
        total_length += lin_op.size[0]
    # Stack all the outputs into a single vector.
    return lu.vstack(vect_lin_ops, (total_length, 1))