예제 #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
파일: nonpos.py 프로젝트: charlenchen/cvxpy
 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()