
    J-ju                    	   d Z ddlmZ 	 e ddlZddlmZ ddl	Z
ddlmZ ddl	mZmZmZmZmZmZmZ ddlmZ ddlmZ 	 d	 Zd
 Zd Zd Zd Zd Zdad Z da!d Z"d Z#d Z$d Z% G d de&      Z' G d de'      Z( G d de(      Z) G d de(      Z* G d de(e&      Z+ G d d e(      Z, G d! d"e(      Z- G d# d$e-e)      Z. G d% d&e-e*      Z/ G d' d(e-e+      Z0 G d) d*e-e,      Z1 G d+ d,e-e*      Z2 G d- d.e-e+      Z3 G d/ d0e-e,      Z4 G d1 d2e)      Z5 G d3 d4e)      Z6 G d5 d6e)      Z7 G d7 d8e)      Z8 G d9 d:e)      Z9 G d; d<e(      Z: G d= d>e:e)      Z; G d? d@e:e*      Z< G dA dBe:e+      Z= G dC dDe:e,      Z> G dE dFe(      Z? G dG dHe?e)      Z@ G dI dJe?e*      ZA G dK dLe?e+      ZB G dM dNe?e,      ZC G dO dPe?e*      ZD G dQ dRe?e+      ZE G dS dTe?e,      ZF G dU dVe)      ZG G dW dXe(      ZH G dY dZeHe)      ZI G d[ d\eHe*      ZJ G d] d^eHe+      ZK G d_ d`eHe,      ZL G da dbe)      ZM G dc dde)      ZN G de dfe)      ZO G dg dhe(      ZP G di djePe)      ZQ G dk dlePe*      ZR G dm dnePe+      ZS G do dpePe,      ZT G dq dre)      ZU G ds dte)      ZV G du dve(      ZW G dw dxeWe)      ZX G dy dzeWe)      ZY G d{ d|eWe*      ZZ G d} d~eWe+      Z[ G d deWe,      Z\ G d de(      Z] G d de]e)      Z^ G d de]e*      Z_ G d de]e+      Z` G d de]e,      Za G d de)      Zb G d de(      Zc G d dece)      Zd G d dece)      Ze G d dece*      Zf G d dece+      Zg G d dece,      Zh G d de)      Zi G d de)      Zje.e5e6e7e8e9e;e@eGeIeMeNeOeQeUeVeXeYe^ebedeeeiejfZke/e0e1eAeBeCe2e3e4eDeEeFe<e=e>eJeKeLeReSeTeZe[e\e_e`eaefegehfZl emd ekD              Zn eoenj                               ZqeqD  cg c]#  }  er|       dz    eren|    j                         z   % c} Zs emd elD              Zt eoetj                               Zu evek       evel      z   Zw emd ewD              Zx G d de)      ZyddZzd Z{e|dk(  rddl}Z} e}j                          yy# e$ r eZY xw xY wc c} w )a  BBOB noiseless testbed.

The optimisation test functions are represented as classes `F1` to
`F24` (and `F101` to `F130`).

This module implements the class `BBOBFunction` and
sub-classes:

* class `BBOBNfreeFunction` which have all the methods common to the
  classes `F1` to `F24`
* classes `BBOBGaussFunction`, `BBOBCauchyFunction`,
  `BBOBUniformFunction` which have methods in classes from
  `F101` to `F130`

Module attributes:

* `dictbbob` is a dictionary such that dictbbob[2] contains
  the test function class F2 and f2 = dictbbob[2]() returns
  the instance 0 of the test function that can be
  called as f2([1,2,3]).
* `nfreeIDs` == range(1,25) indices for the noiseless functions that can be
  found in dictbbob
* `noisyIDs` == range(101, 131) indices for the noisy functions that can be
  found in dictbbob. We have nfreeIDs + noisyIDs == sorted(dictbbob.keys())
* `nfreeinfos` function infos

Examples:

>>> from cma import bbobbenchmarks as bn

This does not work with ``python -OO``::

    >> for s in bn.nfreeinfos:
    ..    print(s)
    1: Noise-free Sphere function
    2: Separable ellipsoid with monotone transformation
    <BLANKLINE>
        Parameter: condition number (default 1e6)
    <BLANKLINE>
    <BLANKLINE>
    3: Rastrigin with monotone transformation separable "condition" 10
    4: skew Rastrigin-Bueche, condition 10, skew-"condition" 100
    5: Linear slope
    6: Attractive sector function
    7: Step-ellipsoid, condition 100, noise-free
    8: Rosenbrock noise-free
    9: Rosenbrock, rotated
    10: Ellipsoid with monotone transformation, condition 1e6
    11: Discus (tablet) with monotone transformation, condition 1e6
    12: Bent cigar with asymmetric space distortion, condition 1e6
    13: Sharp ridge
    14: Sum of different powers, between x^2 and x^6, noise-free
    15: Rastrigin with asymmetric non-linear distortion, "condition" 10
    16: Weierstrass, condition 100
    17: Schaffers F7 with asymmetric non-linear transformation, condition 10
    18: Schaffers F7 with asymmetric non-linear transformation, condition 1000
    19: F8F2 sum of Griewank-Rosenbrock 2-D blocks, noise-free
    20: Schwefel with tridiagonal variable transformation
    21: Gallagher with 101 Gaussian peaks, condition up to 1000, one global rotation, noise-free
    22: Gallagher with 21 Gaussian peaks, condition up to 1000, one global rotation
    23: Katsuura function
    24: Lunacek bi-Rastrigin, condition 100
    <BLANKLINE>
        in PPSN 2008, Rastrigin part rotated and scaled
    <BLANKLINE>
    <BLANKLINE>

>>> f3 = bn.F3(13)  # instantiate instance 13 of function f3
>>> float(f3([0, 1, 2])) # short-cut for f3.evaluate([0, 1, 2]) # doctest:+ELLIPSIS
59.8733529...
>>> print(bn.instantiate(5)[1])  # returns function instance and optimal f-value
51.53
>>> print(bn.nfreeIDs) # list noise-free functions
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
>>> for i in bn.nfreeIDs: # evaluate all noiseless functions once
...    print(bn.instantiate(i)[0]([0., 0., 0., 0.])) # doctest:+ELLIPSIS
-77.2745459...
6180022.8217...
92.987750752...
92.987750752...
140.51011761...
70877.955412...
-72.550520219...
33355.792472...
-339.94
4374717.4934...
15631566.348...
4715481.086...
550.59978390...
-17.299175622...
27.363312851...
-227.82783352...
-24.330591878...
131.42015934...
40.710373742...
6160.8178292...
376.74688954...
107.83042676...
220.48226655...
106.09476738...

    )print_functionN)	set_trace)floor)dotlinspacediagtilezerossignresize)standard_normal)randomc                 p    dt        j                  dt        ||       z        z  dz  dz
  }|dk(  }d||<   |S )zhGenerate a random vector used as optimum argument.

    Rounded by four digits, but never to zero.

            @   r   gh㈵)npr   unif)rseeddimxoptidxs       `/Users/jameslopez/projects/TradingBot25/.venv/lib/python3.12/site-packages/cma/bbobbenchmarks.pycompute_xoptr      sD     rxxd3..//#59D19CDIK    c                 "   t        j                  t        ||z  |       ||f      }t        |      D ][  }t        d|      D ]#  }||   t	        ||   ||         ||   z  z
  ||<   % ||   t        j
                  ||   dz        dz  z  ||<   ] |S )zReturns an orthogonal basis.r            ?)r   reshapegaussranger   sum)seedr   Bijs        r   compute_rotationr'      s     	

5sD)C:6A3Zq!AQ4#adAaD/AaD00AaD trvvadAg",-!  Hr   c           
         t        j                  |       r| dkD  rdt        j                  |       dz  } t        j                  | dt        j                  |       t        j                  d| z        z   z  z         dz  } | S | dk  rgt        j                  |        dz  } t        j                  | dt        j                  d| z        t        j                  d| z        z   z  z         dz   } | S t        j
                  |       } | j                         }| dkD  }t        j                  | |         dz  ||<   t        j                  ||   dt        j                  ||         t        j                  d||   z        z   z  z         dz  ||<   | dk  }t        j                  | |          dz  ||<   t        j                  ||   dt        j                  d||   z        t        j                  d||   z        z   z  z         dz   ||<   |S )z`Maps [-inf,inf] to [-inf,inf] with different constants
    for positive and negative part.

            皙?\(\?gHzG?g?gףp=
?r   )r   isscalarlogexpsinasarraycopy)fgr   s      r   monotoneTFoscr4      s   
 
