
    (phy                         S r SSKrSSKJr  SSKJrJr  SSKJr  SSK	J
r
Jr  SSKJr  S/r " S	 S
5      r " S S5      r " S S5      r " S S5      r " S S5      r\" SSS9     SS j5       rg)z0
A Dual Annealing global optimization algorithm
    N)OptimizeResult)minimizeBounds)gammaln)check_random_state_transition_to_rng)new_bounds_to_olddual_annealingc                   2    \ rS rSrSrSrSrS rS rS r	Sr
g	)
VisitingDistribution   a  
Class used to generate new coordinates based on the distorted
Cauchy-Lorentz distribution. Depending on the steps within the strategy
chain, the class implements the strategy for generating new location
changes.

Parameters
----------
lb : array_like
    A 1-D NumPy ndarray containing lower bounds of the generated
    components. Neither NaN or inf are allowed.
ub : array_like
    A 1-D NumPy ndarray containing upper bounds for the generated
    components. Neither NaN or inf are allowed.
visiting_param : float
    Parameter for visiting distribution. Default value is 2.62.
    Higher values give the visiting distribution a heavier tail, this
    makes the algorithm jump to a more distant region.
    The value range is (1, 3]. Its value is fixed for the life of the
    object.
rng_gen : {`~numpy.random.Generator`}
    A `~numpy.random.Generator` object for generating new locations.
    (can be a `~numpy.random.RandomState` object until SPEC007 transition
     is fully complete).

