
    (ph                         S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJrJrJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  S/r  SSS.S jjr " S S5      r " S S5      r " S S5      rg)z<shgo: The simplicial homology global optimisation algorithm.    )
namedtupleN)spatial)OptimizeResultminimizeBounds)
MemoizeJac)new_bounds_to_old)standardize_constraints)_FunctionWrapper)Complexshgo   )workersc
                ~   [        U[        5      (       a4  [        UR                  UR                  [        UR                  5      5      n[        XX#UXVUXU
S9 nUR                  5         SSS5        WR                  (       d'  UR                  (       a  [        R                  " S5        [        UR                  R                  5      S:X  a  UR                  5         SUl        UR                  SUR                    3S9  UR                   UR"                  l        UR&                  UR"                  l        UR*                  UR"                  l        UR.                  UR"                  l        O UR                  (       d"  SUR"                  l        SUR"                  l        UR"                  $ ! , (       d  f       GNJ= f)	aD  
Finds the global minimum of a function using SHG optimization.

SHGO stands for "simplicial homology global optimization".

Parameters
----------
func : callable
    The objective function to be minimized.  Must be in the form
    ``f(x, *args)``, where ``x`` is the argument in the form of a 1-D array
    and ``args`` is a tuple of any additional fixed parameters needed to
    completely specify the function.
bounds : sequence or `Bounds`
    Bounds for variables. There are two ways to specify the bounds:

    1. Instance of `Bounds` class.
    2. Sequence of ``(min, max)`` pairs for each element in `x`.

args : tuple, optional
    Any additional fixed parameters needed to completely specify the
    objective function.
constraints : {Constraint, dict} or List of {Constraint, dict}, optional
    Constraints definition. Only for COBYLA, COBYQA, SLSQP and trust-constr.
    See the tutorial [5]_ for further details on specifying constraints.

    .. note::

       Only COBYLA, COBYQA, SLSQP, and trust-constr local minimize methods
       currently support constraint arguments. If the ``constraints``
       sequence used in the local optimization problem is not defined in
       ``minimizer_kwargs`` and a constrained method is used then the
       global ``constraints`` will be used.
       (Defining a ``constraints`` sequence in ``minimizer_kwargs``
       means that ``constraints`` will not be added so if equality
       constraints and so forth need to be added then the inequality
       functions in ``constraints`` need to be added to
       ``minimizer_kwargs`` too).
       COBYLA only supports inequality constraints.

    .. versionchanged:: 1.11.0

       ``constraints`` accepts `NonlinearConstraint`, `LinearConstraint`.

n : int, optional
    Number of sampling points used in the construction of the simplicial
    complex. For the default ``simplicial`` sampling method 2**dim + 1
    sampling points are generated instead of the default ``n=100``. For all
    other specified values `n` sampling points are generated. For
    ``sobol``, ``halton`` and other arbitrary `sampling_methods` ``n=100`` or
    another specified number of sampling points are generated.
iters : int, optional
    Number of iterations used in the construction of the simplicial
    complex. Default is 1.
callback : callable, optional
    Called after each iteration, as ``callback(xk)``, where ``xk`` is the
    current parameter vector.
minimizer_kwargs : dict, optional
    Extra keyword arguments to be passed to the minimizer
    ``scipy.optimize.minimize``. Some important options could be:

    method : str
        The minimization method. If not given, chosen to be one of
        BFGS, L-BFGS-B, SLSQP, depending on whether or not the
        problem has constraints or bounds.
    args : tuple
        Extra arguments passed to the objective function (``func``) and
        its derivatives (Jacobian, Hessian).
    options : dict, optional
        Note that by default the tolerance is specified as
        ``{ftol: 1e-12}``

options : dict, optional
    A dictionary of solver options. Many of the options specified for the
    global routine are also passed to the ``scipy.optimize.minimize``
    routine. The options that are also passed to the local routine are
    marked with "(L)".

    Stopping criteria, the algorithm will terminate if any of the specified
    criteria are met. However, the default algorithm does not require any
    to be specified:

    maxfev : int (L)
        Maximum number of function evaluations in the feasible domain.
        (Note only methods that support this option will terminate
        the routine at precisely exact specified value. Otherwise the
        criterion will only terminate during a global iteration)
    f_min : float
        Specify the minimum objective function value, if it is known.
    f_tol : float
        Precision goal for the value of f in the stopping
        criterion. Note that the global routine will also
        terminate if a sampling point in the global routine is
        within this tolerance.
    maxiter : int
        Maximum number of iterations to perform.
    maxev : int
        Maximum number of sampling evaluations to perform (includes
        searching in infeasible points).
    maxtime : float
        Maximum processing runtime allowed
    minhgrd : int
        Minimum homology group rank differential. The homology group of the
        objective function is calculated (approximately) during every
        iteration. The rank of this group has a one-to-one correspondence
        with the number of locally convex subdomains in the objective
        function (after adequate sampling points each of these subdomains
        contain a unique global minimum). If the difference in the hgr is 0
        between iterations for ``maxhgrd`` specified iterations the
        algorithm will terminate.

    Objective function knowledge:

    symmetry : list or bool
        Specify if the objective function contains symmetric variables.
        The search space (and therefore performance) is decreased by up to
        O(n!) times in the fully symmetric case. If `True` is specified
        then all variables will be set symmetric to the first variable.
        Default
        is set to False.

        E.g.  f(x) = (x_1 + x_2 + x_3) + (x_4)**2 + (x_5)**2 + (x_6)**2

        In this equation x_2 and x_3 are symmetric to x_1, while x_5 and
        x_6 are symmetric to x_4, this can be specified to the solver as::

            symmetry = [0,  # Variable 1
                        0,  # symmetric to variable 1
                        0,  # symmetric to variable 1
                        3,  # Variable 4
                        3,  # symmetric to variable 4
                        3,  # symmetric to variable 4
                        ]

    jac : bool or callable, optional
        Jacobian (gradient) of objective function. Only for CG, BFGS,
        Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg. If ``jac`` is a
        boolean and is True, ``fun`` is assumed to return the gradient
        along with the objective function. If False, the gradient will be
        estimated numerically. ``jac`` can also be a callable returning the
        gradient of the objective. In this case, it must accept the same
        arguments as ``fun``. (Passed to `scipy.optimize.minimize`
        automatically)

    hess, hessp : callable, optional
        Hessian (matrix of second-order derivatives) of objective function
        or Hessian of objective function times an arbitrary vector p.
        Only for Newton-CG, dogleg, trust-ncg. Only one of ``hessp`` or
        ``hess`` needs to be given. If ``hess`` is provided, then
        ``hessp`` will be ignored. If neither ``hess`` nor ``hessp`` is
        provided, then the Hessian product will be approximated using
        finite differences on ``jac``. ``hessp`` must compute the Hessian
        times an arbitrary vector. (Passed to `scipy.optimize.minimize`
        automatically)

    Algorithm settings:

    minimize_every_iter : bool
        If True then promising global sampling points will be passed to a
        local minimization routine every iteration. If True then only the
        final minimizer pool will be run. Defaults to True.

    local_iter : int
        Only evaluate a few of the best minimizer pool candidates every
        iteration. If False all potential points are passed to the local
        minimization routine.

    infty_constraints : bool
        If True then any sampling points generated which are outside will
        the feasible domain will be saved and given an objective function
        value of ``inf``. If False then these points will be discarded.
        Using this functionality could lead to higher performance with
        respect to function evaluations before the global minimum is found,
        specifying False will use less memory at the cost of a slight
        decrease in performance. Defaults to True.

    Feedback:

    disp : bool (L)
        Set to True to print convergence messages.

sampling_method : str or function, optional
    Current built in sampling method options are ``halton``, ``sobol`` and
    ``simplicial``. The default ``simplicial`` provides
    the theoretical guarantee of convergence to the global minimum in
    finite time. ``halton`` and ``sobol`` method are faster in terms of
    sampling point generation at the cost of the loss of
    guaranteed convergence. It is more appropriate for most "easier"
    problems where the convergence is relatively fast.
    User defined sampling functions must accept two arguments of ``n``
    sampling points of dimension ``dim`` per call and output an array of
    sampling points with shape `n x dim`.

workers : int or map-like callable, optional
    Sample and run the local serial minimizations in parallel.
    Supply -1 to use all available CPU cores, or an int to use
    that many Processes (uses `multiprocessing.Pool <multiprocessing>`).

    Alternatively supply a map-like callable, such as
    `multiprocessing.Pool.map` for parallel evaluation.
    This evaluation is carried out as ``workers(func, iterable)``.
    Requires that `func` be pickleable.

    .. versionadded:: 1.11.0

Returns
-------
res : OptimizeResult
    The optimization result represented as a `OptimizeResult` object.
    Important attributes are:
    ``x`` the solution array corresponding to the global minimum,
    ``fun`` the function output at the global solution,
    ``xl`` an ordered list of local minima solutions,
    ``funl`` the function output at the corresponding local solutions,
    ``success`` a Boolean flag indicating if the optimizer exited
    successfully,
    ``message`` which describes the cause of the termination,
    ``nfev`` the total number of objective function evaluations including
    the sampling calls,
    ``nlfev`` the total number of objective function evaluations
    culminating from all local search optimizations,
    ``nit`` number of iterations performed by the global routine.

Notes
-----
Global optimization using simplicial homology global optimization [1]_.
Appropriate for solving general purpose NLP and blackbox optimization
problems to global optimality (low-dimensional problems).

In general, the optimization problems are of the form::

    minimize f(x) subject to

    g_i(x) >= 0,  i = 1,...,m
    h_j(x)  = 0,  j = 1,...,p

where x is a vector of one or more variables. ``f(x)`` is the objective
function ``R^n -> R``, ``g_i(x)`` are the inequality constraints, and
``h_j(x)`` are the equality constraints.

Optionally, the lower and upper bounds for each element in x can also be
specified using the `bounds` argument.

While most of the theoretical advantages of SHGO are only proven for when
``f(x)`` is a Lipschitz smooth function, the algorithm is also proven to
converge to the global optimum for the more general case where ``f(x)`` is
non-continuous, non-convex and non-smooth, if the default sampling method
is used [1]_.

The local search method may be specified using the ``minimizer_kwargs``
parameter which is passed on to ``scipy.optimize.minimize``. By default,
the ``SLSQP`` method is used. In general, it is recommended to use the
``SLSQP``, ``COBYLA``, or ``COBYQA`` local minimization if inequality
constraints are defined for the problem since the other methods do not use
constraints.

The ``halton`` and ``sobol`` method points are generated using
`scipy.stats.qmc`. Any other QMC method could be used.

References
----------
.. [1] Endres, SC, Sandrock, C, Focke, WW (2018) "A simplicial homology
       algorithm for lipschitz optimisation", Journal of Global
       Optimization.
.. [2] Joe, SW and Kuo, FY (2008) "Constructing Sobol' sequences with
       better  two-dimensional projections", SIAM J. Sci. Comput. 30,
       2635-2654.
.. [3] Hock, W and Schittkowski, K (1981) "Test examples for nonlinear
       programming codes", Lecture Notes in Economics and Mathematical
       Systems, 187. Springer-Verlag, New York.
       http://www.ai7.uni-bayreuth.de/test_problem_coll.pdf
.. [4] Wales, DJ (2015) "Perspective: Insight into reaction coordinates and
       dynamics from the potential energy landscape",
       Journal of Chemical Physics, 142(13), 2015.
.. [5] https://docs.scipy.org/doc/scipy/tutorial/optimize.html#constrained-minimization-of-multivariate-scalar-functions-minimize

Examples
--------
First consider the problem of minimizing the Rosenbrock function, `rosen`:

>>> from scipy.optimize import rosen, shgo
>>> bounds = [(0,2), (0, 2), (0, 2), (0, 2), (0, 2)]
>>> result = shgo(rosen, bounds)
>>> result.x, result.fun
(array([1., 1., 1., 1., 1.]), 2.920392374190081e-18)

Note that bounds determine the dimensionality of the objective
function and is therefore a required input, however you can specify
empty bounds using ``None`` or objects like ``np.inf`` which will be
converted to large float numbers.

>>> bounds = [(None, None), ]*4
>>> result = shgo(rosen, bounds)
>>> result.x
array([0.99999851, 0.99999704, 0.99999411, 0.9999882 ])

Next, we consider the Eggholder function, a problem with several local
minima and one global minimum. We will demonstrate the use of arguments and
the capabilities of `shgo`.
(https://en.wikipedia.org/wiki/Test_functions_for_optimization)

>>> import numpy as np
>>> def eggholder(x):
...     return (-(x[1] + 47.0)
...             * np.sin(np.sqrt(abs(x[0]/2.0 + (x[1] + 47.0))))
...             - x[0] * np.sin(np.sqrt(abs(x[0] - (x[1] + 47.0))))
...             )
...
>>> bounds = [(-512, 512), (-512, 512)]

`shgo` has built-in low discrepancy sampling sequences. First, we will
input 64 initial sampling points of the *Sobol'* sequence:

>>> result = shgo(eggholder, bounds, n=64, sampling_method='sobol')
>>> result.x, result.fun
(array([512.        , 404.23180824]), -959.6406627208397)

`shgo` also has a return for any other local minima that was found, these
can be called using:

>>> result.xl
array([[ 512.        ,  404.23180824],
       [ 283.0759062 , -487.12565635],
       [-294.66820039, -462.01964031],
       [-105.87688911,  423.15323845],
       [-242.97926   ,  274.38030925],
       [-506.25823477,    6.3131022 ],
       [-408.71980731, -156.10116949],
       [ 150.23207937,  301.31376595],
       [  91.00920901, -391.283763  ],
       [ 202.89662724, -269.38043241],
       [ 361.66623976, -106.96493868],
       [-219.40612786, -244.06020508]])

>>> result.funl
array([-959.64066272, -718.16745962, -704.80659592, -565.99778097,
       -559.78685655, -557.36868733, -507.87385942, -493.9605115 ,
       -426.48799655, -421.15571437, -419.31194957, -410.98477763])

These results are useful in applications where there are many global minima
and the values of other global minima are desired or where the local minima
can provide insight into the system (for example morphologies
in physical chemistry [4]_).

If we want to find a larger number of local minima, we can increase the
number of sampling points or the number of iterations. We'll increase the
number of sampling points to 64 and the number of iterations from the
default of 1 to 3. Using ``simplicial`` this would have given us
64 x 3 = 192 initial sampling points.

>>> result_2 = shgo(eggholder,
...                 bounds, n=64, iters=3, sampling_method='sobol')
>>> len(result.xl), len(result_2.xl)
(12, 23)

Note the difference between, e.g., ``n=192, iters=1`` and ``n=64,
iters=3``.
In the first case the promising points contained in the minimiser pool
are processed only once. In the latter case it is processed every 64
sampling points for a total of 3 times.

To demonstrate solving problems with non-linear constraints consider the
following example from Hock and Schittkowski problem 73 (cattle-feed)
[3]_::

    minimize: f = 24.55 * x_1 + 26.75 * x_2 + 39 * x_3 + 40.50 * x_4

    subject to: 2.3 * x_1 + 5.6 * x_2 + 11.1 * x_3 + 1.3 * x_4 - 5    >= 0,

                12 * x_1 + 11.9 * x_2 + 41.8 * x_3 + 52.1 * x_4 - 21
                    -1.645 * sqrt(0.28 * x_1**2 + 0.19 * x_2**2 +
                                  20.5 * x_3**2 + 0.62 * x_4**2)      >= 0,

                x_1 + x_2 + x_3 + x_4 - 1                             == 0,

                1 >= x_i >= 0 for all i

The approximate answer given in [3]_ is::

    f([0.6355216, -0.12e-11, 0.3127019, 0.05177655]) = 29.894378

>>> def f(x):  # (cattle-feed)
...     return 24.55*x[0] + 26.75*x[1] + 39*x[2] + 40.50*x[3]
...
>>> def g1(x):
...     return 2.3*x[0] + 5.6*x[1] + 11.1*x[2] + 1.3*x[3] - 5  # >=0
...
>>> def g2(x):
...     return (12*x[0] + 11.9*x[1] +41.8*x[2] + 52.1*x[3] - 21
...             - 1.645 * np.sqrt(0.28*x[0]**2 + 0.19*x[1]**2
...                             + 20.5*x[2]**2 + 0.62*x[3]**2)
...             ) # >=0
...
>>> def h1(x):
...     return x[0] + x[1] + x[2] + x[3] - 1  # == 0
...
>>> cons = ({'type': 'ineq', 'fun': g1},
...         {'type': 'ineq', 'fun': g2},
...         {'type': 'eq', 'fun': h1})
>>> bounds = [(0, 1.0),]*4
>>> res = shgo(f, bounds, n=150, constraints=cons)
>>> res
 message: Optimization terminated successfully.
 success: True
     fun: 29.894378159142136
    funl: [ 2.989e+01]
       x: [ 6.355e-01  1.137e-13  3.127e-01  5.178e-02] # may vary
      xl: [[ 6.355e-01  1.137e-13  3.127e-01  5.178e-02]] # may vary
     nit: 1
    nfev: 142 # may vary
   nlfev: 35 # may vary
   nljev: 5
   nlhev: 0

>>> g1(res.x), g2(res.x), h1(res.x)
(-5.062616992290714e-14, -2.9594104944408173e-12, 0.0)

)	argsconstraintsniterscallbackminimizer_kwargsoptionssampling_methodr   Nz/Successfully completed construction of complex.r   TzCFailed to find a feasible minimizer point. Lowest sampling point = )mesz%Optimization terminated successfully.)
isinstancer   r	   lbublenSHGOiterate_allbreak_routinedisplogginginfoLMCxl_mapsfind_lowest_vertexfail_routinef_lowestresfunx_lowestxfnnfev	n_sampledtnevmessagesuccess)funcboundsr   r   r   r   r   r   r   r   r   shcs               G/var/www/html/venv/lib/python3.13/site-packages/scipy/optimize/_shgo.pyr   r      sK   N &&!!"699fiiVYYH
 
d! 0	
  $'
  88LLJK 377??q  	   88;~G 	HllLL	vv}} 	 A 77NE
  
 s   F--
F<c                       \ rS rSr   S$S jrS rS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rS rS%S jrS rS rS rS rS&S jrS&S jrS rS'S jrS%S jrS r S  r!S! r"S(S" jr#S#r$g))r   i  Nc           
      p  ^  SSK Jn  / SQn[        U
[        5      (       a.  X;  a)  [	        SR                  SR                  U5      5      5      e US   SL aJ  [        US   5      (       d7  [        U5      T l	        T R                  R                  nXS'   T R                  nOUT l	         [        X5      T l	        UT l        UT l        UT l        ["        R$                  " U[&        5      n["        R(                  " U5      S   T l        ["        R,                  " U5      ) nSUUS S 2S4   S4'   S	UUS S 2S
4   S
4'   US S 2S4   US S 2S
4   :  nUR/                  5       (       a%  [	        SSR                  S U 5       5       S35      eUT l        UT l        Ub  UT l        / T l        / T l        [9        U["        R:                  " T R*                  [&        5      S5      T l        T R0                   HK  nUS   S;   d  M  T R4                  R=                  US   5         T R6                  R=                  US   5        MM     [?        T R4                  5      T l        [?        T R6                  5      T l        OS T l        S T l        ST R                  0 T R                   S.T l         Ub  T R@                  RC                  U5        OSS0T R@                  S'   T R@                  S   RE                  5       S;   a  Ub	  SU;  a  Uc  T R4                  b  T R2                  T R@                  S'   U	b  T RG                  U	5        OTS T l$        ST l%        S T l&        S T l'        S T l(        S T l)        S T l$        S T l*        S T l+        ST l,        ST l-        ST l.        / SQT l/        0 S/ SQ_S / _S!/ _S"S/_S#S/_S$/ S%Q_S&SS'/_S(SS'/_S)SS*/_S+/ S,Q_S-/ S.Q_S/SS0/_S1/ S%Q_S2/ S%Q_S3SS0/_S4/ S5Q_nT R@                  S   nT =R^                  UURE                  5          -  sl/        S6 nU" T R@                  T R^                  5        U" T R@                  S   T R^                  S/-   5        ST l0        ST l1        UT l2        ST l3        UT l4        ST l5        ST l6        ST l7        ST l8        ST l9        ST l:        T Rh                  c1  T Rd                  c$  U
S7:X  a  S8T R*                  -  S
-   T l4        ST l5        T Rd                  c  S
T l2        T Rh                  c  U
S7:X  d  S9=T l4        T l4        ST l5        T Rh                  S9:X  a  U
S7:X  a  S8T R*                  -  S
-   T l4        T RL                  c4  T RN                  c'  T RP                  c  T RT                  c  T RH                  b  S T l2        [w        T R*                  T R                  T R                  ST RV                  T R0                  US:9T l<        U
S7:X  a  T Rz                  T l>        U
T l?        OU
S;;   d  [        U
[        5      (       d  T R                  T l>        U
S;;   a  U
S<:X  at  [        S8["        R                  " ["        R                  " T Rh                  5      5      -  5      T l4        ST l5        S<T l?        UR                  T R*                  SSS=9T lE        O'S>T l?        UR                  T R*                  SSS=9T lE        U 4S? jn
OS@T l?        T R                  T lH        U
T lI        ST lJ        ST lK        / T lL        [        5       T lN        [        5       T lP        ST R                  lQ        ST R                  lR        ST R                  lS        ST R                  lT        g ! [        [        4 a    UT l	         GNf = f! [         a     T R6                  R=                  S5         GM  f = f)ANr   )qmc)haltonsobol
simplicialz4Unknown sampling_method specified. Valid methods: {}z, jacTgd~Qgd~QJr   zError: lb > ub in bounds c              3   8   #    U  H  n[        U5      v   M     g 7fN)str).0bs     r6   	<genexpr> SHGO.__init__.<locals>.<genexpr>  s     )A&Q#a&&&s   .oldtypeineqr*   r    SLSQP)methodr4   r   r   ftolg-q=r   rK   )slsqpcobylacobyqatrust-constrr   F)r*   x0r   r   r   rK   _custom)r=   hesshesspr4   r   znelder-meadpowellcgbfgsz	newton-cgr=   rS   rT   zl-bfgs-br4   tncrN   catolrO   )r4   r   feasibility_tolrM   )r=   r4   r   doglegrS   z	trust-ncgztrust-krylovztrust-exactrP   )r=   rS   rT   r   c                 h    [        U 5      nU[        U5      -
   H  nU R                  US5        M     g)z8Remove keys from dictionary if not in goodkeys - inplaceN)setpop)
dictionarygoodkeysexistingkeyskeys       r6   _restrict_to_keys(SHGO.__init__.<locals>._restrict_to_keys  s,    z?L#c(m3sD) 4    r<      d   )dimdomainsfieldsfield_argssymmetryr   r   )r:   r;   r;   )dscrambleseedr:   c                 :   > TR                   R                  U 5      $ r?   )
qmc_enginerandom)r   rn   selfs     r6   r   &SHGO.__init__.<locals>.sampling_method  s    ??11!44rf   custom)Uscipy.statsr9   r   r@   
ValueErrorformatjoincallabler   r3   
derivative	TypeErrorKeyErrorr   r4   r   r   nparrayfloatshaperi   isfiniteanyr   min_consg_consg_argsr
   emptyappendtupler   updatelowerinit_options
f_min_trueminimize_every_itermaxitermaxfevmaxevmaxtimeminhgrdrm   infty_cons_sampl
local_iterr!   min_solver_argsstop_globalr    r   
iters_doner   ncn_prcr/   r-   hgrqhull_incrementalr   HCiterate_hypercubeiterate_complexr   iterate_delaunayintceillog2Sobolrr   Haltonsampling_customsamplingsampling_functionstop_l_iterstop_complex_iterminimizer_pool	LMapCacher$   r   r)   r.   nlfevnljevnlhev)rt   r3   r4   r   r   r   r   r   r   r   r   r   r9   methodsr=   aboundinfindbnderrconssolver_argsrK   rd   s   `                     r6   __init__SHGO.__init__  s    	$3os++0N 34:F499W;M4NP P
	!%(D0!"25"9::&t,	ii***-'yy 	
 %T0		  &%(88F#A& ++f%%"'vad|Q"&vad|Q 1q!t,::<<8 $		)A&)A AB!E F F  '"'DMDKDK  75) D
 ((<F+KK&&tE{3/**4<8	 )  ,DK,DKDKDK ,3+/;;,.-1]]!#
 '!!(()9: 17D!!), !!(+113 8H H !,%55'[[$37==D!!-0 g&"DO'+D$  DLDKDJDL"DODL !DM %)D!#DO DI A
H
2
 b
 5'	

 UG
 1
 )
 E8$
 }g.
 B
 5
 ufo
 1
 4
 E6?
  C!
$ &&x0FLLN ;;	* 	$//1E1EF$//	:..&9	;
 !"

!% FFN!3$4$((]Q&DFDG::DJFFN_%D!!DFTVDGFFcM< ?$((]Q&DF%DKK,?

"\\)0GDJ dhht{{!%#'==&*&6&6")	+ l*#'#9#9D #2D  3344#'#8#8D "55"g- bggbggdffo&>!>?DF  DG+2D(&)ii$((U56 '0 '8DO ,4D(&)jj488d67 '1 '9DO5
 (0$ 00DM%4D" !!& ! ; "#] 8$ 	DI	b $ /**2../s+   A]- "]- ^-^^%^54^5c                    U R                   S   R                  U5        S HB  nX R                   S   ;   d  M  U R                   S   R                  U5      U R                   U'   MD     UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        [        R                  " 5       U l	        UR                  S	S5      U l
        S
U;   a"  US
   U l        UR                  SS5      U l        OSU l        UR                  SS5      U l        UR                  SS5      U l        U R                  (       a  S/[        U R                   5      -  U l        OSU l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        g)z
Initiates the options.

Can also be useful to change parameters after class initiation.

Parameters
----------
options : dict

Returns
-------
None

r   rX   r   Tr   Nr   r   r   f_minf_tolg-C6?r   rm   Fr   r   infty_constraintsr!   )r   r   r_   getr   r   r   r   timeinitr   r   r   r   rm   r   r4   r   r   r!   )rt   r   opts      r6   r   SHGO.init_options  s   " 	i(//8 ,C++I66)))488= %%c* , $+;;/Dd#K  {{9d3kk(D1 [[$/
IIK	{{9d3g%g.DO Wd3DJ"DO{{9d3  J6==E#dkk"22DM DM "++lE: ',? F KK.	rf   c                     U $ r?   rI   rt   s    r6   	__enter__SHGO.__enter__-  s    rf   c                 \    U R                   R                  R                  R                  " U6 $ r?   )r   V_mapwrapper__exit__)rt   r   s     r6   r   SHGO.__exit__0  s!    wwyy$$--t44rf   c                    U R                   (       a  [        R                  " S5        U R                  (       dE  U R                  (       a  O3U R                  5         U R                  5         U R                  (       d  ME  U R                  (       d!  U R                  (       d  U R                  5         U R                  U R                  l        U R                  R                  R                  U l        g)z
Construct for `iters` iterations.

If uniform sampling is used, every iteration adds 'n' sampling points.

Iterations if a stopping criteria (e.g., sampling points or
processing time) has been met.

zSplitting first generationN)r!   r"   r#   r   r    iteratestopping_criteriar   find_minimar   r)   nitr   r   r.   r-   r   s    r6   r   SHGO.iterate_all5  s     99LL56""!!LLN""$ """ ''%%  "''))..rf   c                    U R                   (       a  [        R                  " S5        U R                  5         [	        U R
                  5      S:w  ab  U R                  U R                  5        U R                  5         U R                  R                  U l        U R                  R                  U l        OU R                  5         U R                   (       a$  [        R                  " SU R
                   35        gg)zt
Construct the minimizer pool, map the minimizers to local minima
and sort the results into a global return object.
zSearching for minimizer pool...r   zMinimiser pool = SHGO.X_min = N)r!   r"   r#   
minimizersr   X_minminimise_poolr   sort_resultr)   r*   r(   r,   r+   r&   r   s    r6   r   SHGO.find_minimaS  s    
 99LL:;tzz?a t/ !HHLLDM HHJJDM##%99LL9$**FG rf   c                 v   [         R                  U l        U R                  R                  R
                   H  nU R                  R                  U   R                  U R                  :  d  M6  U R                  (       a:  [        R                  " SU R                  R                  U   R                   35        U R                  R                  U   R                  U l        U R                  R                  U   R                  U l        M     U R                  R
                   Hh  nU R                  U   R                  U R                  :  d  M,  U R                  U   R                  U l        U R                  U   R                  U l        Mj     U R                  [         R                  :X  a  S U l        S U l        g g )Nzself.HC.V[x].f = )r   infr(   r   r   cachefr!   r"   r#   x_ar+   r$   r   x_l)rt   r,   lmcs      r6   r&   SHGO.find_lowest_vertexn  s    Awwyy|~~-99LL#4TWWYYq\^^4D!EF $		! $		! 0 0 ! 88>>Cxx}""T]]2 $ 3 3 $ 1 1 "
 ==BFF" DM DM #rf   c                    [        S U R                  U R                  4 5       5      nU R                  (       a&  [        R
                  " SU R                   SU 35        U R                  b!  U R                  U R                  :  a  SU l        U R                  b!  U R                  U R                  :  a  SU l        U R                  $ )Nc              3   .   #    U  H  oc  M  Uv   M     g 7fr?   rI   )rA   r,   s     r6   rC   )SHGO.finite_iterations.<locals>.<genexpr>  s     H6q6s   	zIterations done =  / T)minr   r   r!   r"   r#   r   r   )rt   mis     r6   finite_iterationsSHGO.finite_iterations  s    HTZZ6HH99LL-doo->c"FG::!4::.#' <<#4<<0#' rf   c                     U R                   (       a0  [        R                  " SU R                   SU R                   35        U R                  U R                  :  a  SU l        U R
                  $ )NzFunction evaluations done = r   T)r!   r"   r#   r-   r   r   r   s    r6   
finite_fevSHGO.finite_fev  sO    99LL7yDKK=QR77dkk!#Drf   c                     U R                   (       a0  [        R                  " SU R                   SU R                   35        U R                  U R                  :  a  SU l        g g )NzSampling evaluations done = r   T)r!   r"   r#   r/   r   r   r   s    r6   	finite_evSHGO.finite_ev  sR    99LL77G H"jj\+ ,>>TZZ'#D (rf   c                 "   U R                   (       aF  [        R                  " S[        R                  " 5       U R                  -
   SU R
                   35        [        R                  " 5       U R                  -
  U R
                  :  a  SU l        g g )NzTime elapsed = r   T)r!   r"   r#   r   r   r   r   r   s    r6   finite_timeSHGO.finite_time  sg    99LL?499;+B*C D"ll^- .IIK$))#4#D 5rf   c                    U R                  5         U R                  (       aF  [        R                  " SU R                   35        [        R                  " SU R
                   35        U R                  c  U R                  $ U R
                  S:X  a-  U R                  U R                  ::  a  SU l        U R                  $ U R                  U R
                  -
  [        U R
                  5      -  nU R                  U R
                  ::  aR  SU l        [        U5      SU R                  -  :  a/  [        R                  " SU R
                   SU R                   3SS	9  XR                  ::  a  SU l        U R                  $ )
z
Stop the algorithm if the final function value is known

Specify in options (with ``self.f_min_true = options['f_min']``)
and the tolerance with ``f_tol = options['f_tol']``
zLowest function evaluation = zSpecified minimum =         Trg   z&A much lower value than expected f* = z was found f_lowest =    )
stacklevel)r&   r!   r"   r#   r(   r   r   r   abswarningswarn)rt   pes     r6   finite_precisionSHGO.finite_precision  s0    	!99LL8HILL//@AB== ### ??c!}}

*#'   --$//1S5IIB}}/#' r7a$**n,MM@@Q R004@#$
 ZZ#' rf   c                    U R                   R                  S:X  a  gU R                   R                  U R                  -
  U l        U R                   R                  U l        U R                  U R                  ::  a  SU l        U R                  (       a1  [        R                  " SU R                   SU R                   S35        U R
                  $ )zF
Stop the algorithm if homology group rank did not grow in iteration.
r   NTzCurrent homology growth = z  (minimum growth = ))	r$   sizer   hgrdr   r   r!   r"   r#   r   s    r6   finite_homology_growthSHGO.finite_homology_growth  s     88==AHHMMDHH,	88==99$#D99LL5dii[ A//3||nA? @rf   c                    U R                   b  U R                  5         U R                  b  U R                  5         U R                  b  U R	                  5         U R
                  b  U R                  5         U R                  b  U R                  5         U R                  b  U R                  5         U R                  b  U R                  5         U R                  $ )zL
Various stopping criteria ran every iteration

Returns
-------
stop : bool
)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    r6   r   SHGO.stopping_criteria  s     <<#""$::!""$;;"OO::!NN<<#??&!!#<<#'')rf   c                     U R                  5         U R                  (       a!  U R                  (       d  U R                  5         U =R                  S-  sl        g Nr   )r   r   r    r   r   r   s    r6   r   SHGO.iterate  s>     ##%%  " 	1rf   c                    U R                   (       a  [        R                  " S5        U R                  cD  U R                  R                  5         U R                  R                  R                  5       U l        ODU R                  R                  U R                  5        U =R                  U R                  -  sl        U R                   (       a  [        R                  " S5        [        U R                  R                  5      S:  at  U R                  R                   HZ  nU R                  R                  U   nUR                  5       nUR                   H  nUR!                  UR                  5      nM      M\     U R                  R                  R#                  5         U R                   (       a  [        R                  " S5        U R                  R                  R$                  U l        g)zk
Iterate a subdivision of the complex

Note: called with ``self.iterate_complex()`` after class initiation
z<Constructing and refining simplicial complex graph structureNRTriangulation completed, evaluating all constraints and objective function values.r   Evaluations completed.)r!   r"   r#   r   r   
refine_allr   r   r/   refiner   r$   r%   r   starnnunionprocess_poolsr.   r-   )rt   xlvv_nears       r6   r   SHGO.iterate_hypercube  s2    99LL % &66>GG !WWYY^^-DNGGNN466"NNdff$N99LL : ; txx 1$hhnnGGIIbMA#\\!$$/F  %  			!99LL12 ''))..rf   c                    U =R                   U R                  -  sl         U R                  U R                  S9  U R                  (       a\  [
        R                  " SU R                   35        [
        R                  " SU R                    35        [
        R                  " S5        U R                  S:  a  [        R                  " U R                  SS9U l        U R                  R                  5       U l        / n[        U R                  5       H1  u  p#US:  d  M  UR                  U R                  US-
  US-    5        M3     [        R                  " U5      n[!        S	S
S/5      " U R                  U5      U l        0 U l        OaU R                  R&                  S   U R                  S-   :  a  U R)                  U R*                  S9  U R                  R&                  S   U l        U R                  (       a  [
        R                  " S5        [-        U S	5      (       aD  U R.                  R1                  U R"                  R$                  U R"                  R2                  5        U R                  (       a  [
        R                  " S5        U R.                  R4                  R7                  5         U R                  (       a  [
        R                  " S5        U R.                  R4                  R8                  U l        U R                   U l        g)zv
Build a complex of Delaunay triangulated points

Note: called with ``self.iterate_complex()`` after class initiation
)r   z	self.n = z
self.nc = zRConstructing and refining simplicial complex graph structure from sampling points.rg   r   axisr   Tripoints	simplices)r   r  r  N)r   r   sampled_surfacer   r!   r"   r#   ri   r   argsortC
Ind_sortedflatten	enumerater   r   r   r  r  r   delaunay_triangulationr   hasattrr   vf_to_vvr  r   r  r.   r-   r/   )rt   trisindind_ss       r6   r   SHGO.iterate_delaunay,  s    	466d.C.CD 99LL9TVVH-.LL:dggY/0LL ; < 88a< jja8DO"oo557DOD'8
7KKaa @A 9 88D>D!%(K)@A$&&$ODHDKvv||AA-++$**+=aDJ99LL F G 4GGTXX__dhh.@.@A 99LL : ; 			!99LL12 ''))..rf   c                 h   / U l         U R                  R                  R                   GH  nSn[	        U R
                  R                  5      S:  ag  U R
                  R                   HM  n[        R                  " [        R                  " U5      [        R                  " U5      :H  5      (       d  MK  SnMO     U(       a  M  U R                  R                  U   R                  5       (       d  M  U R                  (       a  [        R                  " S5        [        R                  " SU R                  R                  U   R                   S35        [        R                  " SU R                  R                  U   R                   S35        [        R                  " S5        U R                  R                  U   U R                   ;  a2  U R                   R!                  U R                  R                  U   5        U R                  (       d  GM  [        R                  " S	5        [        R                  " S5        U R                  R                  U   R"                   H3  n[        R                  " S
UR$                   SUR                   35        M5     [        R                  " S5        GM     / U l        / U l        0 U l        U R                    Hy  nU R(                  R!                  UR                  5        U R&                  R!                  UR                  5        UR$                  U R*                  [-        UR                  5      '   M{     [        R                  " U R&                  5      U l        [        R                  " U R(                  5      U l        U R/                  5         U R(                  $ )z'
Returns the indexes of all minimizers
Fr   Tz<============================================================zv.x = z is minimizerzv.f = z==============================z
Neighbors:zx = z || f = )r   r   r   r   r   r$   r%   r   allr   	minimiserr!   r"   r#   r   r   r   r  r,   minimizer_pool_Fr   X_min_cacher   sort_min_pool)rt   r,   in_LMCxlmivnr  s         r6   r   SHGO.minimizerse  sg    !AF488##$q( HH,,DvvbhhqkRXXd^;<<!% - wwyy|%%''99LL*LL6$''))A,*:*:);=!IJLL6$''))A,..)9!GHLL*7799Q<t':'::''..twwyy|<999LL.LL*"ggiilootBDD6"$$%@A . LL*3 !4 !#
$$AJJaee$!!((--.SSDU155\* %
 !#)>)> ?XXdjj)
 	zzrf   c                 v   U R                  U R                  S   U R                  S   S9nU R                  S5        U R                  (       d  U R                  5         U(       a  US-  nUS:X  a  SU l        O[        R                  " U R                  5      S   S:X  a  SU l        OU R                  UR                  U R                  5        U R                  SS2S4   nU R                  U R                  SSS24   U R                  S   5      nU R                  U5        U R                  (       d  M  SU l        g)z
This processing method can optionally minimise only the best candidate
solutions in the minimiser pool

Parameters
----------
force_iter : int
             Number of starting minimizers to process (can be specified
             globally or locally)

r   r"  r   TNF)r   r   r   trim_min_poolr   r   r   r   g_topographr,   ZSs)rt   
force_iter
lres_f_min
ind_xmin_ls       r6   r   SHGO.minimise_pool  s    ]]4::a=d6I6I!6L]M
 	1""""$ a
?'+D$xx

#A&!+#' 
 Z\\4::6 2Jtwwr1u~t7J7J27NOJ z*5 """: !rf   c                    [         R                  " U R                  5      U l        [         R                  " U R
                  5      U R                     U l        [         R                  " U R                  5      U R                     U l        g r?   )r   r  r(  	ind_f_minr   r   r   s    r6   r*  SHGO.sort_min_pool  s^    D$9$9: hht':':;DNNK ")>)> ?NN!rf   c                     [         R                  " U R                  USS9U l        [         R                  " U R                  U5      U l        [         R                  " U R                  U5      U l        g )Nr   r  )r   deleter   r(  r   )rt   trim_inds     r6   r2  SHGO.trim_min_pool  sO    YYtzz8!<
 "		$*?*? J ii(;(;XFrf   c                 j   [         R                  " U/5      n[        R                  R	                  XS5      U l        [         R                  " U R
                  SS9U l        X R                     S   U l        U R                  U R                     U l	        U R                  S   U l	        U R                  $ )z
Returns the topographical vector stemming from the specified value
``x_min`` for the current feasible set ``X_min`` with True boolean
values indicating positive entries and False values indicating
negative entries.

	euclideanr1  r  r   )
r   r   r   distancecdistYr  r4  r5  r   )rt   x_minr   s      r6   r3  SHGO.g_topograph  s     %!!!''kBDFF,-""11$&&9"11!4wwrf   c                    U R                    Vs/ s H  o"S   US   /PM     nnUR                   Hm  n[        UR                  5       HQ  u  pVXaR                  U   :  a  XcU   S   :  a  XcU   S'   XaR                  U   :  d  M=  XcU   S   :  d  MJ  XcU   S'   MS     Mo     U R                  (       a<  [
        R                  " SUR                   35        [
        R                  " SU 35        U$ s  snf )z
Construct locally (approximately) convex bounds

Parameters
----------
v_min : Vertex object
        The minimizer vertex

Returns
-------
cbounds : list of lists
    List of size dimension with length-2 list of bounds for each
    dimension.

r   r   zcbounds found for v_min.x_a = z
cbounds = )r4   r  r  r   r!   r"   r#   )rt   v_minx_b_icboundsr-  ix_is          r6   construct_lcb_simplicialSHGO.construct_lcb_simplicial  s      6:[[A[E!HeAh'[A((B#BFF+))A,&S1:a=-@$'AJqM ))A,&S1:a=-@$'AJqM ,  99LL9%))EFLL:gY/0! Bs   C0c                 V    U R                    Vs/ s H  o3S   US   /PM     nnU$ s  snf )z
Construct locally (approximately) convex bounds

Parameters
----------
v_min : Vertex object
        The minimizer vertex

Returns
-------
cbounds : list of lists
    List of size dimension with length-2 list of bounds for each
    dimension.
r   r   r4   )rt   rI  r"  rJ  rK  s        r6   construct_lcb_delaunaySHGO.construct_lcb_delaunay  s2     6:[[A[E!HeAh'[A Bs   &c                    U R                   (       a-  [        R                  " SU R                  R                   35        U R                  U   R
                  bI  [        R                  " SU R                  U   R
                   35        U R                  U   R
                  $ U R                  b  [        R                  " SU S35        U R                   (       a  [        R                  " SU S35        U R                  S:X  a  [        U5      nU R                  [        U5         n[        U5      nU R                  U R                  R                  U   5      nSU R                  ;   a1  XPR                  S'   [        R                  " U R                  S   5        OPU R                  XS	9nSU R                  ;   a1  XPR                  S'   [        R                  " U R                  S   5        U R                   (       aI  SU R                  ;   a9  [        R                  " S
5        [        R                  " U R                  S   5        [!        U R"                  U40 U R                  D6nU R                   (       a  [        R                  " SU 35        U R$                  =R&                  UR(                  -  sl        SU;   a)  U R$                  =R*                  UR,                  -  sl        SU;   a)  U R$                  =R.                  UR0                  -  sl         UR2                  S   Ul        U R                  U     U R                  R9                  XUS9  U$ ! [4        [6        4 a    UR2                     NIf = f)a<  
This function is used to calculate the local minima using the specified
sampling point as a starting value.

Parameters
----------
x_min : vector of floats
    Current starting point to minimize.

Returns
-------
lres : OptimizeResult
    The local optimization result represented as a `OptimizeResult`
    object.
zVertex minimiser maps = zFound self.LMC[x_min].lres = z#Callback for minimizer starting at :zStarting minimization at z...r<   r4   r0  zbounds in kwarg:zlres = njevnhevr   rQ  )r!   r"   r#   r$   v_mapslresr   r   r   r)  rN  r   r   r   r   rR  r   r3   r)   r   r.   r   rV  r   rW  r*   
IndexErrorr}   add_res)rt   rF  r"  x_min_tx_min_t_normg_boundsrY  s          r6   r   SHGO.minimize$  s   " 99LL3DHHOO3DEF88E?+LL8 HHUO0013 488E?'''==$LL>ugQGH99LL4UG3?@</ElG++E'N;L .L44TWWYY|5LMH4///2:%%h/T228<= 2252BH4///2:%%h/T228<=99T%:%::LL+,LL..x89 		5BD,A,AB99LL74&)* 	$))#T>HHNNdii'NT>HHNNdii'N	xx{DH
 	X6 I& 	HH	s   M M76M7c                 R   U R                   R                  5       nUS   U R                  l        US   U R                  l        US   U R                  l        US   U R                  l        U R                  U R                  R                  -   U R                  l	        U R                  $ )1
Sort results and build the global return object
r  funlr,   r*   )
r$   sort_cache_resultr)   r  rb  r,   r*   r-   r   r.   )rt   resultss     r6   r   SHGO.sort_resultp  sy    
 ((,,.dmS\
u~ $((..0xxrf   c                 d    SU l         SU R                  l        S /U l        XR                  l        g )NTF)r    r)   r2   r   r1   )rt   r   s     r6   r'   SHGO.fail_routine  s)    ! V
rf   c                    U R                   (       a  [        R                  " S5        U R                  U R                  U R
                  5        [        U R                  R                  5      S:  aO  [        R                  " U R                  [        R                  " U R                  R                  5      45      U l        U(       d  U R                  b  U R                  5         U R                  5         U R                  U l        g)ah  
Sample the function surface.

There are 2 modes, if ``infty_cons_sampl`` is True then the sampled
points that are generated outside the feasible domain will be
assigned an ``inf`` value in accordance with SHGO rules.
This guarantees convergence and usually requires less objective
function evaluations at the computational costs of more Delaunay
triangulation points.

If ``infty_cons_sampl`` is False, then the infeasible points are
discarded and only a subspace of the sampled points are used. This
comes at the cost of the loss of guaranteed convergence and usually
requires more objective function evaluations.
zGenerating sampling pointsr   N)r!   r"   r#   r   r   ri   r   r$   r%   r   vstackr  r   r   sampling_subspacesorted_samplesr/   )rt   r   s     r6   r  SHGO.sampled_surface  s    " 99LL56dggtxx(txx 1$YY1A1A(BCDDF{{&&&( 	 rf   c                    U R                   S:X  a  U R                  X5      U l        OU R                  X5      U l        [        [	        U R
                  5      5       H`  nU R                  SS2U4   U R
                  U   S   U R
                  U   S   -
  -  U R
                  U   S   -   U R                  SS2U4'   Mb     U R                  $ )z]
Generates uniform sampling points in a hypercube and scales the points
to the bound limits.
r   Nr   )r/   r   r  ranger   r4   )rt   r   ri   rL  s       r6   r   SHGO.sampling_custom  s     >>Q++A3DF++A3DFs4;;'(A FF1a4L![[^A.Q1BBD"kk!nQ/0DFF1a4L ) vvrf   c                    [        U R                  5       H  u  p[        R                  " U R                   Vs/ s H0  n[        R
                  " U" U/U R                  U   Q76 S:  5      PM2     sn[        S9nU R                  U   U l        U R                  R                  S:X  d  M  SU R                  l
        U R                  (       d  M  [        R                  " U R                  R                  5        M     gs  snf )z7Find subspace of feasible points from g_func definitionr   )dtyper   zJNo sampling point found within the feasible set. Increasing sampling size.N)r  r   r   r   r  r&  r   boolr   r)   r1   r!   r"   r#   )rt   r"  gx_Cfeasibles        r6   rj  SHGO.sampling_subspace  s      ,FC
 xxEIVVLVc#1C 01S89VLH VVH%DFvv{{a%.  999LL!1!12# - Ms   7C=
c                     [         R                  " U R                  SS9U l        U R                  U R                     U l        U R                  U R                  4$ )z*Find indexes of the sorted sampling pointsr   r  )r   r  r  r  Xsr   s    r6   rk  SHGO.sorted_samples  s?    **TVV!4&&)''rf   c                 b   [        U S5      (       aK  U R                  (       a:  U R                  R                  U R                  US 2S S 24   5        U R                  $  [
        R                  " U R                  U R                  S9U l        U R                  $ ! [
        R                   a    [        [        R                  " 5       S   5      S S S:X  aX  [        R                  " S5        SU l        [
        R                  " U R                  U R                  S9U l         U R                  $ e f = f)Nr  )incrementalr      QH6239a   QH6239 Qhull precision error detected, this usually occurs when no bounds are specified, Qhull can only run with handling cocircular/cospherical points and in this case incremental mode is switched off. The performance of shgo will be reduced in this mode.F)r  r   r  
add_pointsr  r   Delaunay
QhullErrorr@   sysexc_infor"   warning)rt   r   s     r6   r  SHGO.delaunay_triangulation  s    4D$:$: HHuvqy 12, xx)"++DFF8<8N8N.& xx! %% s||~a()"1-9OO %D E .3D*&//040F0F HDH xx s   .B BD.,D.)=r  r   r  r$   r5  r  r   r)  rx  rE  r4  r   r4   r    r   r   ri   r!   r(   r   r   r-   r3   r   r   r   r   r;  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(  r   r   r/   r   r  r   rr   r)   r   r   r   r   r   r   rm   r+   )	rI   NNNNNNr<   r   )Fr?   )zFailed to converge)r   )%__name__
__module____qualname____firstlineno__r   r   r   r   r   r   r&   r   r   r   r   r   r   r   r   r   r   r   r   r*  r2  r3  rN  rR  r   r   r'   r  r   rj  rk  r  __static_attributes__rI   rf   r6   r   r     s    BF=AEFBJ=/~5
!<H6!(  $$" H   0	-^6r0h2h& D(IX"!B$3,(rf   r   c                       \ rS rSrS rSrg)LMapi  c                 H    Xl         S U l        S U l        S U l        / U l        g r?   )r  r   rY  r   lbounds)rt   r  s     r6   r   LMap.__init__  s#    	
rf   )r   r  rY  r  r   N)r  r  r  r  r   r  rI   rf   r6   r  r    s    rf   r  c                   0    \ rS rSrS rS rSS jrS rSrg)	r   i  c                 v    0 U l         / U l        / U l        [        5       U l        / U l        / U l        SU l        g )Nr   )r   rX  r%   r^   xl_maps_setf_mapslbound_mapsr   r   s    r6   r   LMapCache.__init__  s9    
 5	rf   c                     [         R                  R                  U5      n[	        U5      n U R
                  U   $ ! [         a     N'f = f! [         a+    [        U5      nX R
                  U'   U R
                  U   s $ f = fr?   )r   ndarraytolistr}   r   r   r~   r  )rt   r  xvals      r6   __getitem__LMapCache.__getitem__  s    	

!!!$A !H	!::a= 	  		
  	!7D JJqM::a= 		!s    < A 
A	A	2B BNc                    [         R                  R                  U5      n[        U5      nUR                  U R
                  U   l        X R
                  U   l        UR                  U R
                  U   l	        X0R
                  U   l
        U =R                  S-  sl        U R                  R                  U5        U R                  R                  UR                  5        U R                  R!                  [        UR                  5      5        U R"                  R                  UR                  5        U R$                  R                  U5        g r  )r   r  r  r   r,   r   r   rY  r*   r   r  r   rX  r   r%   r  addr  r  )rt   r  rY  r4   s       r6   r[  LMapCache.add_res  s    JJa !H FF

1!

1"hh

1 &

1 			Q	 	1DFF#U466]+488$'rf   c                    0 n[         R                  " U R                  5      U l        [         R                  " U R                  5      U l        [         R                  " U R                  5      nU R                  U   US'   [         R                  " U R                  5      U l        U R                  U   US'   US   R
                  US'   U R                  US      US'   U R                  US      US'   [         R                  R                  U R                  5      U l        [         R                  R                  U R                  5      U l        U$ )ra  r  rb  r   r,   r*   )r   r   r%   r  r  Tr  r  )rt   rd  
ind_sorteds      r6   rc  LMapCache.sort_cache_result(  s     xx-hht{{+ ZZ,
 Z0hht{{+++j1!&/++ ||JqM2Z]3zz((6jj''4rf   )r   r  r  r   rX  r%   r  r?   )	r  r  r  r  r   r  r[  rc  r  rI   rf   r6   r   r     s    	!($rf   r   )rI   Nrh   r   NNNr<   )__doc__collectionsr   r   r"   r   r  numpyr   scipyr   scipy.optimizer   r   r   scipy.optimize._optimizer   scipy.optimize._constraintsr	   scipy.optimize._minimizer
   scipy._lib._utilr   !scipy.optimize._shgo_lib._complexr   __all__r   r   r  r   rI   rf   r6   <module>r     sx    B "    
   ; ; / 9 < - 5( GK9EO OdH HV  D Drf   