
    bi                     F    d Z ddlmZ ddlmZmZ ddlmZ  G d de      Zy)a/  
Copyright 2017 Robin Verschueren

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.
    )cvxtypes)MaximizeMinimize)	Reductionc                   (    e Zd ZdZdefdZd Zd Zy)FlipObjectivezEFlip a minimization objective to a maximization and vice versa.
     returnc                      y)NT )selfproblems     Z/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/reductions/flip_objective.pyacceptszFlipObjective.accepts   s        c                     t        |j                        t        k(  }|rt        nt        } t	        j
                          ||j                  j                         |j                        }|g fS )a1  :math:`\max(f(x)) = -\min(-f(x))`

        Parameters
        ----------
        problem : Problem
            The problem whose objective is to be flipped.

        Returns
        -------
        Problem
            A problem with a flipped objective.
        list
            The inverse data.
        )type	objectiver   r   r   r   exprconstraints)r   r   is_maximizer   s       r   applyzFlipObjective.apply   s`     7,,-9 +H	$(""$Y0A0A0F0F/F%G%,%8%8:{r   c                 B    |j                   |j                    |_         |S )aj  Map the solution of the flipped problem to that of the original.

        Parameters
        ----------
        solution : Solution
            A solution object.
        inverse_data : list
            The inverse data returned by an invocation to apply.

        Returns
        -------
        Solution
            A solution to the original problem.
        )opt_val)r   solutioninverse_datas      r   invertzFlipObjective.invert2   s&     ' ( 0 00Hr   N)__name__
__module____qualname____doc__boolr   r   r   r   r   r   r   r      s    	$ *r   r   N)	r    cvxpy.expressionsr   cvxpy.problems.objectiver   r   cvxpy.reductions.reductionr   r   r   r   r   <module>r%      s!     ' 7 0-I -r   