{{1~r6q	CAq4266!9rvvdQh/?#?@@ASHA  Vr
S ADBFF4!8$4rvvdQh7G$GHHISPPAJJqMFFH1u##%###"&&#:O)O!PPQSVV#1u33&#&&3$"&&#*?"&&PQRUPVBW*W"XXY[^^^#r   c                     t        j                  dt        j                  |       dz
        t        |       z  }|t        j                  |dz  d      z  }|S )z?Returns a float penalty for being outside of boundaries [-5, 5]r)      r   )r   maximumabsr   r"   )xfacxoutsidefpens       r   defaultboundaryhandlingr>      sE    zz"bffQi!m,tAw6H!R((DKr   c                     t        d| z  |      }t        j                  dt        j                  |d|        z        t        j                  dt        j
                  z  || d| z   z        z  }t        j                  |dk(        rd||dk(  <   |S )zYSamples N standard normally distributed numbers
    being the same for a given seed

    r   Nr)   >N}a+r   )r   r   sqrtr-   cospiany)Nr#   rr3   s       r   r    r       s{    
 	QUDA
RVVAbqE]"#bffQY1QqS-A&BBA	vva2g!q&	Hr   c                 b   t        j                  |      }|dk  rd}ddgz  }|}t        ddd      D ]6  }t        |dz        }d||dz  z
  z  d|z  z
  }|d	k  r|d
z   }|dk  s2|||<   8 |d	   }t	        |       dgz  }t        t	        |             D ]T  }t        |dz        }d||dz  z
  z  d|z  z
  }|d	k  r|d
z   }t	        t        |dz              }||   }|||<   |d
z  ||<   V t        j
                  |      }|d	k(  j                         rt        j                  d       d||d	k(  <   |S )z/Generates N uniform numbers with starting seed.      ?    r)   '   r7   g    1@g    i@g     (@r   g  Ag     Azzero sampled(?), set to 1e-99rA   )	r   r9   xranger   intr0   rE   warningswarn)rF   inseedrgrandaktseedr%   tmpaktrandrG   s           r   r   r      se    VVF^F{2$YFGBBGg%&GcGm34us{BQ;+Gr6F1I   QiG 	A"ACF^Gg%&GcGm34us{BQ;+G%)+,-+s&!  	

