示例#1
0
def mul_canon(expr, args):
    # Only allow param * var (not var * param). Associate right to left.
    # TODO: Only descend if both sides have parameters
    lhs = args[0]
    rhs = args[1]
    if not (lhs.parameters() and rhs.parameters()):
        return expr.copy(args), []

    op_type = type(expr)
    if lhs.variables():
        with scopes.dpp_scope():
            assert rhs.is_affine()
        t = Variable(lhs.shape)
        return op_type(t, rhs), [t == lhs]
    elif rhs.variables():
        with scopes.dpp_scope():
            assert lhs.is_affine()
        t = Variable(rhs.shape)
        return op_type(lhs, t), [t == rhs]

    # Neither side has variables. One side must be affine in parameters.
    lhs_affine = False
    rhs_affine = False
    with scopes.dpp_scope():
        lhs_affine = lhs.is_affine()
        rhs_affine = rhs.is_affine()
    assert lhs_affine or rhs_affine

    if lhs_affine:
        t = Variable(rhs.shape)
        return lhs * t, [t == rhs]
    else:
        t = Variable(lhs.shape)
        return t * rhs, [t == lhs]
示例#2
0
 def is_dgp(self, dpp: bool = False) -> bool:
     """The objective must be log-log concave.
     """
     if dpp:
         with scopes.dpp_scope():
             return self.args[0].is_log_log_concave()
     return self.args[0].is_log_log_concave()
示例#3
0
 def is_dcp(self, dpp: bool = False) -> bool:
     """The objective must be convex.
     """
     if dpp:
         with scopes.dpp_scope():
             return self.args[0].is_convex()
     return self.args[0].is_convex()
示例#4
0
 def is_dcp(self, dpp=False):
     """The objective must be concave.
     """
     if dpp:
         with scopes.dpp_scope():
             return self.args[0].is_concave()
     return self.args[0].is_concave()
示例#5
0
    def is_dpp(self, context='CP'):
        """The expression is a disciplined parameterized expression.

           context: cone program (CP) or quadratic program (QP)
        """
        with scopes.dpp_scope():
            return self.is_dcp()
示例#6
0
文件: zero.py 项目: whoiszyc/cvxpy
 def is_dgp(self, dpp: bool = False) -> bool:
     if dpp:
         with scopes.dpp_scope():
             return (self.args[0].is_log_log_affine()
                     and self.args[1].is_log_log_affine())
     return (self.args[0].is_log_log_affine()
             and self.args[1].is_log_log_affine())
示例#7
0
 def is_dcp(self, dpp: bool = False) -> bool:
     if dpp:
         with scopes.dpp_scope():
             args_ok = all(arg.is_affine() for arg in self.args)
             exps_ok = not isinstance(self.alpha, cvxtypes.parameter())
             return args_ok and exps_ok
     return all(arg.is_affine() for arg in self.args)
示例#8
0
 def is_dcp(self, dpp: bool = False) -> bool:
     """An exponential constraint is DCP if each argument is affine.
     """
     if dpp:
         with scopes.dpp_scope():
             return all(arg.is_affine() for arg in self.args)
     return all(arg.is_affine() for arg in self.args)
示例#9
0
 def is_dgp(self, dpp=False):
     """The objective must be log-log convex.
     """
     if dpp:
         with scopes.dpp_scope():
             return self.args[0].is_log_log_convex()
     return self.args[0].is_log_log_convex()
示例#10
0
 def is_dcp(self, dpp=False):
     """An SOC constraint is DCP if each of its arguments is affine.
     """
     if dpp:
         with scopes.dpp_scope():
             return all(arg.is_affine() for arg in self.args)
     return all(arg.is_affine() for arg in self.args)
示例#11
0
文件: psd.py 项目: charlenchen/cvxpy
 def is_dcp(self, dpp=False) -> bool:
     """A PSD constraint is DCP if the constrained expression is affine.
     """
     if dpp:
         with scopes.dpp_scope():
             return self.args[0].is_affine()
     return self.args[0].is_affine()