g    חA绽|=c                    X0l         X@l        Xl        X l        X!-
  U l        [
        R                  " SU R                   -
  [
        R                  " U R                   S-
  5      -  5      U l        [
        R                  " SU R                   -
  [
        R                  " S5      -  U R                   S-
  -  5      U l	        [
        R                  " [
        R                  5      U R                  -  U R                  SU R                   -
  -  -  U l        SU R                   S-
  -  S-
  U l        SU R                  -
  U l        [
        R                  SU R                  -
  -  [
        R                  " [
        R                  SU R                  -
  -  5      -  [
        R                  " [!        U R                  5      5      -  U l        g )Ng      @      ?       @      @g      ?)_visiting_paramrng_genlowerupperbound_rangenpexplog_factor2_factor3sqrtpi
_factor4_p_factor5_d1sinr   _factor6)selflbubvisiting_paramr   s        Q/var/www/html/venv/lib/python3.13/site-packages/scipy/optimize/_dual_annealing.py__init__VisitingDistribution.__init__2   s^   
  .

7 d&:&: :bff  3&?(  ( )d&:&: :bffSkI"&"6"6"< > ?''"%%.4==8DMM$&&&=( ) t33c9:S@&t}}!45EES4==()9+ +-/VVGDHH4E-FG    c                 ,   UR                   nX$:  Ga  U R                  X45      nU R                  R                  SS9u  pgU R                  U-  XUU R                  :  '   U R                  * U-  XUU R                  * :  '   XQ-   nXR
                  -
  n	[        R                  " XR                  5      U R                  -   n
[        R                  " XR                  5      U R
                  -   nU[        R                  " XR
                  -
  5      U R                  :  ==   S-  ss'   U$ [        R                  " U5      nU R                  US5      S   nXR                  :  a(  U R                  U R                  R                  5       -  nO8XR                  * :  a(  U R                  * U R                  R                  5       -  nX$-
  nXU   -   X'   X   U R
                  U   -
  n	[        R                  " XR                  U   5      U R                  U   -   n
[        R                  " XR                  U   5      U R
                  U   -   X'   [        R                  " X   U R
                  U   -
  5      U R                  :  a  X==   U R                  -  ss'   U$ )zBased on the step in the strategy chain, new coordinates are
generated by changing all components is the same time or only
one of them, the new values are computed with visit_fn method
   sizer      r   )r/   visit_fnr   uniform
TAIL_LIMITr   r   fmodr   fabsMIN_VISIT_BOUNDcopy)r$   xsteptemperaturedimvisitsupper_samplelower_samplex_visitabvisitindexs                r(   visitingVisitingDistribution.visitingJ   sC   
 ff:]];4F)-)=)=1)=)E&L/3/MFDOO+,150@<0OFT__,,-jG**$A++,t/?/??Agga!1!12TZZ?GBGG**$&(,(<(<= >AGH >(  ggajGMM+q1!4E&$,,*>*>*@@//))(4<<+?+?+AAJE"uX-GNE!22A++E23d6F6Fu6MMAWWQ(8(8) **U+,GNwww~

)  "223$"6"66r+   c                 \   U R                   R                  US4S9R                  u  p4[        R                  " [        R
                  " U5      U R                  S-
  -  5      nU R                  U-  nU[        R                  " U R                  S-
  * [        R
                  " U R                  U-  5      -  SU R                  -
  -  5      -  n[        R                  " U R                  S-
  [        R
                  " [        R                  " U5      5      -  SU R                  -
  -  5      nX7-  $ )z,Formula Visita from p. 405 of reference [2] r-   r.   r   r   )
r   normalTr   r   r   r   r   r#   r5   )r$   r:   r;   r8   yfactor1factor4dens           r(   r1   VisitingDistribution.visit_fnp   s   ||""a"133&&,0D0Ds0JKL//G+ 	
RVVd**S01BFFMMG#5% %(+d.B.B(BD E 	E ffd**S0BFF2771:4FFD0002 3 wr+   )r!   r   r   r   r    r#   r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r3   r6   r)   rD   r1   __static_attributes__ r+   r(   r   r      s$    4 JOG0$Lr+   r   c                   <    \ rS rSrSrSrS
S jrS
S jrS rS r	S	r
g)EnergyState   a  
Class used to record the energy state. At any time, it knows what is the
currently used coordinates and the most recent best location.

Parameters
----------
lower : array_like
    A 1-D NumPy ndarray containing lower bounds for generating an initial
    random components in the `reset` method.
upper : array_like
    A 1-D NumPy ndarray containing upper bounds for generating an initial
    random components in the `reset` method
    components. Neither NaN or inf are allowed.
callback : callable, ``callback(x, f, context)``, optional
    A callback function which will be called for all minima found.
    ``x`` and ``f`` are the coordinates and function value of the
    latest minimum found, and `context` has value in [0, 1, 2]
  Nc                 `    S U l         S U l        S U l        S U l        Xl        X l        X0l        g N)ebestcurrent_energycurrent_locationxbestr   r   callback)r$   r   r   r_   s       r(   r)   EnergyState.__init__   s/    
" $


 r+   c                    Uc>  UR                  U R                  U R                  [        U R                  5      S9U l        O[
        R                  " U5      U l        SnSnU(       Ga!  UR                  U R                  5      U l        U R                  c  [        S5      e[
        R                  " U R                  5      (       dg  U[        R                  :  a  SnSn[        U5      eUR                  U R                  U R                  U R                  R                  S9U l        US-  nOSnU R                  cC  U R                  c6  U R                  U l        [
        R                  " U R                  5      U l        U(       a  GM   gg)	z~
Initialize current location is the search domain. If `x0` is not
provided, a random location within the bounds is generated.
Nr.   Tr   z$Objective function is returning NoneFznStopping algorithm because function create NaN or (+/-) infinity values even with trying new random parametersr0   )r2   r   r   lenr]   r   r7   funr\   
ValueErrorisfiniterV   MAX_REINIT_COUNTr/   r[   r^   )r$   func_wrapperr   x0
init_errorreinit_countermessages          r(   resetEnergyState.reset   sC   
 :$+OODJJ

9<TZZ %4 %JD! %'GGBKD!
"."2"243H3H"ID""* !GHH;;t2233![%A%AA!&J7 
 %W--(/

8<

=AZZ__ )8 )N% !#"
zz!djj&8!00
WWT%:%:;
- jr+   c                     Xl         [        R                  " U5      U l        U R                  b  U R	                  X!U5      nUb	  U(       a  gg g g )Nz;Callback function requested to stop early by returning True)r[   r   r7   r^   r_   )r$   er8   contextvals        r(   update_bestEnergyState.update_best   sL    
WWQZ
==$--g.C,   %r+   c                 F    Xl         [        R                  " U5      U l        g rZ   )r\   r   r7   r]   )r$   ro   r8   s      r(   update_currentEnergyState.update_current   s     "
r+   )r_   r\   r]   r[   r   r   r^   rZ   )rN   rO   rP   rQ   rR   rf   r)   rl   rr   ru   rS   rT   r+   r(   rV   rV      s$    & !"<J-+r+   rV   c                   0    \ rS rSrSrS rS rS rS rSr	g)	StrategyChain   a@  
Class that implements within a Markov chain the strategy for location
acceptance and local search decision making.

Parameters
----------
acceptance_param : float
    Parameter for acceptance distribution. It is used to control the
    probability of acceptance. The lower the acceptance parameter, the
    smaller the probability of acceptance. Default value is -5.0 with
    a range (-1e4, -5].
visit_dist : VisitingDistribution
    Instance of `VisitingDistribution` class.
func_wrapper : ObjectiveFunWrapper
    Instance of `ObjectiveFunWrapper` class.
minimizer_wrapper: LocalSearchWrapper
    Instance of `LocalSearchWrapper` class.
rand_gen : {None, int, `numpy.random.Generator`,
            `numpy.random.RandomState`}, optional

    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance then
    that instance is used.
energy_state: EnergyState
    Instance of `EnergyState` class.

c                    UR                   U l        [        R                  " UR                  5      U l        X`l        Xl        X l        X0l	        X@l
        SU l        SU l        XPl        SU l        S[        UR                  5      -  U l        g )Nr   rX   d   )r\   eminr   arrayr]   xminenergy_stateacceptance_param
visit_distrg   minimizer_wrappernot_improved_idxnot_improved_max_idx	_rand_gentemperature_steprb   K)r$   r   r   rg   r   rand_genr   s          r(   r)   StrategyChain.__init__   sx     !//	HH\::;	( 0$(!2 !$(!! !s<8899r+   c                    U R                   R                  5       nSSU R                  -
  X R                  R                  -
  -  U R
                  -  -
  nUS::  a  SnO:[        R                  " [        R                  " U5      SU R                  -
  -  5      nXF::  aJ  U R                  R                  X#5        [        R                  " U R                  R                  5      U l        U R                  U R                  :  av  US:X  d$  U R                  R                  U R                  :  aK  U R                  R                  U l        [        R                  " U R                  R                  5      U l        g g g )Nr           r   )r   r2   r   r   r\   r   r   r   r   ru   r7   r]   r~   r   r   r|   )r$   jro   r?   rpqv_temppqvs          r(   accept_rejectStrategyChain.accept_reject	  s/   NN""$3!6!66""1113595J5JK Lr>C&&)T***, -C 8,,Q8 1 1 B BCDI   D$=$==Av**99DIIE --<<	GGD$5$5$F$FG	 F >r+   c                     U[        US-   5      -  U l        U =R                  S-  sl        [        U R                  R
                  R                  S-  5       GH2  nUS:X  a  US:X  a  SU l        OSU l        U R                  R                  U R                  R
                  X25      nU R                  R                  U5      nXPR                  R                  :  am  U R                  R                  XT5        XPR                  R                  :  a8  U R                  R                  XTS5      nUb  U(       a  Us  $ SU l        SU l        OU R!                  X5U5        U R                  R"                  U R                  R$                  :  d  GM3    g   g )Nr0   r-   r   TFz8Maximum number of function call reached during annealing)floatr   r   ranger   r]   r/   energy_state_improvedr   rD   rg   rc   r\   ru   r[   rr   r   nfevmaxfun)r$   r9   r:   r   r?   ro   rq   s          r(   runStrategyChain.run  sP    +eD1Ho ="t((99>>BCAAv1915D.16D.oo..!!22ADG !!%%g.A$$333!!00<((...++77AFC#&J15D.,-D) ""11  %%):):)A)AA+1 Dr+   c                    U R                   (       a  U R                  R                  U R                  R                  U R                  R
                  5      u  pXR                  R
                  :  aJ  SU l        U R                  R                  XS5      nUb	  U(       a  U$ U R                  R                  X5        U R                  R                  U R                  R                  :  a  gSnU R                  S[        U R                  R                  5      -  :  az  [        R                   " U R                  U R                  R
                  U R                  R"                  -
  -  U R$                  -  5      nXPR&                  R)                  5       :  a  SnU R                  U R*                  :  a  SnU(       Ga   U R                  R                  U R,                  U R.                  5      u  p[        R0                  " U5      U l        Xl        SU l        U R                  R                  R2                  U l        XR                  R
                  :  aX  U R                  R                  U R.                  U R,                  S5      nUb	  U(       a  U$ U R                  R                  X5        U R                  R                  U R                  R                  :  a  gg g )	Nr   r0   z;Maximum number of function call reached during local searchFZ   Tr-   z=Maximum number of function call reached during dual annealing)r   r   local_searchr   r^   r[   r   rr   ru   rg   r   r   r   rb   r]   r   r   r\   r   r   r2   r   r~   r|   r7   r/   )r$   ro   r8   rq   do_lsplss         r(   r   StrategyChain.local_search=  sD   
 %%))66t7H7H7N7N7;7H7H7N7NPDA$$***()%''33A!<?"
!!006  %%):):)A)AA. 66BT..??@@@&&!!''$*;*;*J*JJL%%& 'C nn,,..   D$=$==E))66tyy$))LDA
DII$%D!(,(9(9(J(J(O(OD%$$***''33IItyy!-?"
!!006  %%):):)A)AA0 B r+   )r   r   r   r|   r   r   rg   r   r   r   r   r   r~   N)
rN   rO   rP   rQ   rR   r)   r   r   r   rS   rT   r+   r(   rx   rx      s    >:*H*,>.1r+   rx   c                   $    \ rS rSrSS jrS rSrg)ObjectiveFunWrapperin  c                 R    Xl         X0l        SU l        SU l        SU l        X l        g )Nr   )funcargsr   ngevnhevr   )r$   r   r   r   s       r(   r)   ObjectiveFunWrapper.__init__p  s&    					r+   c                 f    U =R                   S-  sl         U R                  " U/U R                  Q76 $ )Nr0   )r   r   r   )r$   r8   s     r(   rc   ObjectiveFunWrapper.fun{  s'    		Q	yy'TYY''r+   )r   r   r   r   r   r   N)    cA)rN   rO   rP   rQ   r)   rc   rS   rT   r+   r(   r   r   n  s    	(r+   r   c                   0    \ rS rSrSrSrSrSrS rS r	Sr
g	)
LocalSearchWrapperi  zs
Class used to wrap around the minimizer used for local search
Default local minimizer is SciPy minimizer L-BFGS-B
   r{   rX   c                 \  ^ ^ UT l         UT l        T R                  R                  SS 5      T l        T R                  R                  SS 5      T l        T R                  R                  SS 5      T l        T R                  R                  SS 5        [        T l        [        [        U6 5      n[        R                  " US   5      T l        [        R                  " US   5      T l        T R                  (       d  [        T R                  5      n[!        [#        UT R$                  -  T R&                  5      T R(                  5      nST R                  S'   S	U0T R                  S
'   [        [        T R                  T R                  5      5      T R                  S'   g [+        T R                  5      (       a  UU 4S jnUT R                  S'   [+        T R                  5      (       a  UU 4S jn	U	T R                  S'   [+        T R
                  5      (       a  UU 4S jn
U
T R                  S'   g g )Njachesshesspr   r   r0   zL-BFGS-Bmethodmaxiteroptionsboundsc                 *   > TR                   " U /TQ76 $ rZ   )r   r8   r   r$   s    r(   wrapped_jac0LocalSearchWrapper.__init__.<locals>.wrapped_jac  s    88A---r+   c                 *   > TR                   " U /TQ76 $ rZ   )r   r   s    r(   wrapped_hess1LocalSearchWrapper.__init__.<locals>.wrapped_hess  s    99Q...r+   c                 *   > TR                   " X/TQ76 $ rZ   )r   )r8   pr   r$   s     r(   wrapped_hessp2LocalSearchWrapper.__init__.<locals>.wrapped_hessp  s    ::a2T22r+   )rg   kwargsgetr   r   r   popr   	minimizerlistzipr   r}   r   r   rb   minmaxLS_MAXITER_RATIOLS_MAXITER_MINLS_MAXITER_MAXcallable)r$   search_boundsrg   r   r   bounds_listnls_max_iterr   r   r   s   `  `       r(   r)   LocalSearchWrapper.__init__  s   (;;??5$/KKOOFD1	[[__Wd3
%!3./XXk!n-
XXk!n-
 {{DJJAc!d&;&;";"&"5"57"113K %/DKK!;&DKK	" %)TZZ)D$EDKK!!!.%0E"		""/&2F#

##3'4G$ $r+   c                 @   [         R                  " U5      nU R                  " U R                  R                  U40 U R
                  D6nSU;   a)  U R                  =R                  UR                  -  sl        SU;   a)  U R                  =R                  UR                  -  sl        [         R                  " [         R                  " UR                  5      5      =(       a     [         R                  " UR                  5      n[         R                  " UR                  U R                  :  5      =(       a-    [         R                  " UR                  U R                  :*  5      nU=(       a    UnU(       a(  UR                  U:  a  UR                  UR                  4$ X#4$ )Nnjevr   )r   r7   r   rg   rc   r   r   r   r   allre   r8   r   r   )r$   r8   ro   x_tmpmres	is_finite	in_boundsis_valids           r(   r   LocalSearchWrapper.local_search  s   
~~d//33QF$++FT>""dii/"T>""dii/"FF2;;tvv./IBKK4I	FF466TZZ/0 "RVVFFdjj 6"	* 188TVV##8Or+   )rg   r   r   r   r   r   r   r   N)rN   rO   rP   rQ   rR   r   r   r   r)   r   rS   rT   r+   r(   r   r     s$    
 NN#5Jr+   r   seed
   )position_numc                 *   [        U[        5      (       a4  [        UR                  UR                  [        UR                  5      5      nUb#  [        U5      [        U5      :X  d  [        S5      e[        [        U6 5      n[        R                  " US   5      n[        R                  " US   5      nUS::  d  US:  a  [        S5      e[        R                  " [        R                  " U5      5      (       d  [        R                  " [        R                  " U5      5      (       d^  [        R                  " [        R                  " U5      5      (       d/  [        R                  " [        R                  " U5      5      (       a  [        S5      e[        R                  " UU:  5      (       d  [        S5      e[        U5      [        U5      :X  d  [        S	5      e[        X	/UQ76 nU=(       d    0 n[!        UU/UQ70 UD6n[#        U
5      n[%        UUU5      nUR'                  UUU5        XV-  n[)        UUUU5      n[+        UUUUUU5      nS
nSn/ n[-        5       nSUl        SUl        [        R2                  " US-
  [        R4                  " S5      -  5      S-
  nU(       Gd  [7        U5       H  n[9        U5      S-   n[        R2                  " US-
  [        R4                  " U5      -  5      S-
  nUU-  U-  n UU:  a  UR;                  S5        Sn  OU U:  a  UR'                  UU5          OpUR=                  UU 5      n!U!b  UR;                  U!5        SnS
Ul          O?U(       d/  UR?                  5       n!U!b  UR;                  U!5        SnS
Ul          O	US-  nM     U(       d  GM  UR@                  Ul!        URD                  Ul#        UUl$        URJ                  Ul%        URL                  Ul'        URP                  Ul(        UUl)        U$ )a  
Find the global minimum of a function using Dual Annealing.

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.
maxiter : int, optional
    The maximum number of global search iterations. Default value is 1000.
minimizer_kwargs : dict, optional
    Keyword arguments to be passed to the local minimizer
    (`minimize`). An important option could be ``method`` for the minimizer
    method to use.
    If no keyword arguments are provided, the local minimizer defaults to
    'L-BFGS-B' and uses the already supplied bounds. If `minimizer_kwargs`
    is specified, then the dict must contain all parameters required to
    control the local minimization. `args` is ignored in this dict, as it is
    passed automatically. `bounds` is not automatically passed on to the
    local minimizer as the method may not support them.
initial_temp : float, optional
    The initial temperature, use higher values to facilitates a wider
    search of the energy landscape, allowing dual_annealing to escape
    local minima that it is trapped in. Default value is 5230. Range is
    (0.01, 5.e4].
restart_temp_ratio : float, optional
    During the annealing process, temperature is decreasing, when it
    reaches ``initial_temp * restart_temp_ratio``, the reannealing process
    is triggered. Default value of the ratio is 2e-5. Range is (0, 1).
visit : float, optional
    Parameter for visiting distribution. Default value is 2.62. Higher
    values give the visiting distribution a heavier tail, this makes
    the algorithm jump to a more distant region. The value range is (1, 3].
accept : float, optional
    Parameter for acceptance distribution. It is used to control the
    probability of acceptance. The lower the acceptance parameter, the
    smaller the probability of acceptance. Default value is -5.0 with
    a range (-1e4, -5].
maxfun : int, optional
    Soft limit for the number of objective function calls. If the
    algorithm is in the middle of a local search, this number will be
    exceeded, the algorithm will stop just after the local search is
    done. Default value is 1e7.
rng : `numpy.random.Generator`, optional
    Pseudorandom number generator state. When `rng` is None, a new
    `numpy.random.Generator` is created using entropy from the
    operating system. Types other than `numpy.random.Generator` are
    passed to `numpy.random.default_rng` to instantiate a `Generator`.

    Specify `rng` for repeatable minimizations. The random numbers
    generated only affect the visiting distribution function
    and new coordinates generation.
no_local_search : bool, optional
    If `no_local_search` is set to True, a traditional Generalized
    Simulated Annealing will be performed with no local search
    strategy applied.
callback : callable, optional
    A callback function with signature ``callback(x, f, context)``,
    which will be called for all minima found.
    ``x`` and ``f`` are the coordinates and function value of the
    latest minimum found, and ``context`` has one of the following
    values:

    - ``0``: minimum detected in the annealing process.
    - ``1``: detection occurred in the local search process.
    - ``2``: detection done in the dual annealing process.

    If the callback implementation returns True, the algorithm will stop.
x0 : ndarray, shape(n,), optional
    Coordinates of a single N-D starting point.

Returns
-------
res : OptimizeResult
    The optimization result represented as a `OptimizeResult` object.
    Important attributes are: ``x`` the solution array, ``fun`` the value
    of the function at the solution, and ``message`` which describes the
    cause of the termination.
    See `OptimizeResult` for a description of other attributes.

Notes
-----
This function implements the Dual Annealing optimization. This stochastic
approach derived from [3]_ combines the generalization of CSA (Classical
Simulated Annealing) and FSA (Fast Simulated Annealing) [1]_ [2]_ coupled
to a strategy for applying a local search on accepted locations [4]_.
An alternative implementation of this same algorithm is described in [5]_
and benchmarks are presented in [6]_. This approach introduces an advanced
method to refine the solution found by the generalized annealing
process. This algorithm uses a distorted Cauchy-Lorentz visiting
distribution, with its shape controlled by the parameter :math:`q_{v}`

.. math::

    g_{q_{v}}(\Delta x(t)) \propto \frac{ \
    \left[T_{q_{v}}(t) \right]^{-\frac{D}{3-q_{v}}}}{ \
    \left[{1+(q_{v}-1)\frac{(\Delta x(t))^{2}} { \
    \left[T_{q_{v}}(t)\right]^{\frac{2}{3-q_{v}}}}}\right]^{ \
    \frac{1}{q_{v}-1}+\frac{D-1}{2}}}

Where :math:`t` is the artificial time. This visiting distribution is used
to generate a trial jump distance :math:`\Delta x(t)` of variable
:math:`x(t)` under artificial temperature :math:`T_{q_{v}}(t)`.

From the starting point, after calling the visiting distribution
function, the acceptance probability is computed as follows:

.. math::

    p_{q_{a}} = \min{\{1,\left[1-(1-q_{a}) \beta \Delta E \right]^{ \
    \frac{1}{1-q_{a}}}\}}

Where :math:`q_{a}` is a acceptance parameter. For :math:`q_{a}<1`, zero
acceptance probability is assigned to the cases where

.. math::

    [1-(1-q_{a}) \beta \Delta E] < 0

The artificial temperature :math:`T_{q_{v}}(t)` is decreased according to

.. math::

    T_{q_{v}}(t) = T_{q_{v}}(1) \frac{2^{q_{v}-1}-1}{\left( \
    1 + t\right)^{q_{v}-1}-1}

Where :math:`q_{v}` is the visiting parameter.

.. versionadded:: 1.2.0

References
----------
.. [1] Tsallis C. Possible generalization of Boltzmann-Gibbs
    statistics. Journal of Statistical Physics, 52, 479-487 (1998).
.. [2] Tsallis C, Stariolo DA. Generalized Simulated Annealing.
    Physica A, 233, 395-406 (1996).
.. [3] Xiang Y, Sun DY, Fan W, Gong XG. Generalized Simulated
    Annealing Algorithm and Its Application to the Thomson Model.
    Physics Letters A, 233, 216-220 (1997).
.. [4] Xiang Y, Gong XG. Efficiency of Generalized Simulated
    Annealing. Physical Review E, 62, 4473 (2000).
.. [5] Xiang Y, Gubian S, Suomela B, Hoeng J. Generalized
    Simulated Annealing for Efficient Global Optimization: the GenSA
    Package for R. The R Journal, Volume 5/1 (2013).
.. [6] Mullen, K. Continuous Global Optimization in R. Journal of
    Statistical Software, 60(6), 1 - 45, (2014).
    :doi:`10.18637/jss.v060.i06`

Examples
--------
The following example is a 10-D problem, with many local minima.
The function involved is called Rastrigin
(https://en.wikipedia.org/wiki/Rastrigin_function)

>>> import numpy as np
>>> from scipy.optimize import dual_annealing
>>> func = lambda x: np.sum(x*x - 10*np.cos(2*np.pi*x)) + 10*np.size(x)
>>> lw = [-5.12] * 10
>>> up = [5.12] * 10
>>> ret = dual_annealing(func, bounds=list(zip(lw, up)))
>>> ret.x
array([-4.26437714e-09, -3.91699361e-09, -1.86149218e-09, -3.97165720e-09,
       -6.29151648e-09, -6.53145322e-09, -3.93616815e-09, -6.55623025e-09,
       -6.05775280e-09, -5.00668935e-09]) # random
>>> ret.fun
0.000000

zBounds size does not match x0r   r0   r   r   z3Restart temperature ratio has to be in range (0, 1)z/Some bounds values are inf values or nan valuesz#Bounds are not consistent min < maxz&Bounds do not have the same dimensionsFTr   z#Maximum number of iteration reached)*
isinstancer   r	   r%   r&   rb   rd   r   r   r   r}   anyisinfisnanr   r   r   r   rV   rl   r   rx   r   successstatusr   r   r   r   appendr   r   r^   r8   r[   rc   nitr   r   r   r   rk   )"r   r   r   r   minimizer_kwargsinitial_temprestart_temp_ratiorB   acceptr   rngno_local_searchr_   rh   lur   r   rg   r   r   r   temperature_restartr   strategy_chainneed_to_stop	iterationrk   optimize_rest1ist2r:   rq   s"                                     r(   r
   r
     s   t &&!!"699fiiVYYH	~c"gV4899	c6l	BHHRUOEHHRUOER#5#;NOO
rxx266"((5/#:#:bffHHUO? ? "rxx 7 7JKK66%%-  >??u:U#ABB 't;d;L (-2*9#9'79 !%GueX6L|Wb1 ';%eUE7CJ"6:|#4g|MNLIG!#LLL	bffSk)	*S	0BwAa3AbffQi/036B&+b0KG#DE#00""<9 $$Q4Cs##',$"$113?NN3'#'L+0L(NI9   l@ "''LN#))L L$))L$))L$))L"Lr+   )rT   rX   Ng     n@gh㈵>g(\@g      r   NFNN)rR   numpyr   scipy.optimizer   r   r   scipy.specialr   scipy._lib._utilr   r   scipy.optimize._constraintsr	   __all__r   rV   rx   r   r   r
   rT   r+   r(   <module>r      s     ) + ! C 9
j jZP+ P+fW1 W1t( ($A AH F,267<@D9>%)	W -Wr+   