1A	Q||~56!q&	Hr   g      >@c                     t         dz   a t         dkD  rda t        j                  t        t        j                  |       t               |       }|S )zRNormal random distribution sampling.

    For testing and comparing purpose.

    rI       eA)_randomnseedr   r   r    prodsizeress     r   _myrandnr\   (  s?      "$Lc
**U2774=,7
>CJr   c                     t         dz   a t         dkD  rda t        j                  t        t        j                  |       t               |       }|S )zSUniform random distribution sampling.

    For testing and comparing purpose.

       rV   )_randomseedr   r   r   rX   rY   s     r   _myrandr`   7  s>     /KS
**T"''$-5t
<CJr   c                     t        j                  |       }| t        j                  |t        |      z        z  }d}|d|z  z   }| |k  }	 | |   ||<   |S # t        t
        f$ r |r| }Y |S w xY w)z#Returns Gaussian model noisy value.:0yE>)\(?)r   shaper.   _randn
IndexError	TypeError)ftruebetapopsifvaltolr   s         r   fGaussrm   E  s     HHUOE266$.//D
C$*D
#+C#JS	 K 	" DKs   
A A+*A+c           	         t        j                  |       }t        |      |z  | z  t        j                  dd| dz   z  |t        |      z  z        z  }d}|d|z  z   }| |k  }	 | |   ||<   |S # t        t
        f$ r |r| }Y |S w xY w)z"Returns uniform model noisy value.rI   rV   rA   rb   rc   )r   rd   _randr8   rf   rg   )rh   alphari   rj   rk   rl   r   s          r   fUniformrq   T  s     HHUOE%LD 5(JJrC55=1uuU|7KLMND
C$*D
#+C#JS	 K 	" DKs   #A- -BBc                 F   t        j                  |       }| |t        j                  ddt        |      |k  t	        |      z  t        j
                  t	        |            dz   z  z         z  z   }d}|d|z  z   }| |k  }	 | |   ||<   |S # t        t        f$ r |r| }Y |S w xY w)zReturns Cauchy model noisy value

    Cauchy with median 1e3*alpha and with p=0.2, zero otherwise

    P(Cauchy > 1,10,100,1000) = 0.25, 0.032, 0.0032, 0.00032

    r)        @@g6rb   rc   )r   rd   r8   ro   re   r9   rf   rg   )rh   rp   prj   rk   rl   r   s          r   fCauchyru   d  s     HHUOE52::b#u1A*0-18;=66&-;PSY;Y1[ +[ \ \ \D
C$*D
#+C#JS	 K 	" DKs   ?B	 	B B c                   @    e Zd ZdZd Zd Zd Zd Zd Z e	ee      Z
y)AbstractTestFunctiona  Abstract class for test functions.

    Defines methods to be implemented in test functions which are to be
    provided to method setfun of class Logger.
    In particular, (a) the attribute fopt and (b) the method _evalfull.

    The _evalfull method returns two values, the possibly noisy value and
    the noise-free value. The latter is only meant to be for recording purpose.

    c                 $    | j                  |      S )aF  Returns the objective function value of argument x.

        Example:

            >>> from cma import bbobbenchmarks as bn
            >>> f3 = bn.F3(13) # instantiate function 3 on instance 13
            >>> bool(59.8733529 < f3([0, 1, 2]) < 59.87335292) # call f3, same as f3.evaluate([0, 1, 2])
            True

        )evaluateselfr:   s     r   __call__zAbstractTestFunction.__call__  s     }}Qr   c                 *    | j                  |      d   S )z?Returns the objective function value (in case noisy).

        r   )	_evalfullrz   s     r   ry   zAbstractTestFunction.evaluate  s     ~~a ##r   c                     t         )zEreturn noisy and noise-free value, the latter for recording purpose. )NotImplementedErrorrz   s     r   r~   zAbstractTestFunction._evalfull  s    !!r   c                 H    t        | d      st        d      | j                  S )zAReturns the best function value of this instance of the function.	iinstancez2This function class has not been instantiated yet.)hasattr	Exception_foptr{   s    r   getfoptzAbstractTestFunction.getfopt  s$     t[)PQQzzr   c                 V    	 t        |      | _        y # t        $ r t        d      w xY w)Nz4Optimal function value must be cast-able to a float.)floatr   
ValueErrorr   )r{   fopts     r   setfoptzAbstractTestFunction.setfopt  s0    	TtDJ 	TRSS	Ts    (N)__name__
__module____qualname____doc__r|   ry   r~   r   r   propertyr    r   r   rw   rw   |  s/    	 $"	T GW%Dr   rw   c                   f    e Zd ZdZddZd Zd Zd Z eee      Z	d Z
d Zd	 Zd
 Z eee      Zy)BBOBFunctionzAbstract class of BBOB test functions.

    Implements some base functions that are used by the test functions
    of BBOB such as initialisations of class attributes.

    Nc                 J   	 | j                   }	 |d|z  z   | _        || _        |rd| _        nht        dt        dt        j                  dt        d| j                        d   z  t        d| j                  dz         d   z        d	z              | _        || _        d
| _        d
| _        || _        |j%                         D ]  \  }}t'        | ||        d
| _        y
# t        $ r | j                  }Y w xY w# t        $ r  t        j                  d       d| _        Y w xY w)a  Common initialisation.

        Keyword arguments:
        iinstance -- instance of the function (int)
        zerox -- sets xopt to [0, ..., 0]
        zerof -- sets fopt to 0
        param -- parameter of the function (if applicable)
        kwargs -- additional attributes

        r   z0self.rseed could not be set, reset to 1 instead.r^   r)   i  ii'  r   d   N)rrseedAttributeErrorfunIdr   rg   rN   rO   zeroxr   minmaxr   roundr    r   r   	lastshapeparamitemssetattr_xopt)	r{   r   r   zerofr   kwargsr   r%   vs	            r   __init__zBBOBFunction.__init__  s   	 [[F	#	/1DJ 
DID#ebhhy5DJJCWXYCZ7Z]bcdfjfpfpstft]uvw]x7x.y|.  #B  CDI"
LLNDAqD!Q #
+  	 ZZF	 
  	MMLMDJ	s"   C C9 C65C69%D"!D"c                 d    t        j                  |      }t        j                  |      d   }||fS Nr7   )r   rd   )r{   r:   curshaper   s       r   shape_zBBOBFunction.shape_  s,     88A;hhqk"o}r   c                     | j                   S )a7  Designates the instance of the function class.

        An instance in this case means a given target function value, a
        given optimal argument x, and given transformations for the
        function. It needs to have a string representation. Preferably
        it should be a number or a string.

        
_iinstancer   s    r   getiinstancezBBOBFunction.getiinstance  s     r   c                     || _         y Nr   )r{   r   s     r   setiinstancezBBOBFunction.setiinstance  s	    #r   c                     dt        | j                        z  }t        | d      r|dt        | j                        z  z  }|S )zBGives a short string self representation (shorter than str(self)).zF%sr   z_p%s)strr   r   r   )r{   r[   s     r   shortstrzBBOBFunction.shortstr  s<     c$**o%4!6C

O++C
r   c                     | j                   |j                   k(  xr( t        | d       xs | j                  |j                  k(  S )Nr   )r   r   r   )r{   objs     r   __eq__zBBOBFunction.__eq__  s=    

cii' L w//J4::3J	Mr   c                     || _         y)3Return the argument of the optimum of the function.N)r   )r{   r   s     r   _setxoptzBBOBFunction._setxopt  s	    
r   c                 \    | j                   t        j                  d       | j                   S )r   z3You need to evaluate object to set dimension first.)r   rN   rO   r   s    r   _getxoptzBBOBFunction._getxopt  s#    ::MMOPzzr   )r   FFN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     sM    $L	$ |4IM  Hh'Dr   r   c                       e Zd ZdZd Zy)BBOBNfreeFunctionz*Class of the noise-free functions of BBOB.c                 "    |j                         S )z'Returns the noise-free function values.)r1   r{   rh   s     r   noisezBBOBNfreeFunction.noise=  s     zz|r   N)r   r   r   r   r   r   r   r   r   r   :  s
    4r   r   c                       e Zd ZdZd Zd Zy)BBOBGaussFunctionzuClass of the Gauss noise functions of BBOB.

    Attribute gaussbeta needs to be defined by inheriting classes.

    c                 .    t        || j                        S "Returns the noisy function values.)rm   	gaussbetar   s     r   r   zBBOBGaussFunction.noiseK  s     eT^^,,r   c                     t        |d      S N      Y@r>   rz   s     r   boundaryhandlingz"BBOBGaussFunction.boundaryhandlingP      &q$//r   Nr   r   r   r   r   r   r   r   r   r   r   B  s    -
0r   r   c                       e Zd ZdZd Zd Zy)BBOBUniformFunctionzClass of the uniform noise functions of BBOB.

    Attributes unifalphafac and unifbeta need to be defined by inheriting
    classes.

    c                 j    t        || j                  dd| j                  z  z   z  | j                        S )r   r+   rI   )rq   unifalphafacr   unifbetar   s     r   r   zBBOBUniformFunction.noise]  s/     t00D2=4HI4==YYr   c                     t        |d      S r   r   rz   s     r   r   z$BBOBUniformFunction.boundaryhandlingb  r   r   Nr   r   r   r   r   r   S  s    Z
0r   r   c                       e Zd ZdZd Zd Zy)BBOBCauchyFunctionzClass of the Cauchy noise functions of BBOB.

    Attributes cauchyalpha and cauchyp need to be defined by inheriting
    classes.

    c                 D    t        || j                  | j                        S r   )ru   cauchyalphacauchypr   s     r   r   zBBOBCauchyFunction.noiseo  s     ud..==r   c                     t        |d      S r   r   rz   s     r   r   z#BBOBCauchyFunction.boundaryhandlingt  r   r   Nr   r   r   r   r   r   e  s    >
0r   r   c                        e Zd ZdZdZd Zd Zy)_FSpherezQAbstract Sphere function.

    Method boundaryhandling needs to be defined.

    r^   c                    | j                   |k7  r8| j                  rt        |      | _        nt	        | j
                  |      | _        | j                  |k7  r*|| _         || _        t        | j                  |      | _        y y r   )	r   r   r
   r   r   r   r   r   arrxoptr{   r   r   s      r   initwithsizez_FSphere.initwithsize  sd    88s?zz!#J	(S9	 >>X%DH%DN!$))X6DL &r   c                 :   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j	                  |      z   }|| j
                  z
  }t        j                  |dz  d      }| j                  |      }||z  }||z  }||fS )Nr   r7   )	r   r   r   r   r   r   r   r"   r   r{   r:   faddr   r   rh   rk   s          r   r~   z_FSphere._evalfull  s    yyA# >>X%h, d++A..  q!tR zz%  	U{r   Nr   r   r   r   r   r   r~   r   r   r   r   r   w  s    
 F7r   r   c                       e Zd ZdZdZd Zy)F1zNoise-free Sphere functionr^   c                      yNr)   r   rz   s     r   r   zF1.boundaryhandling      r   Nr   r   r   r   r   r   r   r   r   r   r     s    $Er   r   c                       e Zd ZdZdZdZy)F101z Sphere with moderate Gauss noisee   {Gz?Nr   r   r   r   r   r   r   r   r   r   r     s    *EIr   r   c                       e Zd ZdZdZdZdZy)F102z"Sphere with moderate uniform noisef   r   Nr   r   r   r   r   r   r   r   r   r   r   r     s    ,ELHr   r   c                       e Zd ZdZdZdZdZy)F103z!Sphere with moderate Cauchy noiseg   r   皙?Nr   r   r   r   r   r   r   r   r   r   r   r     s    +EKGr   r   c                       e Zd ZdZdZdZy)F107zSphere with  Gauss noisek   rI   Nr   r   r   r   r   r     s    "EIr   r   c                       e Zd ZdZdZdZdZy)F108zSphere with uniform noisel   rI   Nr   r   r   r   r   r     s    #ELHr   r   c                       e Zd ZdZdZdZdZy)F109zSphere with Cauchy noisem   rI   皙?Nr   r   r   r   r   r     s    "EKGr   r   c                   (    e Zd ZdZdZdZdZd Zd Zy)F2zeSeparable ellipsoid with monotone transformation

    Parameter: condition number (default 1e6)

    r   )rI       .Ar  c                    | j                   |k7  r~| j                  rt        |      | _        nt	        | j
                  |      | _        t        | d      r| j                  r| j                  }n| j                  }|t        dd|      z  | _
        | j                  |k7  r*|| _         || _        t        | j                  |      | _        y y )Nr   r   r^   )r   r   r
   r   r   r   r   r   	conditionr   scalesr   r   r   )r{   r   r   rS   s       r   r   zF2.initwithsize  s    88s?zz!#J	(S9	tW%$**jjnn!Q!44DK >>X%DH%DN!$))X6DL &r   c                 $   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j                  z
  }t        t        |      dz  | j                        }| j                  |      }||z  }||z  }||fS Nr   )	r   r   r   r   r   r   r4   r  r   r   s          r   r~   zF2._evalfull  s    yyA# >>X%h,  M!$a'5zz%  	U{r   N)	r   r   r   r   r   paramValuesr  r   r~   r   r   r   r  r    s"     EKI7&r   r  c                   (    e Zd ZdZdZdZdZd Zd Zy)F3z?Rastrigin with monotone transformation separable "condition" 10         $@r  c                    | j                   |k7  rZ| j                  rt        |      | _        nt	        | j
                  |      | _        | j                  dz  t        dd|      z  | _        | j                  |k7  rn|| _         || _	        t        | j                  |      | _        t        | j                  |      | _        t        | j                  t        dd|      z  |      | _        y y )Nr   r   r^   )r   r   r
   r   r   r   r  r   r  r   r   r   	arrscalesri   arrexpor   s      r   r   zF3.initwithsize  s    88s?zz!#J	(S9	>>R/HQ34GGDK >>X%DH%DN!$))X6DL#DKK:DN!$))hq!S.A"A8LDL &r   c                 T   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j                  z
  }t        |      }|dkD  }||   d| j                  |   t        j                  ||         z  z   z  ||<   | j                  |z  }d| j                  t        j                  t        j                  dt        j                  z  |z        d      z
  z  t        j                  |dz  d      z   }| j                  |      }||z  }||z  }||fS )Nr   r^   
   r   r7   )r   r   r   r   r   r4   r  r   rB   r  r   r"   rC   rD   r   r{   r:   r   r   r   r   rh   rk   s           r   r~   zF3._evalfull  s   yyA# >>X%h,
 !1u3AS 1BGGAcFO CCD#NNQ dhhq255y1}(=r!BBCbffQRSVUWFXXzz%  	U{r   N	r   r   r   r   r   r  ri   r   r~   r   r   r   r  r    s    IEIDM"r   r  c                   D    e Zd ZdZdZdZdZej                  Z	dZ
d Zd Zy)	F4z9skew Rastrigin-Bueche, condition 10, skew-"condition" 100r   r  r   r  c                 $   | j                   |k7  r| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j                  d t        || j                        d         | j                  d t        || j                        d<   | j                  dz  t        dd|      z  | _        | j                  |k7  rE|| _         || _        t        | j                  |      | _        t        | j                  |      | _        y y )Nr   r   r   r^   )r   r   r
   r   r   r   r9   r   maxindexr  r   r  r   r   r   r  r   s      r   r   zF4.initwithsize9  s    88s?zz!#J	(S9	47		B\3sDMMCZ[\B\8]4^DII0s3.q01>>R/HQ34GGDK >>X%DH%DN!$))X6DL#DKK:DN	 &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       t	        j
                  dt	        j                  |      dz
        t        |      z  }dt	        j                  |dz  d      z  }||z   }|| j                  z
  }t        |      }	 |d d d t        | j                  | j                        df   }| j                  dz  ||dkD     z  ||dkD  <   | j                   |z  }d| j                  t	        j                  t	        j"                  dt        j$                  z  |z        d      z
  z  t	        j                  |dz  d      z   }| j'                  |      }	||z  }|	|z  }	|	|fS # t        $ r) |d t        | j                  | j                        d   }Y w xY w)	Nr)   r6   r   r   r7   r   r   r  )r   r   r   r   r   r8   r9   r   r"   r   r4   r   r   r  rf   rp   r  rC   rD   r   )
r{   r:   r   r   r   r<   r=   tmpxrh   rk   s
             r   r~   zF4._evalfullJ  s   yyA# >>X%h, ::b"&&)a-047:RVVHaK,,d{ !	6Q7TXXt}}5a778D r)DN:TAXNNQ dhhq255y1}(=r!BBCbffQRSVUWFXXzz%  	U{  	64c$((DMM2145D	6s   6*F /GGN)r   r   r   r   r   r  rp   r   infr  r   r   r~   r   r   r   r  r  0  s,    CEIEvvHF;"r   r  c                   $    e Zd ZdZdZdZd Zd Zy)F5zLinear sloper6   r   c                    | j                   |k7  r}| j                  rt        |      | _        n'dt	        t        | j                  |            z  | _        t	        | j                         | j                  dz  t        dd|      z  z  | _	        | j                  |k7  r*|| _         || _
        t        | j                  |      | _        y y )Nr6   r   r   r^   )r   r   r
   r   r   r   r   rp   r   r  r   r   r   r   s      r   r   zF5.initwithsizep  s    88s?zz!#J	\$**c%B CC			?*djjB.>8AqRUCV-VVDK >>X%DH%DN!$))X6DL &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       |dt	        j
                  t	        j                  | j                              z  z   }t	        j                  |      }|| j                  z  dkD  }t        ||         dz  ||<   t        || j                        }| j                  |      }||z  }||z  }||fS )Nr6      )r   r   r   r   r   r"   r9   r  arrayr   r   r   r   )r{   r:   r   r   r   idx_out_of_boundsrh   rk   s           r   r~   zF5._evalfull  s    yyA# >>X%h,a"&&!4555 HHQK-3#A&7$89A=

 At{{#zz%  	U{r   N)r   r   r   r   r   rp   r   r~   r   r   r   r  r  j  s    EE7r   r  c                   (    e Zd ZdZdZdZdZd Zd Zy)F6zAttractive sector function   r  r   c                 >   | j                   |k7  r| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  dz  t        dd|      z  | _
        t        t        | j
                  |      t        | j                              | _        t        | j                  | j                        | _        | j                  |k7  r*|| _         || _        t        | j                  |      | _        y y Nr  r   r   r^   r   r   r
   r   r   r   r'   rotationr  r   r  r   r   linearTFr   r   r   r   s      r   r   zF6.initwithsize      88s?zz!#J	(S9	,TZZ#-=sCDM>>R/HQ34GGDK 0S A4CTUDMt}}=DM >>X%DH%DN!$))X6DL &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j                  z
  }t        || j                        }|| j                  z  dkD  }| j                  ||   z  ||<   t        t        j                  |dz  d            dz  }| j                  |      }||z  }||z  }||fS )Nr   r   r7   g?)r   r   r   r   r   r   r,  rp   r4   r   r"   r   r  s           r   r~   zF6._evalfull  s    yyA# >>X%h, 4==! 4<<1$af$#bffQT2./25zz%  	U{r   N	r   r   r   r   r   r  rp   r   r~   r   r   r   r&  r&    s    $EIE7&r   r&  c                   (    e Zd ZdZdZdZdZd Zd Zy)_FStepEllipsoidz^Abstract Step-ellipsoid, condition 100

    Method boundaryhandling needs to be defined.

       r   r  c                    | j                   |k7  r| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  t        dd|      z  | _
        t        t        | j
                  |      t        | j                  dz  dz  t        dd|      z              | _        | j                  |k7  r*|| _         || _        t        | j                  |      | _        y y )Nr  r   r^   r  r   r*  r   s      r   r   z_FStepEllipsoid.initwithsize  s    88s?zz!#J	(S9	,TZZ#-=sCDM..HQ3,??DK 0S A $t~~';b&@XaQRTWEX%X Y[DM >>X%DH%DN!$))X6DL &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j	                  |      z   }|| j
                  z
  }t        || j                        }	 |d d df   }t        j                  |      dkD  }t        j                  ||         ||<   t        j                  | j                  ||    z        | j                  z  || <   t        || j                        }dt        j                  dt        j                  |      z  t        |dz  | j                              z  }| j!                  |      }||z  }||z  }||fS # t        $ r |d   }Y w xY w)Nr   r   r*   g-C6?r   )r   r   r   r   r   r   r   r,  rf   r   r9   r   rp   r+  r8   r  r   )	r{   r:   r   r   r   x1r   rh   rk   s	            r   r~   z_FStepEllipsoid._evalfull  sa   yyA# >>X%h, d++A.. 4==!	1a4B ffQi"n!C&!#((4::3$/04::=3$4==! RZZrvvbz 13qAvt{{3KLLzz%  	U{  	1B	s   <	E* *E;:E;N)	r   r   r   r   r   r  rp   r   r~   r   r   r   r1  r1    s"    
 FIE7$r   r1  c                       e Zd ZdZdZd Zy)F7z)Step-ellipsoid, condition 100, noise-freer2  c                     t        |d      S NrI   r   rz   s     r   r   zF7.boundaryhandling
      &q"--r   Nr   r   r   r   r7  r7    s    3E.r   r7  c                       e Zd ZdZdZdZy)F113z.Step-ellipsoid with gauss noise, condition 100q   rI   Nr   r   r   r   r<  r<    s    8EIr   r<  c                       e Zd ZdZdZdZdZy)F114z0Step-ellipsoid with uniform noise, condition 100r   rI   Nr   r   r   r   r?  r?    s    :ELHr   r?  c                       e Zd ZdZdZdZdZy)F115z/Step-ellipsoid with Cauchy noise, condition 100s   rI   r  Nr   r   r   r   rB  rB    s    9EKGr   rB  c                        e Zd ZdZdZd Zd Zy)_FRosenbrockzXAbstract Rosenbrock, non-rotated

    Method boundaryhandling needs to be defined.

    r   c                 8   | j                   |k7  rR| j                  rt        |      | _        ndt	        | j
                  |      z  | _        t        d|dz  dz        | _        | j                  |k7  r*|| _         || _        t        | j                  |      | _
        y y )Ng      ?r^   r          @)r   r   r
   r   r   r   r   r  r   r   r   r   s      r   r   z_FRosenbrock.initwithsize&  s    88s?zz!#J	,tzz3"??	aR0DK >>X%DH%DN!$))X6DL &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j	                  |      z   }|| j
                  z
  }| j                  |z  }|dz   }	 dt        j                  |d d d df   dz  |d d dd f   z
  dz  d      z  t        j                  |d d d df   dz
  dz  d      z   }| j                  |      }||z  }||z  }||fS # t        $ rI dt        j                  |d d dz  |dd  z
  dz        z  t        j                  |d d dz
  dz        z   }Y pw xY w)Nr^   r   r7   r   rI   )r   r   r   r   r   r   r  r   r"   rf   r   r   s          r   r~   z_FRosenbrock._evalfull5  si   yyA# >>X%h, d++A.. KK!OE	12661QV9>AaeH#<"BBGGVVQq#2#vY^1267E
 zz%  	U{  	12661Sb6Q;12#61"<==VVQsVb[Q./0E	1s   :AC3 3AEENr   r   r   r   rE  rE    s    
 F7r   rE  c                       e Zd ZdZdZd Zy)F8zRosenbrock noise-freer   c                      yr   r   rz   s     r   r   zF8.boundaryhandlingV  r   r   Nr   r   r   r   rJ  rJ  S  s    Er   rJ  c                       e Zd ZdZdZdZy)F104z0Rosenbrock non-rotated with moderate Gauss noiseh   r   Nr   r   r   r   rM  rM  Y  s    :EIr   rM  c                       e Zd ZdZdZdZdZy)F105z2Rosenbrock non-rotated with moderate uniform noisei   r   Nr   r   r   r   rP  rP  ^  s    <ELHr   rP  c                       e Zd ZdZdZdZdZy)F106z1Rosenbrock non-rotated with moderate Cauchy noisej   r   r   Nr   r   r   r   rS  rS  d  s    ;EKGr   rS  c                       e Zd ZdZdZdZy)F110z'Rosenbrock non-rotated with Gauss noisen   rI   Nr   r   r   r   rV  rV  j  s    1EIr   rV  c                       e Zd ZdZdZdZdZy)F111z)Rosenbrock non-rotated with uniform noiseo   rI   Nr   r   r   r   rY  rY  o  s    3ELHr   rY  c                       e Zd ZdZdZdZdZy)F112z(Rosenbrock non-rotated with Cauchy noisep   rI   r  Nr   r   r   r   r\  r\  u  s    2EKGr   r\  c                        e Zd ZdZdZd Zd Zy)F9zRosenbrock, rotated	   c           	      :   | j                   |k7  r| j                  r&t        |      | _        t	        j
                  d       nt        | j                  |      | _        t        d|dz  dz        }|t        | j                  |      z  | _
        t        j                  t        dt        j                  d|f      z  | j                  j                              |dz  z  | _        | j                   |k7  r*|| _         || _        t#        | j                  |      | _        y y )Nz(F9 does not feature setting xopt to zeror^   r   rG  r   )r   r   r
   r   rN   rO   r   r   r   r'   r,  r   hstackr   onesTr   r   r   r{   r   r   scales       r   r   zF9.initwithsize  s    88s?zz!#J	HI(S9	3"9r>*E!$4TZZ$EEDM		#b277As8+<&<dmmoo"NORW[\R\\DI >>X%DH%DN!$))X6DL &r   c                 T   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       t	        || j
                        dz   }	 dt        j                  |d d d df   dz  |d d dd f   z
  dz  d      z  t        j                  |d d d df   dz
  dz  d      z   }| j                  |      }||z  }||z  }||fS # t        $ rI dt        j                  |d d dz  |dd  z
  dz        z  t        j                  |d d dz
  dz        z   }Y pw xY w)Nr   r   r7   r   r^   rI   )
r   r   r   r   r   r,  r   r"   rf   r   r   s          r   r~   zF9._evalfull  sC   yyA# >>X%h,
 4==!C'	12661QV9>AaeH#<"BBGGVVQq#2#vY^1267E
 zz%  	U{  	12661Sb6Q;12#61"<==VVQsVb[Q./0E	1s   AC AD'&D'Nr   r   r   r   r   r   r~   r   r   r   r_  r_  {  s    E7$r   r_  c                   $    e Zd ZdZdZdZd Zd Zy)_FEllipsoidzhAbstract Ellipsoid with monotone transformation.

    Method boundaryhandling needs to be defined.

    r  r  c                 ~   | j                   |k7  ru| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  t        dd|      z  | _
        | j                  |k7  r*|| _         || _        t        | j                  |      | _        y y Nr  r   r^   )r   r   r
   r   r   r   r'   r+  r  r   r  r   r   r   r   s      r   r   z_FEllipsoid.initwithsize  s    88s?zz!#J	(S9	,TZZ#-=sCDM..HQ3,??DK >>X%DH%DN!$))X6DL &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j	                  |      z   }|| j
                  z
  }t        || j                        }t        |      }t        |dz  | j                        }	 t        j                  |      }| j                  |      }||z  }||z  }||fS # t        $ r Y *w xY wr
  )r   r   r   r   r   r   r   r+  r4   r  r   rb  rg   r   r   s          r   r~   z_FEllipsoid._evalfull  s    yyA# >>X%h, d++A.. 4==!! AFDKK(	IIe$E zz%  	U{  		s    C 	C C N)r   r   r   r   r   r  r   r~   r   r   r   rj  rj    s    
 FI7 r   rj  c                       e Zd ZdZdZdZd Zy)F10z5Ellipsoid with monotone transformation, condition 1e6r  r  c                      yr   r   rz   s     r   r   zF10.boundaryhandling  r   r   Nr   r   r   r   r   r  r   r   r   r   ro  ro    s    ?EIr   ro  c                       e Zd ZdZdZdZdZy)F116zDEllipsoid with Gauss noise, monotone x-transformation, condition 1e4t   r   rI   Nr   r   r   r   r   r  r   r   r   r   rs  rs    s    NEIIr   rs  c                        e Zd ZdZdZdZdZdZy)F117zFEllipsoid with uniform noise, monotone x-transformation, condition 1e4u   r   rI   Nr   r   r   r   r   r  r   r   r   r   r   rw  rw    s    PEILHr   rw  c                        e Zd ZdZdZdZdZdZy)F118zEEllipsoid with Cauchy noise, monotone x-transformation, condition 1e4v   r   rI   r  Nr   r   r   r   r   r  r   r   r   r   r   r{  r{    s    OEIKGr   r{  c                   $    e Zd ZdZdZdZd Zd Zy)F11z;Discus (tablet) with monotone transformation, condition 1e6   r  c                 @   | j                   |k7  rV| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  |k7  r*|| _         || _        t        | j                  |      | _
        y y )Nr  )r   r   r
   r   r   r   r'   r+  r   r   r   r   s      r   r   zF11.initwithsize  s{    88s?zz!#J	(S9	,TZZ#-=sCDM >>X%DH%DN!$))X6DL &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j                  z
  }t        || j                        }t        |      }	 t        j                  |dz  d      | j                  dz
  |d d df   dz  z  z   }| j                  |      }||z  }||z  }||fS # t        $ r4 t        j                  |dz        | j                  dz
  |d   dz  z  z   }Y [w xY w)Nr   r7   rI   r   )r   r   r   r   r   r   r+  r4   r   r"   r  rf   r   r   s          r   r~   zF11._evalfull  s
   yyA# >>X%h,
 4==!!	EFF1a4$(;qAw!|'KKE zz%  	U{  	EFF1a4LDNNR$71Q419#DDE	Es   36C :DDNr   r   r   r   r   r  r   r~   r   r   r   r  r    s    EEI7r   r  c                   (    e Zd ZdZdZdZdZd Zd Zy)F12z:Bent cigar with asymmetric space distortion, condition 1e6   r  r   c                    | j                   |k7  rY| j                  rt        |      | _        nt	        | j
                  dz   |      | _        t        | j
                  dz   |      | _        | j                  |k7  rS|| _         || _        t        | j                  |      | _
        t        | j                  t        dd|      z  |      | _        y y rl  )r   r   r
   r   r   r   r'   r+  r   r   r   ri   r   r  r   s      r   r   zF12.initwithsize2  s    88s?zz!#J	(c)93?	,TZZ#-=sCDM >>X%DH%DN!$))X6DL!$))hq!S.A"A8LDL	 &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j                  z
  }t        || j                        }|dkD  }||   d| j                  |   t        j                  ||         z  z   z  ||<   t        || j                        }	 | j                  t        j                  |dz  d      z  d| j                  z
  |d d df   dz  z  z   }| j                  |      }||z  }||z  }||fS # t        $ rA | j                  t        j                  |dz        z  d| j                  z
  |d   dz  z  z   }Y hw xY w)Nr   r^   r   r7   )r   r   r   r   r   r   r+  r  r   rB   r  r"   rf   r   r  s           r   r~   zF12._evalfullB  sa   yyA# >>X%h,
 4==!!e3AS 1BGGAcFO CCD#4==!	SNNRVVAqD"%55T^^9KqQRTUQUwXYz8YYE zz%  	U{  	SNNRVVAqD\1Q5G1Q4QR74RRE	Ss   7AD AE#"E#Nr  r   r   r   r  r  ,  s    DEIDM r   r  c                   (    e Zd ZdZdZdZdZd Zd Zy)F13zSharp ridge   r  r   c                 >   | j                   |k7  r| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  dz  t        dd|      z  | _
        t        t        | j
                  |      t        | j                              | _        t        | j                  | j                        | _        | j                  |k7  r*|| _         || _        t        | j                  |      | _        y y r)  r*  r   s      r   r   zF13.initwithsizee  s    88s?zz!#J	(S9	,TZZ#-=sCDM>>R/HQ34GGDK 0S A4CTUDMt}}=DM >>X%DH%DN!$))X6DL &r   c           
      T   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j                  z
  }t        || j                        }	 |d d df   dz  | j                  t        j                  t        j                  |d d dd f   dz  d            z  z   }| j                  |      }||z  }||z  }||fS # t        $ rH |d   dz  | j                  t        j                  t        j                  |dd  dz  d            z  z   }Y ow xY w)Nr   r   r^   r7   )r   r   r   r   r   r   r,  rp   r   rB   r"   rf   r   r   s          r   r~   zF13._evalfullw  s   yyA# >>X%h,
 4==!	MadGqL4::qABx1}b8Q0R#RRE zz%  	U{  	MaDAI

RWWRVVAabEQJ5K-L LLE	Ms   (AC AD'&D'Nr/  r   r   r   r  r  _  s    EIE7$r   r  c                   $    e Zd ZdZdZdZd Zd Zy)	_FDiffPowznAbstract Sum of different powers, between x^2 and x^6.

    Method boundaryhandling needs to be defined.

    g      @   c           	         | j                   |k7  rV| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  |k7  rV|| _         || _        t        | j                  |      | _
        t        d| j                  t        dd|      z  z   |      | _        y y )Nr         @r   r^   )r   r   r
   r   r   r   r'   r+  r   r   r   rp   r   r  r   s      r   r   z_FDiffPow.initwithsize  s    88s?zz!#J	(S9	,TZZ#-=sCDM >>X%DH%DN!$))X6DL!"tzzHQ34G'G"GRDL	 &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j	                  |      z   }|| j
                  z
  }t        || j                        }t        j                  t        j                  t        j                  |      | j                  z  d            }| j                  |      }||z  }||z  }||fS r   )r   r   r   r   r   r   r   r+  r   rB   r"   r9   r  r   r   s          r   r~   z_FDiffPow._evalfull  s    yyA# >>X%h, d++A.. 4==! rvvayDLL8"=>zz%  	U{r   N)r   r   r   r   rp   r   r   r~   r   r   r   r  r    s    
 EFS r   r  c                       e Zd ZdZdZd Zy)F14z8Sum of different powers, between x^2 and x^6, noise-freer  c                      yr   r   rz   s     r   r   zF14.boundaryhandling  r   r   Nr   r   r   r   r  r    s    BEr   r  c                       e Zd ZdZdZdZy)F119z=Sum of different powers with Gauss noise, between x^2 and x^6w   rI   Nr   r   r   r   r  r    s    GEIr   r  c                       e Zd ZdZdZdZdZy)F120z?Sum of different powers with uniform noise, between x^2 and x^6x   rI   Nr   r   r   r   r  r    s    IELHr   r  c                       e Zd ZdZdZdZdZy)F121zESum of different powers with seldom Cauchy noise, between x^2 and x^6y   rI   r  Nr   r   r   r   r  r    s    OEKGr   r  c                   (    e Zd ZdZdZdZdZd Zd Zy)F15z?Rastrigin with asymmetric non-linear distortion, "condition" 10   r  r  c                    | j                   |k7  r| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  dz  t        dd|      z  | _
        t        t        | j
                  |      t        | j                              | _        t        | j                  | j                        | _        | j                  |k7  rS|| _         || _        t        | j                  |      | _        t        | j"                  t        dd|      z  |      | _        y y r)  r   r   r
   r   r   r   r'   r+  r  r   r  r   r   r,  r   r   r   ri   r  r   s      r   r   zF15.initwithsize  s    88s?zz!#J	(S9	,TZZ#-=sCDM>>R/HQ34GGDK 0S A4CTUDMt}}=DM >>X%DH%DN!$))X6DL!$))hq!S.A"A8LDL	 &r   c                 z   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j                  z
  }t        || j                        }t        |      }|dkD  }||   d| j                  |   t        j                  ||         z  z   z  ||<   t        || j                        }d|t        j                  t        j                  dt        j                  z  |z        d      z
  z  t        j                  |dz  d      z   }| j                  |      }||z  }||z  }||fS )Nr)   rI   r  r   r7   )r   r   r   r   r   r   r+  r4   r  r   rB   r,  r"   rC   rD   r   r  s           r   r~   zF15._evalfull  s    yyA# >>X%h,
 4==!!"f3Bc!2RWWQsV_!DDE#4==! sRVVBFF1ruu9q=$92>>?"&&aQSBTTzz%  	U{r   Nr  r   r   r   r  r    s    IEIDM(r   r  c                   $    e Zd ZdZdZdZd Zd Zy)F16zWeierstrass, condition 100   r   c                    | j                   |k7  r| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        d| j                  dz  z  t        dd|      z  | _
        t        t        | j
                  |      t        | j                              | _        t        | j                  | j                        | _        t        j                  dd      }t        j                   d|z  d      | _        t        j                   d|z  d      | _        t        j&                  | j"                  t        j(                  d	t        j*                  z  | j$                  z  dz        z        | _        | j.                  |k7  r*|| _         || _        t1        | j                  |      | _        y y )
Nr  rI   r   r   r^   r  )r^   r  g      @r   )r   r   r
   r   r   r   r'   r+  r  r   r  r   r   r,  r   aranger   aKbKr"   rC   rD   f0r   r   r   )r{   r   r   Ks       r   r   zF16.initwithsize  sK   88s?zz!#J	(S9	,TZZ#-=sCDM" 44!Q9LLDK 0S A4CTUDMt}}=DM		!R Ajj73DGjjq'2DGffTWWrvva"%%i$''.AC.G'HHIDG >>X%DH%DN!$))X6DL &r   c                 :   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       t	        j
                  dt	        j                  |      dz
        t        |      z  }d|z  t	        j                  |dz  d      z  }||z   }|| j                  z
  }t        || j                        }t        |      }t        || j                        }t        |      dk  rt	        j                  t        | j                  t	        j                   t        | j"                  j$                  dt        j&                  z  t	        j(                  |dt        |      f      dz   z                          }nt	        j*                  |d         }t-        |      D ]  \  }}	t	        j                  t        | j                  t	        j                   t        | j"                  j$                  dt        j&                  z  t	        j(                  |	dt        |	      f      dz   z                          ||<    d||z  | j.                  z
  dz  z  }	 t	        j0                  |      }| j5                  |      }
||z  }|
|z  }
|
|fS # t2        $ r Y *w xY w)	Nr         @r  r   r7   r^   r   r  )r   r   r   r   r   r8   r9   r   r"   r   r   r+  r4   r,  lenr  rC   r  rd  rD   r   r
   	enumerater  rb  rg   r   )r{   r:   r   r   r   r<   r=   rh   kr%   rk   s              r   r~   zF16._evalfull*  s'   yyA# >>X%h, ::aR047:c	RVVHM266d{ 4==!!4==! x=1FF3twws47799a"%%i2::VWZ[]`ab]cYdKehkKk>l/m(nopEHHXa[)E!!166#dggrvvc$''))QYRTR\R\]^abdghidj`kRlorRrEs6t/u"vwa % us{TWW,22	IIe$E zz%  	U{  		s   J 	JJNr  r   r   r   r  r    s    $EI7.%r   r  c                   (    e Zd ZdZdZdZdZd Zd Zy)_FSchaffersF7zAbstract Schaffers F7 with asymmetric non-linear transformation, condition 10

    Class attribute condition and method boundaryhandling need to be defined.

       Nr   c                 F   | j                   |k7  r| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  dz  t        dd|      z  | _
        t        t        | j
                  |      t        | j                              | _        | j                  |k7  rS|| _         || _        t        | j                  |      | _        t        | j"                  t        dd|      z  |      | _        y y r)  r  r   s      r   r   z_FSchaffersF7.initwithsize[  s    88s?zz!#J	(S9	,TZZ#-=sCDM>>R/HQC4HHDK 0S A4CTUDM >>X%DH%DN!$))X6DL!$))hq!S.A"A8LDL	 &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j	                  |      z   }|| j
                  z
  }t        || j                        }|dkD  }||   d| j                  |   t        j                  ||         z  z   z  ||<   t        || j                        }	 |d d d df   dz  |d d dd f   dz  z   }t        j                  |dz  t        j                  d|dz  z        dz  dz   z  d      dz  }| j                  |      }||z  }||z  }||fS # t        $ r |d d dz  |dd  dz  z   }Y yw xY w)Nr   r^   r7   r         ?2   r*   )r   r   r   r   r   r   r   r+  r  r   rB   r,  rf   meanr/   r   )	r{   r:   r   r   r   r   srh   rk   s	            r   r~   z_FSchaffersF7._evalfullm  s~   yyA# >>X%h, d++A.. 4==!!e3AS 1BGGAcFO CCD#4==!	)!SbS&	Q1ab5Q.A SBFF2R<$8A$=$ABBG1Lzz%  	U{  	)#2!aeqj(A	)s   E E"!E")	r   r   r   r   r   r  ri   r   r~   r   r   r   r  r  Q  s#    
 FIDM$r   r  c                       e Zd ZdZdZdZd Zy)F17zDSchaffers F7 with asymmetric non-linear transformation, condition 10r  r  c                     t        |d      S Nr  r   rz   s     r   r   zF17.boundaryhandling      &q#..r   Nrq  r   r   r   r  r    s    NEI/r   r  c                       e Zd ZdZdZdZd Zy)F18zFSchaffers F7 with asymmetric non-linear transformation, condition 1000   rs   c                     t        |d      S r  r   rz   s     r   r   zF18.boundaryhandling  r  r   Nrq  r   r   r   r  r    s    PEI/r   r  c                       e Zd ZdZdZdZdZy)F122zVSchaffers F7 with Gauss noise, with asymmetric non-linear transformation, condition 10z   r  rI   Nru  r   r   r   r  r    s    `EIIr   r  c                        e Zd ZdZdZdZdZdZy)F123zSSchaffers F7 with uniform noise, asymmetric non-linear transformation, condition 10{   r  rI   Nry  r   r   r   r  r    s    ]EILHr   r  c                        e Zd ZdZdZdZdZdZy)F124zYSchaffers F7 with seldom Cauchy noise, asymmetric non-linear transformation, condition 10|   r  rI   r  Nr}  r   r   r   r  r    s    cEIKGr   r  c                   $    e Zd ZdZdZdZd Zd Zy)_F8F2zAbstract F8F2 sum of Griewank-Rosenbrock 2-D blocks

    Class attribute facftrue and method boundaryhandling need to be defined.

    N   c           
         | j                   |k7  rt        d|dz  dz        }|t        | j                  |      z  | _        | j
                  rt        j                  d       t        j                  t        | j                  dt        j                  |df      z  |dz  z              | _        | j                  |k7  r*|| _         || _        t        | j                  |      | _        y y )Nr^   r   rG  z6F19,F125,F126,F127 do not feature setting xopt to zeror   )r   r   r'   r   r,  r   rN   rO   r   rb  r   rc  r   r   r   r   re  s       r   r   z_F8F2.initwithsize  s    88s?3"9r>*E!$4TZZ$EEDMzzVW		#dmmS277C8;L5LuXYz5Y"Z[DI >>X%DH%DN!$))X6DL &r   c                 ~   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j	                  |      z   }t        || j                        dz   }	 d|d d d df   dz  |d d dd f   z
  dz  z  d|d d d df   z
  dz  z   }| j                  | j                  t        j                  |dz  t        j                  |      z
  d      z  |dz
  z  z   }| j                  |      }||z  }||z  }||fS # t        $ r# d|d d dz  |dd  z
  dz  z  d|d d z
  dz  z   }Y w xY w)Nr   r   r7   r   r^   rI   g     @@)r   r   r   r   r   r   r,  rf   facftruer   r"   rC   r   )r{   r:   r   r   r   f2rh   rk   s           r   r~   z_F8F2._evalfull  so   yyA# >>X%h, d++A.. 4==!C'	H1crc6a!AqrE(2q88B1crc6Nq;PPB rEzBFF2J7NPR0S SWZ]_W_ ``zz%  	U{  	H3B1qu,22b1Sb6ka5GGB	Hs   02D )D<;D<)r   r   r   r   r  r   r   r~   r   r   r   r  r    s    
 HF7r   r  c                       e Zd ZdZdZdZd Zy)F19z6F8F2 sum of Griewank-Rosenbrock 2-D blocks, noise-freer  r  c                      yr   r   rz   s     r   r   zF19.boundaryhandling  r   r   N)r   r   r   r   r   r  r   r   r   r   r  r    s    @EHr   r  c                       e Zd ZdZdZdZdZy)F125z;F8F2 sum of Griewank-Rosenbrock 2-D blocks with Gauss noise}   rI   N)r   r   r   r   r   r  r   r   r   r   r  r    s    EEHIr   r  c                        e Zd ZdZdZdZdZdZy)F126z=F8F2 sum of Griewank-Rosenbrock 2-D blocks with uniform noise~   rI   N)r   r   r   r   r   r  r   r   r   r   r   r  r    s    GEHLHr   r  c                        e Zd ZdZdZdZdZdZy)F127zCF8F2 sum of Griewank-Rosenbrock 2-D blocks with seldom Cauchy noise   rI   r  N)r   r   r   r   r   r  r   r   r   r   r   r  r    s    MEHKGr   r  c                   $    e Zd ZdZdZdZd Zd Zy)F20z1Schwefel with tridiagonal variable transformation   r  c                 T   | j                   |k7  r| j                  r&t        |      | _        t	        j
                  d       n-dt        t        || j                        dz
        z  dz  | _        | j                  dz  t        j                  dd|      z  | _        | j                  |k7  r|| _         || _        t        dt        j                  | j                        z  |      | _        t        | j                  |      | _        t        t        | j                        |      | _        y y )Nz3F20 does not feature setting xopt to zero correctlyr   guO@r   r^   r   )r   r   r
   r   rN   rO   r   r   r   r  r   r   r  r   r   r9   r   r  arrsignsr   s      r   r   zF20.initwithsize  s    88s?zz!#J	ST$tC'<s'B"CClR	>>R/BKK1c4JJDK >>X%DH%DN!!bffTYY&7"7BDL#DKK:DN"4		?H=DM &r   c                 v   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       d| j                  z  |z  }	 |d d dd f   d|d d d df   | j
                  d d d df   z
  z  z   |d d dd f<   d| j                  || j
                  z
  z  | j
                  z   z  }t        j                  dt        j                  |      dz
        t        |      z  }dt        j                  |dz  d      z  }||z   }dd	t        j                  |t        j                  t        j                  t        j                  |                  z  d      z
  z  }| j!                  |      }||z  }||z  }||fS # t        $ r% |dd  d|d d | j
                  d d z
  z  z   |dd  Y )w xY w)