示例#12
0
文件: nonpos.py 项目: thanever/cvxpy
 def is_dgp(self, dpp=False):
     if dpp:
         with scopes.dpp_scope():
             return (self.args[0].is_log_log_convex()
                     and self.args[1].is_log_log_concave())
     return (self.args[0].is_log_log_convex()
             and self.args[1].is_log_log_concave())
示例#13
0
 def is_dpp(self, context='dcp') -> bool:
     with scopes.dpp_scope():
         if context.lower() == 'dcp':
             return self.is_dcp(dpp=True)
         elif context.lower() == 'dgp':
             return self.is_dgp(dpp=True)
         else:
             raise ValueError("Unsupported context ", context)
示例#14
0
 def is_dcp(self, dpp: bool = False) -> bool:
     """A power cone constraint is DCP if each argument is affine.
     """
     if dpp:
         with scopes.dpp_scope():
             args_ok = self.args[0].is_affine() and self.args[1].is_affine()
             exps_ok = not isinstance(self.alpha, cvxtypes.parameter())
             return args_ok and exps_ok
     return True
示例#15
0
    def is_dgp(self, dpp=False):
        """Checks whether the Expression is log-log DCP.

        Returns
        -------
        bool
            True if the Expression is log-log DCP, False otherwise.
        """
        if dpp:
            with scopes.dpp_scope():
                return self.is_log_log_convex() or self.is_log_log_concave()
        return self.is_log_log_convex() or self.is_log_log_concave()
示例#16
0
    def is_dcp(self, dpp=False):
        """Checks whether the Expression is DCP.

        Parameters
        ----------
        dpp : bool, optional
            If True, enforce the disciplined parametrized programming (DPP)
            ruleset; only relevant when the problem involves Parameters.

        Returns
        -------
        bool
            True if the Expression is DCP, False otherwise.
        """
        if dpp:
            with scopes.dpp_scope():
                return self.is_convex() or self.is_concave()
        return self.is_convex() or self.is_concave()
示例#17
0
 def is_dcp(self, dpp=False) -> bool:
     """A non-negative constraint is DCP if its argument is concave."""
     if dpp:
         with scopes.dpp_scope():
             return self.args[0].is_concave()
     return self.args[0].is_concave()
示例#18
0
文件: nonpos.py 项目: whoiszyc/cvxpy
 def is_dcp(self, dpp: bool = False) -> bool:
     """A non-positive constraint is DCP if its argument is convex."""
     if dpp:
         with scopes.dpp_scope():
             return self.expr.is_convex()
     return self.expr.is_convex()
示例#19
0
 def is_dpp(self):
     """The objective must be concave.
     """
     with scopes.dpp_scope():
         return self.args[0].is_concave()
示例#20
0
文件: zero.py 项目: whoiszyc/cvxpy
 def is_dcp(self, dpp: bool = False) -> bool:
     """An equality constraint is DCP if its argument is affine."""
     if dpp:
         with scopes.dpp_scope():
             return self.expr.is_affine()
     return self.expr.is_affine()
示例#21
0
文件: parameter.py 项目: zxuen/cvxpy
def is_param_affine(expr) -> bool:
    """Returns true if expression is parameters-affine (and variable-free)"""
    with scopes.dpp_scope():
        return not expr.variables() and expr.is_affine()
示例#22
0
文件: zero.py 项目: whoiszyc/cvxpy
 def is_dcp(self, dpp: bool = False) -> bool:
     """A zero constraint is DCP if its argument is affine."""
     if dpp:
         with scopes.dpp_scope():
             return self.args[0].is_affine()
     return self.args[0].is_affine()
示例#23
0
 def is_dpp(self):
     with scopes.dpp_scope():
         return self.args[0].is_convex()
示例#24
0
文件: nonpos.py 项目: thanever/cvxpy
 def is_dcp(self, dpp=False):
     """A non-positive constraint is DCP if its argument is convex."""
     if dpp:
         with scopes.dpp_scope():
             return self.args[0].is_convex()
     return self.args[0].is_convex()
示例#25
0
文件: atom.py 项目: songj01/cvxpy
 def is_dpp(self):
     """The expression is a disciplined parameterized expression.
     """
     with scopes.dpp_scope():
         return self.is_dcp()