Example #1
0
def convexify_para_constr(self):
    """
    input:
        self: a constraint of a problem
    return:
        if the constraint is dcp, return itself;
        otherwise, return
            a convexified constraint
            para: [left side, right side]
                if the left/right-hand side of the the constraint is linearized,
                left/right side = [zero order parameter, {variable: [value parameter, [gradient parameter]]}]
                else,
                left/right side = []
            dom: domain
    """
    if not self.is_dcp():
        dom = []  # domain
        para = []  # a list for parameters
        if self.expr.args[0].curvature == 'CONCAVE':  # left-hand concave
            lin = linearize_para(self.expr.args[0])  # linearize the expression
            left = lin[0]
            para.append(
                [lin[1], lin[2]]
            )  # [zero order parameter, {variable: [value parameter, [gradient parameter]]}]
            for con in lin[3]:
                dom.append(con)
        else:
            left = self.expr.args[0]
            para.append(
                []
            )  # appending an empty list indicates the expression has the right curvature
        if self.expr.args[
                1].curvature == 'CONCAVE':  # negative right-hand must be concave (right-hand is convex)
            lin = linearize_para(self.expr.args[1])  # linearize the expression
            neg_right = lin[0]
            para.append([lin[1], lin[2]])
            for con in lin[3]:
                dom.append(con)
        else:
            neg_right = self.expr.args[1]
            para.append([])
        return left + neg_right <= 0, para, dom
    else:
        return self
Example #2
0
def convexify_para_constr(self):
    """
    input:
        self: a constraint of a problem
    return:
        if the constraint is dcp, return itself;
        otherwise, return
            a convexified constraint
            para: [left side, right side]
                if the left/right-hand side of the the constraint is linearized,
                left/right side = [zero order parameter, {variable: [value parameter, [gradient parameter]]}]
                else,
                left/right side = []
            dom: domain
    """
    if not self.is_dcp():
        dom = [] # domain
        para = [] # a list for parameters
        if self.expr.args[0].curvature == 'CONCAVE': # left-hand concave
            lin = linearize_para(self.expr.args[0]) # linearize the expression
            left = lin[0]
            para.append([lin[1],lin[2]]) # [zero order parameter, {variable: [value parameter, [gradient parameter]]}]
            for con in lin[3]:
                dom.append(con)
        else:
            left = self.expr.args[0]
            para.append([]) # appending an empty list indicates the expression has the right curvature
        if self.expr.args[1].curvature == 'CONCAVE': # negative right-hand must be concave (right-hand is convex)
            lin = linearize_para(self.expr.args[1]) # linearize the expression
            neg_right = lin[0]
            para.append([lin[1],lin[2]])
            for con in lin[3]:
                dom.append(con)
        else:
            neg_right = self.expr.args[1]
            para.append([])
        return left + neg_right <= 0, para, dom
    else:
        return self
Example #3
0
def convexify_para_obj(obj):
    """
    input:
        obj: an objective of a problem
    return:
        if the objective is dcp,
        return the cost function (an expression);
        if the objective has a wrong curvature,
        return the linearized expression of the cost function,
        the zeros order parameter,
        the dictionary of parameters indexed by variables,
        the domain
    """
    if obj.is_dcp() == False:
        return linearize_para(obj.expr)
    else:
        return obj.expr
Example #4
0
def convexify_para_obj(obj):
    """
    input:
        obj: an objective of a problem
    return:
        if the objective is dcp,
        return the cost function (an expression);
        if the objective has a wrong curvature,
        return the linearized expression of the cost function,
        the zeros order parameter,
        the dictionary of parameters indexed by variables,
        the domain
    """
    if obj.is_dcp() == False:
        return linearize_para(obj.expr)
    else:
        return obj.expr