Nr   r^   r  r7   r   r)   g     @@r   g",/z@)r   r   r   r   r  r   rf   r  r   r8   r9   r   r"   r  r/   rB   r   )	r{   r:   r   r   r   r<   r=   rh   rk   s	            r   r~   zF20._evalfull  s   yyA# >>X%h, !	?ABx#1crc6T\\!SbS&5I)I"JJAaeH DNNa$,,&67$,,FG ::b"&&)d"23d1g=bffX]B//d{ *bgga"&&PQAS:T6TVX.YYZzz%  	U{!  	?abEC1Sb6DLL",=#=>>AabE	?s   9F
 
*F87F8Nr  r   r   r   r  r    s    ;EI>$r   r  c                   4    e Zd ZdZdZdZdZdZdZdZ	d Z
d Zy)_FGallagherzAbstract Gallagher with nhighpeaks Gaussian peaks, condition up to 1000, one global rotation

    Attribute fac2, nhighpeaks, highpeakcond and method boundary
    handling need to be defined.

       rs   )g?g333333"@Nc           
      V   | j                   |k7  rt        | j                  |      | _        | j                  t        dd| j                  dz
        z  }t        j                  t        | j                  dz
  | j                              }t        j                  ||   d| j                        }g | _        t        |      D ]b  \  }}|t        dd|      z  }t        j                  t        || j                  d|z  z               }| j                  j                  ||          d t        j                  | j                        | _        t        j                  t        | j                   d   | j                   d   | j                  dz
        dd      | _        | j$                  |k7  r|| _         || _        t'        | j(                  t        j*                  dt        || j                  z  | j                        z  dz
  | j                  |f      z  | j                        | _        | j.                  rt1        |      | j,                  dd d f<   n'd| j,                  dd d f   z  | j,                  dd d f<   t'        | j,                  dd d f   | j                  j2                        | _        y y )	Nr   r^         r   rs   r  r  g?)r   r'   r   r+  maxconditionr   
