+
    /i                         ^ RI t ^ RIt^ RIHtHtHtHt ^RIH	t	 ^RI
HtHtHtHtHt ^RIHtHtHtHtHt ^RIHtHtHtHtHtHt RR ltR tR	 tR
 t R t!R t"R t#R t$R# )    N)BoundsLinearConstraintNonlinearConstraintOptimizeResult)TrustRegion)ObjectiveFunctionBoundConstraintsLinearConstraintsNonlinearConstraintsProblem)MaxEvalErrorTargetSuccessCallbackSuccessFeasibleSuccessexact_1d_array)
ExitStatusOptions	ConstantsDEFAULT_OPTIONSDEFAULT_CONSTANTSPRINT_OPTIONSc                   Vf   / pM\        V4      pVP                  \        P                  \        \        P                  ,          4      p\        V4      pVP                  \        P                  \        \        P                  ,          4      p	\        V	4      p	VP                  \        P                  \        \        P                  ,          4      p
\        V
4      p
VP                  \        P                  \        \        P                  ,          4      p\        V4      p\        P                  V9   d(   V\        P                  ,          ^ 8:  d   \        R4      hVP                  \        P                  \        \        P                  ,          4      p\        V4      p\        P                  V9   d(   V\        P                  ,          ^ 8:  d   \        R4      hVP                  \        P                  \        \        P                  ,          4      p\        V4      pVP                  \        P                  \        \        P                  ,          4      p\        V4      p\        V\         4      '       g   V3p\#        WV.VO5!  p\%        VR4      '       g   V.p\'        V4      p\)        \+        VV4      4      p\-        V4      w  pp\/        VVV4      p\1        VW4      p\3        VVVVVVV	V
VVVV4      p\5        VVP6                  4       \9        R/ VB pVP:                  P<                  '       g   \?        VRR\@        PB                  ^ V4      # VP6                  ^ 8X  d   \?        VRR\@        PD                  ^ V4      # V'       d   \G        R4       \G        R	V\        PH                  ,           R
24       \G        RV\        PJ                  ,           R
24       \G        RV\        PL                  ,           R
24       \G        RV\        PN                  ,           R
24       \G        4         \Q        VVV4      pRp^ pRp^ p^ p^ p TT\        PN                  ,          8  d   \@        P`                  pEM&T^,          p\b        Pd                  Pk                  TPl                  TPn                  Pp                  Pr                  ,
          4      T\t        Pv                  ,          TPx                  ,          8  d   TP{                  T4       TPx                  pTP}                  T4      w  p p!T T!,           p"\b        Pd                  Pk                  T"4      p#T#T\t        P~                  ,          TP                  ,          8:  d   T;Px                  T\t        P                  ,          ,          un<        TTP                  8  d   ^ p^ pM,T^,          pT^,          pT#RTP                  ,          8  d   ^ pT^8  ;'       g    T^8  p$T$'       d	   ^ p^ pRp%EM& TP                  4       w  pp&T&\        TPx                  T\t        P                  ,          TP                  ,          4      8  p%EMTP                  T"4      p'T''       Ed    \        TTT"T4      w  p(p)p*TP                  TPl                  TP                  TP                  TP                  4      p+TP                  TPl                  T",           T(T)T*4      p,TP                  R8X  d   T,T+8  d   \b        Pd                  Pk                  T 4      T\t        P                  ,          R,          TPx                  ,          8  dS   TP                  T"T4      p-\b        Pd                  Pk                  T-4      R8  d   T"T-,          p" \        TTT"T4      w  p(p)p*TP                  T"T(T)T*4      p. TP                  TPl                  T",           4      ^ ,          p TPn                  P                  TTPl                  T",           T(T)T*4      p/TP                  4        TP                  T"T.4       TPx                  TP                  8:  d   T.T\t        P                  ,          8  d   ^ pMT^,          pTPn                  P                  TPl                  4      p0 TPn                  P                  TPl                  4      p1\b        Pd                  Pk                  T04      T\t        P                  ,          \b        Pd                  Pk                  T14      ,          8  d   ^ pT^8  d    TPn                  P                  4        ^ pTP                  TPl                  T",           4        TP                  4       w  pp&T/;'       gb    T.T\t        P                  ,          8*  ;'       d@    T&\        TPx                  T\t        P                  ,          TP                  ,          4      8  p%TTP                  8*  ;'       d*    T.T\t        P                  ,          8*  ;'       d    T%'       * p$MRp$Rp%T$'       d   TP                  T\        PJ                  ,          8:  d   Rp\@        P                  pEM$TP                  T4       TP                  4        T'       d   TP                  TPl                  TP                  TP                  4      p2\        RTP                   2TTP                  TPl                  4      TP                  T2TP                  T4       \G        4        T%'       g   EK   TP                  TT4      p" \        TTT"T4      w  p(p)p* TPn                  P                  TTPl                  T",           T(T)T*4       TP                  4        EKU  \?        TTP                  TTTT4      #   \R         d"    \?        TRR\@        PT                  ^ T4      u # \V         d"    \?        TRR\@        PX                  ^ T4      u # \Z         d"    \?        TRR\@        P\                  ^ T4      u # \^         d"    \?        TRR\@        P`                  ^ T4      u # \b        Pd                  Pf                   d"    \?        TRR\@        Ph                  ^ T4      u # i ; i  \b        Pd                  Pf                   d    \@        Ph                  p EK8  i ; i  \R         d    \@        PT                  pRp EK]  \Z         d    \@        P\                  pRp EK}  \V         d    \@        PX                  pRp EK  \^         d    \@        P                  p EK  i ; i  \R         d    \@        PT                  pRp EK  \Z         d    \@        P\                  pRp EK   \V         d    \@        PX                  pRp EK   \^         d    \@        P                  p EK>  i ; i  \b        Pd                  Pf                   d    \@        Ph                  p EKu  i ; i  \b        Pd                  Pf                   d    \@        Ph                  p EK  i ; i  \b        Pd                  Pf                   d    \@        Ph                  p EK  i ; i  \b        Pd                  Pf                   d    \@        Ph                  p EK  i ; i  \b        Pd                  Pf                   d    \@        Ph                  p EKQ  i ; i  \b        Pd                  Pf                   d    \@        Ph                  p EK  i ; i  \R         d    \@        PT                  pRp EK  \Z         d    \@        P\                  pRp EK  \V         d    \@        PX                  pRp EK  \^         d    \@        P                  p EK  i ; i  \b        Pd                  Pf                   d    \@        Ph                  p EKB  i ; i)a:  
Minimize a scalar function using the COBYQA method.

The Constrained Optimization BY Quadratic Approximations (COBYQA) method is
a derivative-free optimization method designed to solve general nonlinear
optimization problems. A complete description of COBYQA is given in [3]_.

Parameters
----------
fun : {callable, None}
    Objective function to be minimized.

        ``fun(x, *args) -> float``

    where ``x`` is an array with shape (n,) and `args` is a tuple. If `fun`
    is ``None``, the objective function is assumed to be the zero function,
    resulting in a feasibility problem.
x0 : array_like, shape (n,)
    Initial guess.
args : tuple, optional
    Extra arguments passed to the objective function.
bounds : {`scipy.optimize.Bounds`, array_like, shape (n, 2)}, optional
    Bound constraints of the problem. It can be one of the cases below.

    #. An instance of `scipy.optimize.Bounds`. For the time being, the
       argument ``keep_feasible`` is disregarded, and all the constraints
       are considered unrelaxable and will be enforced.
    #. An array with shape (n, 2). The bound constraints for ``x[i]`` are
       ``bounds[i][0] <= x[i] <= bounds[i][1]``. Set ``bounds[i][0]`` to
       :math:`-\infty` if there is no lower bound, and set ``bounds[i][1]``
       to :math:`\infty` if there is no upper bound.

    The COBYQA method always respect the bound constraints.
constraints : {Constraint, list}, optional
    General constraints of the problem. It can be one of the cases below.

    #. An instance of `scipy.optimize.LinearConstraint`. The argument
       ``keep_feasible`` is disregarded.
    #. An instance of `scipy.optimize.NonlinearConstraint`. The arguments
       ``jac``, ``hess``, ``keep_feasible``, ``finite_diff_rel_step``, and
       ``finite_diff_jac_sparsity`` are disregarded.

    #. A list, each of whose elements are described in the cases above.

callback : callable, optional
    A callback executed at each objective function evaluation. The method
    terminates if a ``StopIteration`` exception is raised by the callback
    function. Its signature can be one of the following:

        ``callback(intermediate_result)``

    where ``intermediate_result`` is a keyword parameter that contains an
    instance of `scipy.optimize.OptimizeResult`, with attributes ``x``
    and ``fun``, being the point at which the objective function is
    evaluated and the value of the objective function, respectively. The
    name of the parameter must be ``intermediate_result`` for the callback
    to be passed an instance of `scipy.optimize.OptimizeResult`.

    Alternatively, the callback function can have the signature:

        ``callback(xk)``

    where ``xk`` is the point at which the objective function is evaluated.
    Introspection is used to determine which of the signatures to invoke.
options : dict, optional
    Options passed to the solver. Accepted keys are:

        disp : bool, optional
            Whether to print information about the optimization procedure.
            Default is ``False``.
        maxfev : int, optional
            Maximum number of function evaluations. Default is ``500 * n``.
        maxiter : int, optional
            Maximum number of iterations. Default is ``1000 * n``.
        target : float, optional
            Target on the objective function value. The optimization
            procedure is terminated when the objective function value of a
            feasible point is less than or equal to this target. Default is
            ``-numpy.inf``.
        feasibility_tol : float, optional
            Tolerance on the constraint violation. If the maximum
            constraint violation at a point is less than or equal to this
            tolerance, the point is considered feasible. Default is
            ``numpy.sqrt(numpy.finfo(float).eps)``.
        radius_init : float, optional
            Initial trust-region radius. Typically, this value should be in
            the order of one tenth of the greatest expected change to `x0`.
            Default is ``1.0``.
        radius_final : float, optional
            Final trust-region radius. It should indicate the accuracy
            required in the final values of the variables. Default is
            ``1e-6``.
        nb_points : int, optional
            Number of interpolation points used to build the quadratic
            models of the objective and constraint functions. Default is
            ``2 * n + 1``.
        scale : bool, optional
            Whether to scale the variables according to the bounds. Default
            is ``False``.
        filter_size : int, optional
            Maximum number of points in the filter. The filter is used to
            select the best point returned by the optimization procedure.
            Default is ``sys.maxsize``.
        store_history : bool, optional
            Whether to store the history of the function evaluations.
            Default is ``False``.
        history_size : int, optional
            Maximum number of function evaluations to store in the history.
            Default is ``sys.maxsize``.
        debug : bool, optional
            Whether to perform additional checks during the optimization
            procedure. This option should be used only for debugging
            purposes and is highly discouraged to general users. Default is
            ``False``.

    Other constants (from the keyword arguments) are described below. They
    are not intended to be changed by general users. They should only be
    changed by users with a deep understanding of the algorithm, who want
    to experiment with different settings.

Returns
-------
`scipy.optimize.OptimizeResult`
    Result of the optimization procedure, with the following fields:

        message : str
            Description of the cause of the termination.
        success : bool
            Whether the optimization procedure terminated successfully.
        status : int
            Termination status of the optimization procedure.
        x : `numpy.ndarray`, shape (n,)
            Solution point.
        fun : float
            Objective function value at the solution point.
        maxcv : float
            Maximum constraint violation at the solution point.
        nfev : int
            Number of function evaluations.
        nit : int
            Number of iterations.

    If ``store_history`` is True, the result also has the following fields:

        fun_history : `numpy.ndarray`, shape (nfev,)
            History of the objective function values.
        maxcv_history : `numpy.ndarray`, shape (nfev,)
            History of the maximum constraint violations.

    A description of the termination statuses is given below.

    .. list-table::
        :widths: 25 75
        :header-rows: 1

        * - Exit status
          - Description
        * - 0
          - The lower bound for the trust-region radius has been reached.
        * - 1
          - The target objective function value has been reached.
        * - 2
          - All variables are fixed by the bound constraints.
        * - 3
          - The callback requested to stop the optimization procedure.
        * - 4
          - The feasibility problem received has been solved successfully.
        * - 5
          - The maximum number of function evaluations has been exceeded.
        * - 6
          - The maximum number of iterations has been exceeded.
        * - -1
          - The bound constraints are infeasible.
        * - -2
          - A linear algebra error occurred.

Other Parameters
----------------
decrease_radius_factor : float, optional
    Factor by which the trust-region radius is reduced when the reduction
    ratio is low or negative. Default is ``0.5``.
increase_radius_factor : float, optional
    Factor by which the trust-region radius is increased when the reduction
    ratio is large. Default is ``numpy.sqrt(2.0)``.
increase_radius_threshold : float, optional
    Threshold that controls the increase of the trust-region radius when
    the reduction ratio is large. Default is ``2.0``.
decrease_radius_threshold : float, optional
    Threshold used to determine whether the trust-region radius should be
    reduced to the resolution. Default is ``1.4``.
decrease_resolution_factor : float, optional
    Factor by which the resolution is reduced when the current value is far
    from its final value. Default is ``0.1``.
large_resolution_threshold : float, optional
    Threshold used to determine whether the resolution is far from its
    final value. Default is ``250.0``.
moderate_resolution_threshold : float, optional
    Threshold used to determine whether the resolution is close to its
    final value. Default is ``16.0``.
low_ratio : float, optional
    Threshold used to determine whether the reduction ratio is low. Default
    is ``0.1``.
high_ratio : float, optional
    Threshold used to determine whether the reduction ratio is high.
    Default is ``0.7``.
very_low_ratio : float, optional
    Threshold used to determine whether the reduction ratio is very low.
    This is used to determine whether the models should be reset. Default
    is ``0.01``.
penalty_increase_threshold : float, optional
    Threshold used to determine whether the penalty parameter should be
    increased. Default is ``1.5``.
penalty_increase_factor : float, optional
    Factor by which the penalty parameter is increased. Default is ``2.0``.
short_step_threshold : float, optional
    Factor used to determine whether the trial step is too short. Default
    is ``0.5``.
low_radius_factor : float, optional
    Factor used to determine which interpolation point should be removed
    from the interpolation set at each iteration. Default is ``0.1``.
byrd_omojokun_factor : float, optional
    Factor by which the trust-region radius is reduced for the computations
    of the normal step in the Byrd-Omojokun composite-step approach.
    Default is ``0.8``.
threshold_ratio_constraints : float, optional
    Threshold used to determine which constraints should be taken into
    account when decreasing the penalty parameter. Default is ``2.0``.
large_shift_factor : float, optional
    Factor used to determine whether the point around which the quadratic
    models are built should be updated. Default is ``10.0``.
large_gradient_factor : float, optional
    Factor used to determine whether the models should be reset. Default is
    ``10.0``.
resolution_factor : float, optional
    Factor by which the resolution is decreased. Default is ``2.0``.
improve_tcg : bool, optional
    Whether to improve the steps computed by the truncated conjugate
    gradient method when the trust-region boundary is reached. Default is
    ``True``.

References
----------
.. [1] J. Nocedal and S. J. Wright. *Numerical Optimization*. Springer Ser.
   Oper. Res. Financ. Eng. Springer, New York, NY, USA, second edition,
   2006. `doi:10.1007/978-0-387-40065-5
   <https://doi.org/10.1007/978-0-387-40065-5>`_.
.. [2] M. J. D. Powell. A direct search optimization method that models the
   objective and constraint functions by linear interpolation. In S. Gomez
   and J.-P. Hennart, editors, *Advances in Optimization and Numerical
   Analysis*, volume 275 of Math. Appl., pages 51--67. Springer, Dordrecht,
   Netherlands, 1994. `doi:10.1007/978-94-015-8330-5_4
   <https://doi.org/10.1007/978-94-015-8330-5_4>`_.
.. [3] T. M. Ragonneau. *Model-Based Derivative-Free Optimization Methods
   and Software*. PhD thesis, Department of Applied Mathematics, The Hong
   Kong Polytechnic University, Hong Kong, China, 2022. URL:
   https://theses.lib.polyu.edu.hk/handle/200/12294.

Examples
--------
To demonstrate how to use `minimize`, we first minimize the Rosenbrock
function implemented in `scipy.optimize` in an unconstrained setting.

.. testsetup::

    import numpy as np
    np.set_printoptions(precision=3, suppress=True)

>>> from cobyqa import minimize
>>> from scipy.optimize import rosen

To solve the problem using COBYQA, run:

>>> x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
>>> res = minimize(rosen, x0)
>>> res.x
array([1., 1., 1., 1., 1.])

To see how bound and constraints are handled using `minimize`, we solve
Example 16.4 of [1]_, defined as

.. math::

    \begin{aligned}
        \min_{x \in \mathbb{R}^2}   & \quad (x_1 - 1)^2 + (x_2 - 2.5)^2\\
        \text{s.t.}                 & \quad -x_1 + 2x_2 \le 2,\\
                                    & \quad x_1 + 2x_2 \le 6,\\
                                    & \quad x_1 - 2x_2 \le 2,\\
                                    & \quad x_1 \ge 0,\\
                                    & \quad x_2 \ge 0.
    \end{aligned}

>>> import numpy as np
>>> from scipy.optimize import Bounds, LinearConstraint

Its objective function can be implemented as:

>>> def fun(x):
...     return (x[0] - 1.0)**2 + (x[1] - 2.5)**2

This problem can be solved using `minimize` as:

>>> x0 = [2.0, 0.0]
>>> bounds = Bounds([0.0, 0.0], np.inf)
>>> constraints = LinearConstraint([
...     [-1.0, 2.0],
...     [1.0, 2.0],
...     [1.0, -2.0],
... ], -np.inf, [2.0, 6.0, 2.0])
>>> res = minimize(fun, x0, bounds=bounds, constraints=constraints)
>>> res.x
array([1.4, 1.7])

To see how nonlinear constraints are handled, we solve Problem (F) of [2]_,
defined as

.. math::

    \begin{aligned}
        \min_{x \in \mathbb{R}^2}   & \quad -x_1 - x_2\\
        \text{s.t.}                 & \quad x_1^2 - x_2 \le 0,\\
                                    & \quad x_1^2 + x_2^2 \le 1.
    \end{aligned}

>>> from scipy.optimize import NonlinearConstraint

Its objective and constraint functions can be implemented as:

>>> def fun(x):
...     return -x[0] - x[1]
>>>
>>> def cub(x):
...     return [x[0]**2 - x[1], x[0]**2 + x[1]**2]

This problem can be solved using `minimize` as:

>>> x0 = [1.0, 1.0]
>>> constraints = NonlinearConstraint(cub, -np.inf, [0.0, 1.0])
>>> res = minimize(fun, x0, constraints=constraints)
>>> res.x
array([0.707, 0.707])

Finally, to see how to supply linear and nonlinear constraints
simultaneously, we solve Problem (G) of [2]_, defined as

.. math::

    \begin{aligned}
        \min_{x \in \mathbb{R}^3}   & \quad x_3\\
        \text{s.t.}                 & \quad 5x_1 - x_2 + x_3 \ge 0,\\
                                    & \quad -5x_1 - x_2 + x_3 \ge 0,\\
                                    & \quad x_1^2 + x_2^2 + 4x_2 \le x_3.
    \end{aligned}

Its objective and nonlinear constraint functions can be implemented as:

>>> def fun(x):
...     return x[2]
>>>
>>> def cub(x):
...     return x[0]**2 + x[1]**2 + 4.0*x[1] - x[2]

This problem can be solved using `minimize` as:

>>> x0 = [1.0, 1.0, 1.0]
>>> constraints = [
...     LinearConstraint(
...         [[5.0, -1.0, 1.0], [-5.0, -1.0, 1.0]],
...         [0.0, 0.0],
...         np.inf,
...     ),
...     NonlinearConstraint(cub, -np.inf, 0.0),
... ]
>>> res = minimize(fun, x0, constraints=constraints)
>>> res.x
array([ 0., -3., -3.])
Nz)The size of the history must be positive.z(The size of the filter must be positive.__len__        FTz$Starting the optimization procedure.zInitial trust-region radius: .zFinal trust-region radius: z(Maximum number of function evaluations: zMaximum number of iterations: g?znonlinearly constrained       @zNew trust-region radius:  )cdictgetr   VERBOSEr   boolFEASIBILITY_TOLfloatSCALESTORE_HISTORYHISTORY_SIZE
ValueErrorintFILTER_SIZEDEBUG
isinstancetupler   hasattrlenr	   _get_bounds_get_constraintsr
   r   r   _set_default_optionsn_set_default_constantsboundsis_feasible_build_resultr   INFEASIBLE_ERRORFIXED_SUCCESSprintRHOBEGRHOENDMAX_EVALMAX_ITERr   r   TARGET_SUCCESSr   CALLBACK_SUCCESSr   FEASIBLE_SUCCESSr   MAX_ITER_WARNINGnplinalgLinAlgErrorLINALG_ERRORnormx_bestmodelsinterpolationx_baser   LARGE_SHIFT_FACTORradiusshift_x_baseget_trust_region_stepSHORT_STEP_THRESHOLD
resolutionDECREASE_RESOLUTION_FACTORget_index_to_removemaxRESOLUTION_FACTORincrease_penalty_evalMAX_EVAL_WARNINGmeritfun_bestcub_bestceq_besttypeBYRD_OMOJOKUN_FACTOR get_second_order_correction_stepget_reduction_ratioupdate_interpolationset_best_indexupdate_radiusVERY_LOW_RATIOfun_gradfun_alt_gradLARGE_GRADIENT_FACTORreset_modelsset_multipliers	LOW_RATIORADIUS_SUCCESSenhance_resolutiondecrease_penaltymaxcv_print_stepbuild_xn_evalget_geometry_steppenalty)3funx0argsr4   constraintscallbackoptionskwargsverbosefeasibility_tolscalestore_historyhistory_sizefilter_sizedebugobjn_origlinear_constraintsnonlinear_constraintslinear	nonlinearpb	constants	frameworksuccessn_iterk_newn_short_stepsn_very_short_stepsn_alt_modelsstatusradius_savenormal_steptangential_stepsteps_normrk   improve_geometrydist_newsame_best_pointfun_valcub_valceq_val	merit_old	merit_newsoc_stepratioill_conditionedgradgrad_alt	maxcv_vals3   &&&&&&&,                                           T/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/_lib/cobyqa/main.pyminimizer   $   s   F w-kk'//?7??+KLG7mGkk//0O O,OKKw}}'EFEKEKK--.M 'Mw&773G3G+HA+MDEE;;,,-L |$Lg%''2E2E*F!*KCDD++++,K k"KKKw}}'EFEKE dE""w
C%
7$
7C 2y!!TWFk&&9:F 1A0M--165AF$%:GKI 


B  "$$'&00I 99   ''
 	
 
$$
 	
 45-ggnn.E-FaHI+GGNN,C+DAFG6w''(),	
 	.ww7G7G/H.IKL3
GY7	j GFEML
 WW--..00F! IINN  9#3#3#A#A#H#HH 5569I9IIJ
 ""7+  &&'0'F'Fw'O$__,% 7789;O;OOP 	)*N*N OOY111 !%&"""a'"C)"6"666)*&!.!!3!N!N7IQ7N! !%&"#( &/&C&C&EOE8 $,c$$i99:**+/ $  (88>O05!	1-GWg. &OO$$&&&&&&		 &OO$$t+Wgw	 GG88!I-		{3	 > >?3F&&''  )IIg H yy~~h/#5("8= " ) $ '	95GWg. "55	%99!((4/E&/&6&6&K&Ky//$6'O ((* ''e4 ##y';';;	)*B*B CC'($)(//889I9IJ"'0'7'7'D'D ) 0 0(H 99>>$/)%;;3IINN8435 5 ,-L'1,& ) 0 0 = = ? ,-L )))*:*:T*AB&/&C&C&EOE8
 $  	)*=*= >>   !((!)"="=>#../ !  9#7#77 - -9+>+>!??- -,, # &+"#(  ##ww~~'>>#22((1&&(HH$$i&8&8):L:L	 /	0D0D/EFJJy//0&&II   225'B,1"iw,O)'$
  55$$t+ $$&
 q
  	
%%
 	
  	
''
 	
  	
''
 	
  	
''
 	
 99   	
##
 	
	
J yy,, '44F( % '66F"G& '88F"G& '88F"G# '88FF  - "%/%>%>F&*G!. "%/%@%@F&*G!. "%/%@%@F&*G!+ "%/%@%@F!"" yy,, '44F yy,, '44F&  "yy44 "%/%<%<F!" $&99#8#8 &)3)@)@ %& yy,, '44Fh 99(( #00 ! #22" #44" #44 #44 99(( #00st  8o  r+ 
s" &u% )w( 70x 2%y >z ={ ={; |2 #0~5  )r(+r(4r(r(r(?r(r()r(r('r(+/ss"u"u"u"#u",u"u"u"!u"%w%w%w%&w%/w%w%w%$w%(/xx/yy/z
	z
/{ {/{87{8;/|/.|/2~2~2~23~2<~2~2~21~25/)()c                   V fT   \        \        P                  ! V\        P                  ) 4      \        P                  ! V\        P                  4      4      # \	        V \         4      '       dh   V P
                  P                  V38w  g   V P                  P                  V38w  d   \        RV R24      h\        V P
                  V P                  4      # \        V R4      '       dO   \        P                  ! V 4      p V P                  V^38w  d   \        R4      h\        V R,          V R,          4      # \        R4      h)z
Uniformize the bounds.
zThe bounds must have z
 elements.r   zGThe shape of the bounds is not compatible with the number of variables.zPThe bounds must be an instance of scipy.optimize.Bounds or an array-like object.)NNNr   )r      )r   rB   fullinfr+   lbshapeubr'   r-   asarray	TypeError)r4   r2   s   &&r   r/   r/   q  s     ~bgga"&&)2771bff+=>>	FF	#	#99??qd"fiioo!&=4QCzBCCfii++		#	#F#<<Aq6!+  fTlF4L11=
 	
    c                   \        V \        4      '       g   \        V R4      '       g   V 3p . p. pV  EF  p\        V\        4      '       di   \	        VP
                  R4      p\	        VP                  R4      pVP                  \        VP                  .\        P                  ! WE4      O5!  4       K  \        V\        4      '       dj   \	        VP
                  R4      p\	        VP                  R4      pVP                  \        VP                  .\        P                  ! WE4      O5!  4       EK  \        V\        4      '       d   RV9  g   VR,          R9  d   \        R4      hRV9  g   \        VR,          4      '       g   \        R	4      hVP                  RVR,          RVR,          R
VP                  R
R4      /4       EK  \!        R4      h	  W3# )z/
Extract the linear and nonlinear constraints.
r   z;The lower bound of the linear constraints must be a vector.z;The upper bound of the linear constraints must be a vector.z>The lower bound of the nonlinear constraints must be a vector.z>The upper bound of the nonlinear constraints must be a vector.r\   z+The constraint type must be "eq" or "ineq".rs   z)The constraint function must be callable.ru   zrThe constraints must be instances of scipy.optimize.LinearConstraint, scipy.optimize.NonlinearConstraint, or dict.)eqineqr   )r+   r   r-   r   r   r   r   appendArB   broadcast_arraysr   rs   r'   callabler   r   )rv   r   r   
constraintr   r   s   &     r   r0   r0     s    +t$$GK,K,K"n !
j"233MB  MB %% LL((0 
$788B  B "((#NN((0 
D))Z':f+= F , !!NOOJ&hz%7H.I.I !LMM!((:e,Jv.JNN626 ? g "p 44r   c                   \         P                  V 9   d(   V \         P                  ,          R8:  d   \        R4      h\         P                  V 9   d(   V \         P                  ,          R8  d   \        R4      h\         P                  V 9   dT   \         P                  V 9   d?   V \         P                  ,          V \         P                  ,          8  d   \        R4      hEMZ\         P                  V 9   dc   \        P
                  ! \        \         P                  ,          V \         P                  ,          .4      V \         P                  P                  &   M\         P                  V 9   dc   \        P                  ! \        \         P                  ,          V \         P                  ,          .4      V \         P                  P                  &   Ml\        \         P                  ,          V \         P                  P                  &   \        \         P                  ,          V \         P                  P                  &   \        V \         P                  ,          4      V \         P                  P                  &   \        V \         P                  ,          4      V \         P                  P                  &   \         P                  V 9   d(   V \         P                  ,          ^ 8:  d   \        R4      h\         P                  V 9   dd   V \         P                  ,          V^,           V^,           ,          ^,          8  d,   \        RV^,           V^,           ,          ^,           R24      hV P                  \         P                  P                  \        \         P                  ,          ! V4      4       \        V \         P                  ,          4      V \         P                  P                  &   \         P                  V 9   d(   V \         P                  ,          ^ 8:  d   \        R4      hV P                  \         P                  P                  \        P                  ! \        \         P                  ,          ! V4      V \         P                  ,          ^,           .4      4       \        V \         P                  ,          4      V \         P                  P                  &   \         P                  V 9   d(   V \         P                  ,          ^ 8:  d   \        R	4      hV P                  \         P                  P                  \        \         P                  ,          ! V4      4       \        V \         P                  ,          4      V \         P                  P                  &   V P                  \         P                  P                  \        \         P                  ,          4       \        V \         P                  ,          4      V \         P                  P                  &   V P                  \         P                   P                  \        \         P                   ,          4       \        V \         P                   ,          4      V \         P                   P                  &   V P                  \         P"                  P                  \        \         P"                  ,          4       \%        V \         P"                  ,          4      V \         P"                  P                  &   V P                  \         P&                  P                  \        \         P&                  ,          4       \%        V \         P&                  ,          4      V \         P&                  P                  &   V P                  \         P(                  P                  \        \         P(                  ,          4       \        V \         P(                  ,          4      V \         P(                  P                  &   V P                  \         P*                  P                  \        \         P*                  ,          4       \%        V \         P*                  ,          4      V \         P*                  P                  &   V P                  \         P,                  P                  \        \         P,                  ,          4       \        V \         P,                  ,          4      V \         P,                  P                  &   V P                  \         P.                  P                  \        \         P.                  ,          4       \%        V \         P.                  ,          4      V \         P.                  P                  &   V  FH  pV\         P0                  P3                  4       9  g   K(  \4        P6                  ! R
V R2\8        ^4       KJ  	  R# )z
Set the default options.
r   z1The initial trust-region radius must be positive.z2The final trust-region radius must be nonnegative.z_The initial trust-region radius must be greater than or equal to the final trust-region radius.z4The number of interpolation points must be positive.z3The number of interpolation points must be at most r   z<The maximum number of function evaluations must be positive.z2The maximum number of iterations must be positive.zUnknown option: N)r   r:   r'   r;   rB   minr   valuerS   r#   NPT
setdefaultr(   r<   r=   TARGETr"   r    r!   r$   r)   r%   r&   r*   __members__valueswarningswarnRuntimeWarning)rx   r2   keys   && r   r1   r1     sY    ~~ WW^^%<%CLMM~~ WW^^%<s%BMNN~~ W^^w%>7>>"WW^^%<<B  =
 
7	"(*/')
$$% 
7	"(*/')
$$% )8(G$$%(7(G$$%$)''..*A$BGGNN  !$)''..*A$BGGNN  !{{g''++"6!"; % & 	& 	wGKK QUq1u$5!#;;AQ1q5!a'(+
 	
 w{{((/'++*Fq*IJ!$WW[[%9!:GGKK7"ww/?/?'@A'EJ
 	
 
 0 01!4$q(	
 '*''2B2B*C&DGG""#7"ww/?/?'@A'EMNN(()!, '*''2B2B*C&DGG""#w~~++_W^^-LM$)''..*A$BGGNN  !%%//0 .3''(.GG##))* w,,ogoo.NO%)''//*B%CGGOO!!"w}}**OGMM,JK#'(>#?GGMM !!++, *-WW5H5H-I)JGG%%&##--. ,08M8M0N+OGG!!''("",,- +.gg6J6J.K*LGG  &&'w}}**OGMM,JK#'(>#?GGMM  g))0022MM,SE3^QG r   c                 #   \        V 4      pVP                  \        P                  P                  \
        \        P                  ,          4       \        V\        P                  ,          4      V\        P                  P                  &   V\        P                  ,          R8:  g   V\        P                  ,          R8  d   \        R4      hVP                  \        P                  P                  \
        \        P                  ,          4       \        V\        P                  ,          4      V\        P                  P                  &   V\        P                  ,          R8:  d   \        R4      h\        P                  V9   d(   V\        P                  ,          R8:  d   \        R4      h\        P                  V9   d(   V\        P                  ,          R8:  d   \        R4      h\        P                  V9   dT   \        P                  V9   d?   V\        P                  ,          V\        P                  ,          8  d   \        R4      hEMo\        P                  V9   dq   \        P                  ! \
        \        P                  ,          RRV\        P                  ,          ,           ,          .4      V\        P                  P                  &   M\        P                  V9   dj   \        P                  ! \
        \        P                  ,          R	V\        P                  ,          ,          .4      V\        P                  P                  &   Ml\
        \        P                  ,          V\        P                  P                  &   \
        \        P                  ,          V\        P                  P                  &   VP                  \        P                  P                  \
        \        P                  ,          4       \        V\        P                  ,          4      V\        P                  P                  &   V\        P                  ,          R8:  g   V\        P                  ,          R8  d   \        R
4      h\        P                  V9   d(   V\        P                  ,          R8:  d   \        R4      h\        P                   V9   d(   V\        P                   ,          R8:  d   \        R4      h\        P                  V9   dT   \        P                   V9   d?   V\        P                   ,          V\        P                  ,          8  d   \        R4      hEMZ\        P                  V9   dc   \        P                  ! \
        \        P                   ,          V\        P                  ,          .4      V\        P                   P                  &   M\        P                   V9   dc   \        P                  ! \
        \        P                  ,          V\        P                   ,          .4      V\        P                  P                  &   Ml\
        \        P                  ,          V\        P                  P                  &   \
        \        P                   ,          V\        P                   P                  &   \        P"                  V9   dD   V\        P"                  ,          R8:  g   V\        P"                  ,          R8  d   \        R4      h\        P$                  V9   dD   V\        P$                  ,          R8:  g   V\        P$                  ,          R8  d   \        R4      h\        P"                  V9   dT   \        P$                  V9   d?   V\        P"                  ,          V\        P$                  ,          8  d   \        R4      hEMZ\        P"                  V9   dc   \        P                  ! \
        \        P$                  ,          V\        P"                  ,          .4      V\        P$                  P                  &   M\        P$                  V9   dc   \        P                  ! \
        \        P"                  ,          V\        P$                  ,          .4      V\        P"                  P                  &   Ml\
        \        P"                  ,          V\        P"                  P                  &   \
        \        P$                  ,          V\        P$                  P                  &   VP                  \        P&                  P                  \
        \        P&                  ,          4       \        V\        P&                  ,          4      V\        P&                  P                  &   V\        P&                  ,          R8:  g   V\        P&                  ,          R8  d   \        R4      h\        P(                  V9   d(   V\        P(                  ,          R8  d   \        R4      h\        P*                  V9   d(   V\        P*                  ,          R8:  d   \        R4      h\        P(                  V9   dT   \        P*                  V9   d?   V\        P*                  ,          V\        P(                  ,          8  d   \        R4      hEMZ\        P(                  V9   dc   \        P                  ! \
        \        P*                  ,          V\        P(                  ,          .4      V\        P*                  P                  &   M\        P*                  V9   dc   \        P                  ! \
        \        P(                  ,          V\        P*                  ,          .4      V\        P(                  P                  &   Ml\
        \        P(                  ,          V\        P(                  P                  &   \
        \        P*                  ,          V\        P*                  P                  &   VP                  \        P,                  P                  \
        \        P,                  ,          4       \        V\        P,                  ,          4      V\        P,                  P                  &   V\        P,                  ,          R8:  g   V\        P,                  ,          R8  d   \        R4      hVP                  \        P.                  P                  \
        \        P.                  ,          4       \        V\        P.                  ,          4      V\        P.                  P                  &   V\        P.                  ,          R8:  g   V\        P.                  ,          R8  d   \        R4      hVP                  \        P0                  P                  \
        \        P0                  ,          4       \        V\        P0                  ,          4      V\        P0                  P                  &   V\        P0                  ,          R8:  g   V\        P0                  ,          R8  d   \        R4      hVP                  \        P2                  P                  \
        \        P2                  ,          4       \        V\        P2                  ,          4      V\        P2                  P                  &   V\        P2                  ,          R8:  d   \        R4      hVP                  \        P4                  P                  \
        \        P4                  ,          4       \        V\        P4                  ,          4      V\        P4                  P                  &   V\        P4                  ,          R8  d   \        R4      hVP                  \        P6                  P                  \
        \        P6                  ,          4       \        V\        P6                  ,          4      V\        P6                  P                  &   V\        P6                  ,          R8:  d   \        R4      hVP                  \        P8                  P                  \
        \        P8                  ,          4       \        V\        P8                  ,          4      V\        P8                  P                  &   V\        P8                  ,          R8:  d   \        R4      hVP                  \        P:                  P                  \
        \        P:                  ,          4       \=        V\        P:                  ,          4      V\        P:                  P                  &   V  FH  pV\        P>                  PA                  4       9  g   K(  \B        PD                  ! RV R2\F        ^4       KJ  	  V# )z
Set the default constants.
r   g      ?zCThe constant decrease_radius_factor must be in the interval (0, 1).z>The constant increase_radius_threshold must be greater than 1.z;The constant increase_radius_factor must be greater than 1.z>The constant decrease_radius_threshold must be greater than 1.zPThe constant decrease_radius_threshold must be less than increase_radius_factor.g      ?r   zGThe constant decrease_resolution_factor must be in the interval (0, 1).z?The constant large_resolution_threshold must be greater than 1.zBThe constant moderate_resolution_threshold must be greater than 1.zVThe constant moderate_resolution_threshold must be at most large_resolution_threshold.z6The constant low_ratio must be in the interval (0, 1).z7The constant high_ratio must be in the interval (0, 1).z2The constant low_ratio must be at most high_ratio.z;The constant very_low_ratio must be in the interval (0, 1).zKThe constant penalty_increase_threshold must be greater than or equal to 1.z<The constant penalty_increase_factor must be greater than 1.zaThe constant penalty_increase_factor must be greater than or equal to penalty_increase_threshold.zAThe constant short_step_threshold must be in the interval (0, 1).z>The constant low_radius_factor must be in the interval (0, 1).zAThe constant byrd_omojokun_factor must be in the interval (0, 1).z@The constant threshold_ratio_constraints must be greater than 1.z4The constant large_shift_factor must be nonnegative.z:The constant large_gradient_factor must be greater than 1.z6The constant resolution_factor must be greater than 1.zUnknown constant: r   )$r   r   r   DECREASE_RADIUS_FACTORr   r   r#   r'   INCREASE_RADIUS_THRESHOLDINCREASE_RADIUS_FACTORDECREASE_RADIUS_THRESHOLDrB   r   rS   rQ   LARGE_RESOLUTION_THRESHOLDMODERATE_RESOLUTION_THRESHOLDri   
HIGH_RATIOrc   PENALTY_INCREASE_THRESHOLDPENALTY_INCREASE_FACTORrO   LOW_RADIUS_FACTORr]   THRESHOLD_RATIO_CONSTRAINTSrK   rf   rT   IMPROVE_TCGr!   r   r   r   r   r   )ry   r   r   s   ,  r   r3   r3   7  sf    VI((..)::; 9>)2239Ii..445 	)223s:Y556#=
 	
 ++11)==> <A)556<Ii11778 445<L
 	
 	((I5i6673>I
 	
 	++y8i99:cAL
 	
 	((I5//9< i99:99:; 4 ; 
	)	)Y	6?Avv!)"E"EFsYy'G'GHHI@
	)55;;< 
	,	,		9<>FF!)"B"BCi	 C CDD=
	)22889 =N,,=
	)22889 iAAB 	)55;;<,,22)>>? =B)667=Ii22889 	)6673>Y99:cA
 	

 	,,	9i::;sBM
 	
 	//9<i==>#E
 	

 	,,	933y@ i==>	<<=> > > 
	-	-	:CE66!)"I"IJ)>>?D
	)99??@ 
	0	0I	=@B!)"F"FG)AABA
	)66<<= iBBC 	)66<<= iEEF 	)99??@ i')%%&#-Y(()S0D
 	
 y()&&'3.Y))*c1E
 	
 i'I,@,@I,MY(()Ii6J6J,KKD  L 
				)02!)"6"67)--.1
	)&&,,- 
			*/1vv!)"5"56)../0
	)%%++, 0A0
	)%%++, 1B  1
	)&&,,-   &&)223 16)**+1Ii&&,,- 	)**+s2Y--.#5I
 	
 	,,	9i::;cA*
 	

 	))Y6i778C?J
 	
 	,,	9--: i778	<<=> . > 
	-	-	:=?VV!)"C"CD)>>?>
	)3399: 
	*	*i	7@B!)"F"FG);;<A
	)66<<= iBBC 	)66<<= >O-->
	)3399: &&,,)889 7<)0017Ii,,223 	)001S8Y334;O
 	
 ##)))556 49)--.4Ii))//0 	)--.#5Y001S8L
 	
 &&,,)889 7<)0017Ii,,223 	)001S8Y334;O
 	
 --33)??@ >C)778>Ii3399: 6673>N
 	
 $$**)667 5:)../5Ii**001 --.4 ( ) 	)''--)99: 8=)1128Ii--334 001S8H
 	
 ##)))556 49)--.4Ii))//0 ,,-4D
 	
 ##)//0 .2)''(.Ii##))*
 i++2244MM.se15~qI  r   c                   V P                   V\        P                  ,          8  d   \        hVP                  V,           pV ! WAP
                  4      w  rVpV P                  WFV4      pWS\        P                  ,          8:  d"   W\        P                  ,          8:  d   \        hV P                  '       d"   W\        P                  ,          8:  d   \        hWVV3# )z2
Evaluate the objective and constraint functions.
)rp   r   r<   r   rG   rr   rm   r   r"   r   is_feasibilityr   )	r   r   r   rx   x_evalr   r   r   r_vals	   &&&&     r   rV   rV     s     
yyGG,,--$F "6+<+< =GgHHVg.E7>>**W4455	Ug.E.E&FFW$$r   c                   V P                  V4      w  rgpT;'       d5    \        P                  ! V4      ;'       d    \        P                  ! V4      pV\        P                  \        P
                  39  d$   T;'       d    W\        P                  ,          8*  p\        4       p	\        P                  R\        P                  R\        P                  R\        P                  R\        P
                  R\        P                  R\        P                  R\        P                  R\        P                  R	/	P!                  VR
4      V	n        W)n        VP&                  V	n        V P+                  V4      V	n        Wyn        Wn        V P2                  V	n        WIn        V\        P8                  ,          '       d#   V P:                  V	n        V P<                  V	n        V\        P>                  ,          '       dN   \A        V	P"                  V V	P,                  V	P.                  V	P0                  V	P4                  V	P6                  4       V	# )z/
Build the result of the optimization process.
z<The lower bound for the trust-region radius has been reachedz4The target objective function value has been reachedz0All variables are fixed by the bound constraintsz9The callback requested to stop the optimization procedurez=The feasibility problem received has been solved successfullyz<The maximum number of function evaluations has been exceededz2The maximum number of iterations has been exceededz$The bound constraints are infeasiblezA linear algebra error occurredzUnknown exit status)!	best_evalrB   isfiniter   r>   r@   r   r"   r   rj   r8   r?   rW   rA   r7   rE   r   messager   r   r   ro   xrs   rm   rp   nfevnitr%   fun_historymaxcv_historyr    rn   )
r   rr   r   r   r   rx   r   rs   rm   results
   &&&&&&    r   r6   r6     s   
 LL)MAEAA"++c*AAr{{5/AGj//1L1LMMGGew/F/F'GGF!! $=!! $2   #0## &>## &@## &E## &5##%K!B!" 
c&'(# N$ NLLFMzz!}FHJL))FKJw$$%%^^!// wNNHHJJLLKKJJ	
 Mr   c                   \        4        \        V  R24       \        RV R24       \        RV R24       VP                  '       g   \        RVP                   RV R24       \        RV R24       \        P                  ! R	/ \
        B ;_uu_ 4        \        RV R24       RRR4       R#   + '       g   i     R# ; i)
zH
Print information about the current state of the optimization process.
r   z Number of function evaluations: zNumber of iterations: zLeast value of z: zMaximum constraint violation: zCorresponding point: Nr   )r9   r   fun_namerB   printoptionsr   )r   r   r   r   r   rp   r   s   &&&&&&&r   rn   rn     s     
G	WIQ-	,VHA
67	"6(!
,-}Bwiq9:	*5'
34		)=	)	)%aS*+ 
*	)	)	)s   B00C	)r   Nr   NN)%r   numpyrB   scipy.optimizer   r   r   r   r   r   problemr   r	   r
   r   r   utilsr   r   r   r   r   settingsr   r   r   r   r   r   r   r/   r0   r1   r3   rV   r6   rn   r   r   r   <module>r      sj       #   JZ
2B5JeHPTn
%&2j,r   