
    bi                     0    d Z ddlmZm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.
    )ABCMetaabstractmethodc                   L    e Zd ZdZd	d
dZd Zd Zd Zed        Z	ed        Z
y)	Reductiona  Abstract base class for reductions.

    A reduction is an actor that transforms a problem into an
    equivalent problem. By equivalent we mean that there exists
    a mapping between solutions of either problem: if we reduce a problem
    :math:`A` to another problem :math:`B` and then proceed to find a solution
    to :math:`B`, we can convert it to a solution of :math:`A` with at most a
    moderate amount of effort.

    A reduction that is instantiated with a non-None problem offers
    two key methods: `reduce` and `retrieve`. The `reduce()` method converts
    the problem the reduction was instantiated with to an equivalent
    problem. The `retrieve()` method takes as an argument a Solution
    for the equivalent problem and returns a Solution for the problem
    owned by the reduction.

    Every reduction offers three low-level methods: accepts, apply, and invert.
    The accepts method of a particular reduction specifies the types of problems
    that it is applicable to; the apply method takes a problem and reduces
    it to an equivalent form, and the invert method maps solutions
    from reduced-to problems to their problems of provenance.

    Parameters
    ----------
    problem : Problem
        A problem owned by this reduction; possibly None.
    Nc                     || _         y)zConstruct a reduction for reducing `problem`.

        If `problem` is not None, then a subsequent invocation of `reduce()`
        will reduce `problem` and return an equivalent one.
        N)problemselfr   s     U/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/reductions/reduction.py__init__zReduction.__init__1   s         c                     t               )a  States whether the reduction accepts a problem.

        Parameters
        ----------
        problem : Problem
            The problem to check.

        Returns
        -------
        bool
            True if the reduction can be applied, False otherwise.
        NotImplementedErrorr	   s     r   acceptszReduction.accepts9   s     "##r   c                     t        | d      r| j                  S | j                  t        d      | j	                  | j                        \  }}|| _        || _        |S )a2  Reduces the owned problem to an equivalent problem.

        Returns
        -------
        Problem or dict
            An equivalent problem, encoded either as a Problem or a dict.

        Raises
        ------
        ValueError
            If this Reduction was constructed without a Problem.
        _emitted_problemz0The reduction was constructed without a Problem.)hasattrr   r   
ValueErrorapply_retrieval_data)r
   r   retrieval_datas      r   reducezReduction.reduceH   se     4+,(((<<@B B #'**T\\": '-r   c                 h    t        | d      st        d      | j                  || j                        S )a  Retrieves a solution to the owned problem.

        Parameters
        ----------
        solution : Solution
            A solution to the problem emitted by `reduce()`.

        Returns
        -------
        Solution
            A solution to the owned problem.

        Raises
        ------
        ValueError
            If `self.problem` is None, or if `reduce()` was not previously
            called.
        r   z.`reduce()` must be called before `retrieve()`.)r   r   invertr   )r
   solutions     r   retrievezReduction.retrievea   s2    & t./MNN{{8T%9%9::r   c                     t               )a  Applies the reduction to a problem and returns an equivalent problem.

        Parameters
        ----------
        problem : Problem
            The problem to which the reduction will be applied.

        Returns
        -------
        Problem or dict
            An equivalent problem, encoded either as a Problem or a dict.

        InverseData, list or dict
            Data needed by the reduction in order to invert this particular
            application.
        r   r	   s     r   r   zReduction.applyx   s    $ "##r   c                     t               )a~  Returns a solution to the original problem given the inverse_data.

        Parameters
        ----------
        solution : Solution
            A solution to a problem that generated the inverse_data.
        inverse_data
            The data encoding the original problem.

        Returns
        -------
        Solution
            A solution to the original problem.
        r   )r
   r   inverse_datas      r   r   zReduction.invert   s      "##r   )N)returnN)__name__
__module____qualname____doc__r   r   r   r   r   r   r    r   r   r   r      sC    8$2;. $ $& $ $r   r   )	metaclassN)r%   abcr   r   r   r&   r   r   <module>r)      s     (H$' H$r   