nhighpeaksr   argsortr   inserthighpeakcondr  r  appendvstack	fitvalues
peakvaluesr   r   fac2r   xlocalr   r
   rd  r   )r{   r   r   arrconditionr   r%   er  s           r   r   z_FGallagher.initwithsize?  s    88s?,TZZ=DM,,AtQR?R0SSL**T$//A"5tzzBCC99\#%64;L;LMLDN!,/1#r3//jjc4::a+?!@A%%af- 0  YYt~~6DN ii1BDNNSTDUW[WfWfijWj(kmnpstDO >>X%DH%DNdii"**S4doo@UW[WaWa;b5beg5gjnjyjy{~i  +A  A"mm-DKzz$)#JAqD! %($++ad*;$;AqD!DKK1-t}}?DI &r   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j	                  |      z   }t        || j                        }d|z  }t        |      dk  rt        j                  | j                        }t        || j                  df      | j                  z
  }| j                  t        j                  |t        j                  | j                   |dz  z  d      z        z  |d d  nr|d   d| j                  z  k  rt        j                  |d   | j                  f      }t#        |      D ]z  \  }}	t        |	| j                  df      | j                  z
  }| j                  t        j                  |t        j                  | j                   |dz  z  d      z        z  ||d d f<   | nt        j                  |d   | j                  f      }t%        | j                        D ]t  }
