
    bi                     T    d Z ddlZddlmZ ddlmZ  G d de      Z G d de      Zy)	a,  
Copyright 2013 Steven Diamond

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    N)
Constraint)scopesc                        e Zd ZdZdd fdZd ZdefdZed        Z	ed        Z
defdZdd	edefd
Zdd	edefdZdefdZed        Zed        ZddZ xZS )Zeroa  A constraint of the form :math:`x = 0`.

    The preferred way of creating a ``Zero`` constraint is through
    operator overloading. To constrain an expression ``x`` to be zero,
    simply write ``x == 0``. The former creates a ``Zero`` constraint with
    ``x`` as its argument.
    returnc                 0    t         t        |   |g|       y N)superr   __init__)selfexpr	constr_id	__class__s      Q/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/constraints/zero.pyr   zZero.__init__   s    dD"D695    c                 "    | j                         S z>Returns a string showing the mathematical constraint.
        namer   s    r   __str__zZero.__str__"        yy{r   c                 f    | j                   j                  dt        | j                  d         dS )@Returns a string with information about the constraint.
        (r   )r   __name__reprargsr   s    r   __repr__zZero.__repr__'   s+      >>22		!-/ 	/r   c                 4    | j                   d   j                  S ).int : The shape of the constrained expression.r   )r    shaper   s    r   r$   z
Zero.shape-   s     yy|!!!r   c                 4    | j                   d   j                  S )-int : The size of the constrained expression.r   )r    sizer   s    r   r'   z	Zero.size2   s     yy|   r   c                 &    d| j                   d   z  S )Nz%s == 0r   r    r   s    r   r   z	Zero.name7   s    499Q<''r   dppc                     |r;t        j                         5  | j                  d   j                         cddd       S | j                  d   j                         S # 1 sw Y   &xY w)z3A zero constraint is DCP if its argument is affine.r   N)r   	dpp_scoper    	is_affiner   r*   s     r   is_dcpzZero.is_dcp:   sV    !!# 0yy|--/0 0yy|%%''0 0s   AA$c                      y)NF r.   s     r   is_dgpzZero.is_dgpA   s    r   c                 "    | j                         S r	   r/   r   s    r   is_dqcpzZero.is_dqcpD       {{}r   c                     | j                   j                  yt        j                  | j                   j                        S z\The residual of the constraint.

        Returns
        -------
        Expression
        Nr   valuenpabsr   s    r   residualzZero.residualG   ,     99??"vvdiioo&&r   c                 4    | j                   d   j                  S z8NumPy.ndarray : The value of the dual variable.
        r   dual_variablesr:   r   s    r   
dual_valuezZero.dual_valueT        ""1%+++r   c                 @    | j                   d   j                  |       yzSave the value of the dual variable for the constraint's parent.

        Args:
            value: The value of the dual variable.
        r   NrB   
save_valuer   r:   s     r   save_dual_valuezZero.save_dual_valueZ        	A))%0r   r	   r   NF)r   
__module____qualname____doc__r   r   strr!   propertyr$   r'   r   boolr/   r2   r5   r=   rC   rJ   __classcell__r   s   @r   r   r      s    6
/# / " " ! !(c (($ (4 ($ 4   	' 	' , ,
1r   r   c                        e Zd ZdZdd fdZd ZdefdZd fdZe	d        Z
e	d        Ze	d	        Zdefd
ZddedefdZddedefdZdefdZe	d        Ze	d        ZddZ xZS )Equalityz,A constraint of the form :math:`x = y`.
    r   c                 F    ||z
  | _         t        t        |   ||g|       y r	   )_exprr
   rW   r   )r   lhsrhsr   r   s       r   r   zEquality.__init__f   s#    3Y
h&Sz9=r   c                 "    | j                         S r   r   r   s    r   r   zEquality.__str__j   r   r   c                     | j                   j                  dt        | j                  d         dt        | j                  d         dS )r   r   r   z,    r   r   r   s    r   r!   zEquality.__repr__o   s<      $~~66#DIIaL14		!3EG 	Gr   c                 B    t         t        |   | j                  g       y r	   )r
   rW   _construct_dual_variablesrY   )r   r    r   s     r   r`   z"Equality._construct_dual_variablesu   s    h7Er   c                     | j                   S r	   )rY   r   s    r   r   zEquality.exprx   s    zzr   c                 .    | j                   j                  S )r#   )r   r$   r   s    r   r$   zEquality.shape|   s     yyr   c                 .    | j                   j                  S )r&   )r   r'   r   s    r   r'   zEquality.size   s     yy~~r   c                 D    | j                   d   d| j                   d   S )Nr   z == r^   r)   r   s    r   r   zEquality.name   s    !YYq\499Q<88r   r*   c                     |r8t        j                         5  | j                  j                         cddd       S | j                  j                         S # 1 sw Y   #xY w)z8An equality constraint is DCP if its argument is affine.N)r   r,   r   r-   r.   s     r   r/   zEquality.is_dcp   sN    !!# -yy**,- -yy""$$- -s   AAc                 J   |rZt        j                         5  | j                  d   j                         xr | j                  d   j                         cd d d        S | j                  d   j                         xr | j                  d   j                         S # 1 sw Y   ExY w)Nr   r^   )r   r,   r    is_log_log_affiner.   s     r   r2   zEquality.is_dgp   s    !!# :		!668 9		!668: : 		!..0 1		!..0	2: :s   <BB"c                 "    | j                         S r	   r4   r   s    r   r5   zEquality.is_dqcp   r6   r   c                     | j                   j                  yt        j                  | j                   j                        S r8   r9   r   s    r   r=   zEquality.residual   r>   r   c                 4    | j                   d   j                  S r@   rA   r   s    r   rC   zEquality.dual_value   rD   r   c                 @    | j                   d   j                  |       yrF   rG   rI   s     r   rJ   zEquality.save_dual_value   rK   r   r	   rL   rM   )r   rN   rO   rP   r   r   rQ   r!   r`   rR   r   r$   r'   r   rS   r/   r2   r5   r=   rC   rJ   rT   rU   s   @r   rW   rW   c   s    >
G# GF      9c 9%$ %4 %2$ 24 2  	' 	' , ,
1r   rW   )	rP   numpyr;   cvxpy.constraints.constraintr   cvxpy.utilitiesr   r   rW   r1   r   r   <module>ro      s2      3 "I1: I1XP1z P1r   