|t        | j                  |
d d f   |d   df      z
  }| j                  |
   t        j                  |t        |dz  | j                   |
d d f         z        z  |d d |
f<   v t'        dt        j(                  |d      z
        dz  }| j+                  |      }||z  }||z  }||fS )Nr  r   r^   r   r   r  r7   )r   r   r   r   r   r   r+  r  r   r
   r  r	   r  r  r.   r"   r  r  r!   r4   r   r   )r{   r:   r   r   r   r;   r2   xxr  r  r%   rh   rk   s                r   r~   z_FGallagher._evalfull\  sm   yyA# >>X%h, d++A.. 4==! Sj x=1)Aa$//1-.<B??RVVC"&&"PQ'9QST2U,U%VVAaDa[2//(1+t78A!!1!dooq12T[[@//BFF3QSWXQX@XZ[9\3\,]]!Q$ % (1+t78A4??+$t{{1a408A;2BCC//!,rvvcSq$..YZ\]Y]J^=_6`/aa!Q$ , b266!R=01Q6zz%  	U{r   )r   r   r   r   r   r  r  r  r  r  r   r~   r   r   r   r  r  1  s2     FLIDJL@:&r   r  c                   &    e Zd ZdZdZdZdZdZd Zy)F21zXGallagher with 101 Gaussian peaks, condition up to 1000, one global rotation, noise-freer  r   rI   'In?@c                     t        |d      S r9  r   rz   s     r   r   zF21.boundaryhandling  r:  r   N)	r   r   r   r   r   r  r  r  r   r   r   r   r  r    s    bEJDL.r   r  c                   *    e Zd ZdZdZdZdZdZdZd Z	y)F22zKGallagher with 21 Gaussian peaks, condition up to 1000, one global rotation   r  g\(\?rs   c                     t        |d      S r9  r   rz   s     r   r   zF22.boundaryhandling  r:  r   N)
r   r   r   r   r   r   r  r  r  r   r   r   r   r  r    s#    UEFJDL.r   r  c                   $    e Zd ZdZdZdZdZdZdZy)F128z]Gallagher with 101 Gaussian peaks with Gauss noise, condition up to 1000, one global rotation   r   rI   r  N)	r   r   r   r   r   r  r  r  r   r   r   r   r  r    s    gEJDLIr   r  c                   (    e Zd ZdZdZdZdZdZdZdZ	y)F129z_Gallagher with 101 Gaussian peaks with uniform noise, condition up to 1000, one global rotation   r   rI   r  N)
r   r   r   r   r   r  r  r  r   r   r   r   r   r  r    s#    iEJDLLHr   r  c                   (    e Zd ZdZdZdZdZdZdZdZ	y)F130zeGallagher with 101 Gaussian peaks with seldom Cauchy noise, condition up to 1000, one global rotation   r   rI   r  r  N)
r   r   r   r   r   r  r  r  r   r   r   r   r   r  r    s#    oEJDLKGr   r  c                   r    e Zd ZdZdZdZ ej                  d ej                  dd      z  d      Z	d Z
d	 Zy
)F23zKatsuura function   r   r  r^   !   )r^   rJ   c                 >   | j                   |k7  r| j                  rt        |      | _        nt	        | j
                  |      | _        t        | j
                  dz   |      | _        | j                  dz  t        dd|      z  | _
        t        t        | j
                  |      t        | j                              | _        t        | j                  | j                        | _        | j                  |k7  r*|| _         || _        t        | j                  |      | _        y y r)  r*  r   s      r   r   zF23.initwithsize  r-  r   c                 z   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       t	        j
                  dt	        j                  |      dz
        t        |      z  }t	        j                  |dz  d      }||z   }|| j                  z
  }t        || j                        }t        |      dk  rt        t	        j                  ||df      | j                        }d|dz  z  d|dz  z  t	        j                  dt	        j                   d|dz         t	        j                  t	        j                  |t	        j"                  |      z
        | j                  j$                  d	z        j$                  z  z         d|d
z  z  z  z  z   }nt'        |d         }t)        |      D ]  \  }	}
t        t	        j                  |
|df      | j                        }d|dz  z  d|dz  z  t	        j                  dt	        j                   d|dz         t	        j                  t	        j                  |t	        j"                  |      z
        | j                  j$                  d	z        j$                  z  z         d|d
z  z  z  z  z   ||	<    | j+                  |      }||z  }||z  }||fS )Nr   r  r   r7   r^   g      $r  r  g      g333333?)r   r   r   r   r   r8   r9   r   r"   r   r   r,  r  r   arr2krX   r  r   rd  r
   r  r   )r{   r:   r   r   r   r<   r=   arrrh   r  r  rk   s               r   r~   zF23._evalfull  s   yyA# >>X%h, ::aR047:vvh!mR(d{ 4==! x=1bjjS!H-tzz:CC2I%3"9_WWQ1cAg!6sRXXVY]GZ@[]a]g]g]i]imp]p9q9s9s!ssty|  @C  GJ  @J  zJ  KKKE (1+&E!!1"**Qa14::> 3"9,#)OGGA		!S1W(=rvvcTVT\T\]`TaNaGbdhdndndpdptwdw@x@z@z(z$z{  AD  GJ  NQ  GQ  AQ  RRRa %
 zz%  	U{r   N)r   r   r   r   r   r  r   r   r  r  r   r~   r   r   r   r  r    s=    EIBJJribii2./9E7&#r   r  c                   (    e Zd ZdZdZdZdZd Zd Zy)F24z^Lunacek bi-Rastrigin, condition 100

    in PPSN 2008, Rastrigin part rotated and scaled

       r   g      @c                    | j                   |k7  r| j                  r&t        |      | _        t	        j
                  d       n4d| j                  z  t        t        || j                              z  | _        t        | j                  dz   |      | _        | j                  dz  t        dd|      z  | _        t        t        | j                  |      t!        | j                              | _        t        | j"                  | j                        | _        | j$                  |k7  r6|| _         || _        t'        dt        | j                        z  |      | _        y y )Nz3F24 does not feature setting xopt to zero correctlyr   r  r   r^   r  )r   r   r
   r   rN   rO   _mu1r   r    r   r'   r+  r  r   r  r   r   r,  r   r   r  r   s      r   r   zF24.initwithsize  s    88s?zz!#J	STNT%TZZ2H-II	,TZZ#-=sCDM>>R/HQ34GGDK 0S A4CTUDMt}}=DM >>X%DH%DN#Bdii$8(CDN	 &r   c                 r   | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       t	        j
                  dt	        j                  |      dz
        t        |      z  }dt	        j                  |dz  d      z  }||z   }| j                  |z  }dd|dz   dz  d	z
  z  z
  }d}| j                  dz  |z
  |z  dz   }	t	        j                  t	        j                  || j                  z
  dz  d      ||z  |t	        j                  ||	z
  dz  d      z  z         }
|
d
|t	        j                  t	        j                  dt        j                  z  t        || j                  z
  | j                        z        d      z
  z  z   }
| j!                  |
      }|
|z  }
||z  }||
fS )Nr   r  r   r   r7   r^   r   r  gffffff@r  )r   r   r   r   r   r8   r9   r   r"   r  r  minimumrC   rD   r   r,  r   )r{   r:   r   r   r   r<   r=   r  dmu2rh   rk   s               r   r~   zF24._evalfull  s   yyA# >>X%h, ::aR047:RVVHM2..d{ NNQ sRx#o+,,a!#q(R//

2661tyy=Q"6;s7QSQ)C%CCEcBFF266!bee)c!dii-QUQ^Q^>_2_+`bd$eeffzz%  	U{r   N)	r   r   r   r   r   r  r  r   r~   r   r   r   r  r    s#    
 EIDD*r   r  c              #   8   K   | ]  }|j                   |f  y wr   r   .0r%   s     r   	<genexpr>r"  2       ;?aaggq\?   z: c              #   8   K   | ]  }|j                   |f  y wr   r  r   s     r   r"  r"  6  r#  r$  c              #   8   K   | ]  }|j                   |f  y wr   r  r   s     r   r"  r"  :  s     1j!jr$  c                        e Zd ZdZdZd Zd Zy)
_FTemplatezTemplate based on F1im c                    | j                   |k7  r8| j                  rt        |      | _        nt	        | j
                  |      | _        | j                  |k7  r)|| _         || _        t        | j                  |      | _        d | _	        d | _
        y r   )r   r   r
   r   r   r   r   r   r   linearTfr+  r   s      r   r   z_FTemplate.initwithsizeB  sm    88s?zz!#J	(S9	 >>X%DH%DN!$))X6DLr   c                    | j                   }| j                  |      \  }}| j                  |k7  r| j                  ||       || j                  z
  }t        j                  |dz  d      }| j                  |      }||z  }||z  }||fS )Nr   r^   )r   r   r   r   r   r   r"   r   r   s          r   r~   z_FTemplate._evalfullS  s    yyA# >>X%h,
  q!tQzz%  	U{r   Nrh  r   r   r   r(  r(  =  s    E"r   r(  c                 @    t        |    d||d|}||j                  fS )zOReturns test function ifun, by default instance 0,
    and its optimal f-value.)r   r   r   )dictbbobr   )ifunr   r   r   r[   s        r   instantiater/  i  s*     4.
HY
H
HC=r   c                 H    	 t         |    j                  S # t        $ r Y yw xY w)z2Returns the parameter values of the function ifun.r   )r-  r  r   )r.  s    r   	get_paramr1  o  s)    ~))) s    	!!__main__)r   N)r   
__future__r   rL   	NameErrorr!   rN   pdbr   numpyr   mathr   r   r   r   r	   r
   r   r   numpy.randomr   re   r   ro   r   r'   r4   r>   r    r   rW   r\   r_   r`   rm   rq   ru   objectrw   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r&  r1  r7  r<  r?  rB  rE  rJ  rM  rP  rS  rV  rY  r\  r_  rj  ro  rs  rw  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  r  r  r  nfreefunclassesnoisyfunclassesdictdictbbobnfreesortedkeysnfreeIDsr   
nfreeinfosdictbbobnoisynoisyIDslist
funclassesr-  r(  r/  r1  r   doctesttestmod)r%   s   0r   <module>rH     s  eT &
     @ @ @ 2 (AJ	0	"R   04&6 4&lf(' f(P 0 0"0, 0$0 0$+| +Z$ 8& 
8( 8' 8& 
8( 8' 0	 0d0	 0d8	 8t.	 .`/	 /b:l :x.+ .?- 
?/ ?. 3< 3j( <* 
<, <+ <* 
<, <+ /	 /b4, 4l+( ;) ;+ ;* -
 -^1
 1f0
 0d/ /b)& 9' 
9) 9( 3
 3jA
 AF9L 9v/-* //-* /=+ =- =, 1L 1f%" 5# 5% 5$ 3
 3jQ, Qf.+( ..+( .;) ;+ ;* <
 <|;
 ;| r2r2r2r2sCc3S#sCc3EtT4tT4tT4tT4tT4tT4O ;?;;-$$&'EMNXc!ftmc-"2":":;;XN
;?;;-$$&'/"T/%::
1j11*" *X zGOO K@  FF> Os   Q: (R:RR