o
    ñh0Ä  ã                   @   sZ   d Z ddlZddlZddlZddlZddlmZ ddlZddl	m
Z
mZ G dd„ dƒZdS )z:Base classes for low memory simplicial complex structures.é    N)Úcacheé   )ÚVertexCacheFieldÚVertexCacheIndexc                   @   sž   e Zd ZdZ		d#dd„Zdd„ Zd$d
d„Z			d%dd„Zd&dd„Zd$dd„Z	d&dd„Z
dd„ Zedd„ ƒZdd„ Zdd„ Zd'dd„Zd'dd „Zd'd!d"„ZdS )(ÚComplexaz  
    Base class for a simplicial complex described as a cache of vertices
    together with their connections.

    Important methods:
        Domain triangulation:
                Complex.triangulate, Complex.split_generation
        Triangulating arbitrary points (must be traingulable,
            may exist outside domain):
                Complex.triangulate(sample_set)
        Converting another simplicial complex structure data type to the
            structure used in Complex (ex. OBJ wavefront)
                Complex.convert(datatype, data)

    Important objects:
        HC.V: The cache of vertices and their connection
        HC.H: Storage structure of all vertex groups

    Parameters
    ----------
    dim : int
        Spatial dimensionality of the complex R^dim
    domain : list of tuples, optional
        The bounds [x_l, x_u]^dim of the hyperrectangle space
        ex. The default domain is the hyperrectangle [0, 1]^dim
        Note: The domain must be convex, non-convex spaces can be cut
              away from this domain using the non-linear
              g_cons functions to define any arbitrary domain
              (these domains may also be disconnected from each other)
    sfield :
        A scalar function defined in the associated domain f: R^dim --> R
    sfield_args : tuple
        Additional arguments to be passed to `sfield`
    vfield :
        A scalar function defined in the associated domain
                       f: R^dim --> R^m
                   (for example a gradient function of the scalar field)
    vfield_args : tuple
        Additional arguments to be passed to vfield
    symmetry : None or list
            Specify if the objective function contains symmetric variables.
            The search space (and therefore performance) is decreased by up to
            O(n!) times in the fully symmetric case.

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

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

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

    constraints : dict or sequence of dict, optional
        Constraints definition.
        Function(s) ``R**n`` in the form::

            g(x) <= 0 applied as g : R^n -> R^m
            h(x) == 0 applied as h : R^n -> R^p

        Each constraint is defined in a dictionary with fields:

            type : str
                Constraint type: 'eq' for equality, 'ineq' for inequality.
            fun : callable
                The function defining the constraint.
            jac : callable, optional
                The Jacobian of `fun` (only for SLSQP).
            args : sequence, optional
                Extra arguments to be passed to the function and Jacobian.

        Equality constraint means that the constraint function result is to
        be zero whereas inequality means that it is to be
        non-negative.constraints : dict or sequence of dict, optional
        Constraints definition.
        Function(s) ``R**n`` in the form::

            g(x) <= 0 applied as g : R^n -> R^m
            h(x) == 0 applied as h : R^n -> R^p

        Each constraint is defined in a dictionary with fields:

            type : str
                Constraint type: 'eq' for equality, 'ineq' for inequality.
            fun : callable
                The function defining the constraint.
            jac : callable, optional
                The Jacobian of `fun` (unused).
            args : sequence, optional
                Extra arguments to be passed to the function and Jacobian.

        Equality constraint means that the constraint function result is to
        be zero whereas inequality means that it is to be non-negative.

    workers : int  optional
        Uses `multiprocessing.Pool <multiprocessing>`) to compute the field
         functions in parallel.
    N© r   c           	   	   C   sd  || _ || _|d u rdg| | _n|| _|| _|| _|| _|d urn|| _g | _g | _t	|t
tfƒs4|f}|D ]*}|d dv r`| j |d ¡ z
| j |d ¡ W q6 ty_   | j d¡ Y q6w q6t
| jƒ| _t
| jƒ| _nd | _d | _d| _d| _g | _|d us†| jd ur©|d ur—t||| j| j|d| _n| jd ur¨t||| j| j|d| _ntƒ | _g | _d S )	N)ç        g      ð?ÚtypeÚineqÚfunÚargsr   r   )ÚfieldÚ
field_argsÚg_consÚg_cons_argsÚworkers)ÚdimÚdomainÚboundsÚsymmetryÚsfieldÚsfield_argsÚmin_consr   Úg_argsÚ
isinstanceÚtupleÚlistÚappendÚKeyErrorÚgenÚ
perm_cycleÚHr   ÚVr   Ú
V_non_symm)	Úselfr   r   r   r   r   Úconstraintsr   Úconsr   r   úU/var/www/vscode/kcb/lib/python3.10/site-packages/scipy/optimize/_shgo_lib/_complex.pyÚ__init__t   s\   ÿü
ý
ý€
zComplex.__init__c                 C   s   | j S ©N)r!   )r$   r   r   r'   Ú__call__»   s   zComplex.__call__Tc              
   c   sØ   t |ƒ}t |ƒ}| j|  | j| }|jV  | j|  | j| ¡ |V  | j| gg}t t|ƒ¡}	|d |	d< | jt |	ƒ }	| j|  |	¡ |	jV  |	gg}
g }t|dd… ƒD ]Í\}}| g ¡ |
 g ¡ z|d  dd„ |d|d … D ƒ}dd„ |
d|d … D ƒ}tt||ƒƒD ]•\}\}}tt||ƒƒD ]‡\}\}}t|jƒ}t|jƒ}||d  ||d < ||d  ||d < | jt |ƒ }| |¡ |jV  | jt |ƒ }| |¡ | |¡ | |¡ | ||f¡ ||d   |¡ ||d   |¡ |
|d   |¡ |
|d   |¡ ||  |¡ |
|  |¡ |jV  qqt |¡}|D ]O}t|d jƒ}t|d jƒ}||d  ||d < ||d  ||d < | jt |ƒ }| jt |ƒ }|d  |¡ | |¡ | |d |f¡ | ||f¡ q-W qZ t	y(   || }|
| }||}}tt||ƒƒD ]‹\}\}}t|jƒ}||d  ||d < | jt |ƒ }| |¡ | |¡ | ||f¡ ||d   |¡ |
|d   |¡ | | j| ¡ |jV  t |¡}|D ]7}|d j| || kr"t|d jƒ}||d  ||d < | jt |ƒ }|d  |¡ | |d |f¡ qìqšY qZw z~~~
~~~W n
 t
y;   Y nw |rg| j| }| j| }| |¡ |  ||¡}|jD ]}| |¡ qW|jV  |jS |V  |S )z3Generate initial triangulation using cyclic productr   r   Nc                 S   ó   g | ]}|d d … ‘qS r)   r   ©Ú.0Úxr   r   r'   Ú
<listcomp>è   ó    z*Complex.cyclic_product.<locals>.<listcomp>c                 S   r+   r)   r   r,   r   r   r'   r/   é   r0   )r   r"   r.   ÚconnectÚcopyr   Ú	enumerater   ÚzipÚ
IndexErrorÚUnboundLocalErrorÚ
disconnectÚ
split_edgeÚnn)r$   r   ÚoriginÚsupremumÚcentroidÚvotÚvutÚvoÚC0xÚa_voÚC1xÚab_CÚir.   ÚcC0xÚcC1xÚjÚVLÚVUÚkÚvlÚvuÚa_vlÚa_vuÚab_CcÚvpÚb_vÚab_vÚvsÚvcÚvr   r   r'   Úcyclic_product¿   sÔ   €

	








Ú
*
ó




€÷êü&ÿ



zComplex.cyclic_productFc                 C   s~  |du r| j }dd„ | jD ƒ}|| _dd„ | jD ƒ}|| _|du r%| j}ndt | j¡}t|ƒD ]Y\}}	||	urˆ| j||  d g||< | j||  d g||< | j||  | j||	  urˆt d|› d|	› d	|› d
| j||  › d|	› d
| j||	  › d¡ | j||	  ||< q/|du rÆ|  ||||¡| _	| j	D ]}| q™z| j
 t| jƒt| jƒf¡ W n| ttfyÅ   t| jƒt| jƒfg| _
Y nfw z| j	 W n ttfyß   |  ||||¡| _	Y nw zt| jjƒ|k röt| j	ƒ t| jjƒ|k séW n3 ty*   z| j
 t| jƒt| jƒf¡ W n ttfy'   t| jƒt| jƒfg| _
Y nw Y nw |r=| jjD ]
}
| j|
  ¡  q2dS )a  
        Triangulate the initial domain, if n is not None then a limited number
        of points will be generated

        Parameters
        ----------
        n : int, Number of points to be sampled.
        symmetry :

            Ex. Dictionary/hashtable
            f(x) = (x_1 + x_2 + x_3) + (x_4)**2 + (x_5)**2 + (x_6)**2

            symmetry = symmetry[0]: 0,  # Variable 1
                       symmetry[1]: 0,  # symmetric to variable 1
                       symmetry[2]: 0,  # symmetric to variable 1
                       symmetry[3]: 3,  # Variable 4
                       symmetry[4]: 3,  # symmetric to variable 4
                       symmetry[5]: 3,  # symmetric to variable 4
                        }
        centroid : bool, if True add a central point to the hypercube
        printout : bool, if True print out results

        NOTES:
        ------
        Rather than using the combinatorial algorithm to connect vertices we
        make the following observation:

        The bound pairs are similar a C2 cyclic group and the structure is
        formed using the cartesian product:

        H = C2 x C2 x C2 ... x C2 (dim times)

        So construct any normal subgroup N and consider H/N first, we connect
        all vertices within N (ex. N is C2 (the first dimension), then we move
        to a left coset aN (an operation moving around the defined H/N group by
        for example moving from the lower bound in C2 (dimension 2) to the
        higher bound in C2. During this operation connection all the vertices.
        Now repeat the N connections. Note that these elements can be connected
        in parallel.
        Nc                 S   ó   g | ]}|d  ‘qS )r   r   ©r-   rD   r   r   r'   r/   ”  ó    z'Complex.triangulate.<locals>.<listcomp>c                 S   rW   ©r   r   rX   r   r   r'   r/   –  rY   r   r   z	Variable z( was specified as symmetric to variable z, however, the bounds z = z and zE do not match, the mismatch was ignored in the initial triangulation.)r   r   r:   r;   r2   r3   ÚloggingÚwarningrV   ÚcpÚtriangulated_vectorsr   r   ÚAttributeErrorr   Úlenr"   r   ÚnextÚStopIterationÚ	print_out)r$   Únr   r<   Úprintoutr:   r;   ÚcboundsrD   rG   rU   r   r   r'   Útriangulatef  sŒ   +ÿÿþýý
û€

ÿÿÿ


ÿÿ
ÿ€
ÿÿÿ€üzComplex.triangulatec              
   C   s  |d u r0z
| j  |  ¡  W d S  ty/ } zt|ƒdkr*| j| jd W Y d }~d S ‚ d }~ww t| jjƒ| }t| jjƒ|k rˆz-| j  zt	| j
ƒ W n  tttfyk   | j d }| j|d| jiŽ| _
t	| j
ƒ Y nw W n ttfy   |  || j¡ Y nw t| jjƒ|k s@d S )Nú8'Complex' object has no attribute 'triangulated_vectors')r   r   r   )r^   Ú
refine_allr_   Ústrrg   r   r`   r"   r   ra   Úrlsrb   r   Úrefine_local_spacer   )r$   rd   ÚaeÚntrP   r   r   r'   ÚrefineÙ  s:   €ú
ý€ûñzComplex.refinec              
   C   s–   z'| j  t | j ¡}t|ƒD ]\}}| j|d| jiŽ| _| jD ]}| qqW dS  tyJ } zt|ƒdkr>| j| j	|d n‚ W Y d}~dS d}~ww )z0Refine the entire domain of the current complex.r   rh   )r   r<   N)
r^   r2   r3   rl   r   rk   r_   rj   rg   r   )r$   Ú	centroidsÚtvsrD   rP   rm   r   r   r'   ri     s$   
ÿþö
þ€özComplex.refine_allc           G      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 ||8  
|	¡ |@jV  q²q¢W qÏ tyM   |"D ]²}%t|%d	 jƒ}5t|%d
 jƒ})||d  |5|d < ||d  |)|d < | jt|)ƒ })|)V  |  |%d j|)j¡}*|)V  |* 	|%d ¡ |* 	|%d ¡ |* 	|%d	 ¡ |* 	|%d
 ¡ |*jV  | jt|5ƒ }5|5V  |  |%d	 j|5j¡}6|  |%d
 j|)j¡}1|  |6j|1j¡}A|6V  |1V  |AV  |%\}7}}}}	||||	|5|)g}2t |2d¡}3|3D ]}4|  |4d j|4d j¡ qqî|| }|| } || }!|| |!}9}:};tt|9|:|;ƒƒD ]\}<\}}=}t|jƒ}	||d  |	|d < | jt|	ƒ }	|jV  |  |j|	j¡}7|  |j|j¡ |7 	|¡ |7 	|=¡ |7 	|¡ |7 	|¡ |7 	|	¡ |7jV  |  |j|	j¡}?|? 	|¡ |7 	|?¡ |?jV  ||d   
|¡ ||d   
|?¡ ||d   
|	¡ | 
|7|||	g¡ |	jV  q½Y qÏw z~~~~~"W n
 ty_   Y nw z| j t|ƒt|ƒf¡ W n
 tyx   Y nw |D ]}| j 
t|jƒt|jƒf¡ q{|rtƒ }Bg }C|D ]"}|  |j|j¡}Dz|D |B¡ W n
 ty²   Y nw |C 
|D¡ q—|CD ]}Dz|D |B¡ W q¼ tyÑ   Y q¼w t||CƒD ]3\}}D|  |j|j¡}E|B |E¡ z|D |B¡ W n
 tyù   Y nw |DD ]}F|E 	|F¡ qü|EjV  q×n	 |V  d S )N)NNNr   r   c                 S   r+   r)   r   r,   r   r   r'   r/   b  r0   z.Complex.refine_local_space.<locals>.<listcomp>c                 S   r+   r)   r   r,   r   r   r'   r/   c  r0   c                 S   r+   r)   r   r,   r   r   r'   r/   d  r0   é   é   é   )r2   r   r3   r   r"   r8   r.   r9   r   r1   r   r5   Ú	itertoolsÚcombinationsr4   r6   r^   ÚremoveÚ
ValueErrorÚsetÚvpoolr   Úadd)Gr$   r:   r;   r   r<   Úorigin_cÚ
supremum_crK   rL   rN   Ús_ovÚs_originÚs_svÚ
s_supremumrD   Úvir=   r>   r?   rS   ÚvcoÚsup_setrM   Úc_vÚCoxÚCcxÚCuxrC   Ús_ab_Cr.   Út_a_vlÚcCoxÚcCcxÚcCuxrO   Ús_ab_CcÚt_a_vuÚvectorsÚbc_vcÚb_vlÚb_vuÚba_vuÚd_bc_vcÚb_vl_cÚos_vÚss_vÚb_vu_cÚd_b_vlÚd_b_vuÚd_ba_vuÚcombÚ	comb_iterÚvecsÚba_vlÚd_ba_vlÚc_vcrG   rH   ÚVCrI   rJ   rT   Úc_vlÚc_vuÚa_vcÚd_ba_vcÚvcn_setÚ
c_nn_listsÚc_nnÚvcnÚvnnr   r   r'   rl     s¸  €


€




























ÿ



















ÿ  













Æÿ=þÿ





ÿ

ßÜHÿ
ÿþ ÿÿ
ÿözComplex.refine_local_spacec                 C   s¦   t   |j¡}g }tƒ }|D ]}| t   |j¡¡ qt||ƒD ]2\}}| |¡}|  |j|j¡}|D ]}| |¡ q1| 	|¡ |D ]}	|  |j|	j¡}
| |
¡ q@qdS )z'Refine the star domain of a vertex `v`.N)
r2   r9   ry   r   r4   Úintersectionr8   r.   r1   r{   )r$   rU   r¬   Úv1nnÚ
d_v0v1_setÚv1ÚvnnuÚd_v0v1Úo_d_v0v1Úv2Úd_v1v2r   r   r'   Úrefine_starÑ  s    

þzComplex.refine_starc                 C   sŽ   | j | }| j | }| |¡ z|j|j d |j }W n ty3   |j|j t d¡ |j }Y nw | j t|ƒ }| |¡ | |¡ |S )Ng       @)r"   r7   Úx_aÚ	TypeErrorÚdecimalÚDecimalr   r1   )r$   r°   r´   ÚvctrT   r   r   r'   r8   æ  s   


 ÿ

zComplex.split_edgec              
   C   s  t |ƒ}t |ƒ}| j| }| j| }t|ƒ}t|ƒ}tt||ƒƒD ]\}	\}
}||	 |kr1|||	< ||	 |
k r;|
||	< q!tƒ }| |j¡ | |j¡ t |¡}|D ]-}t|j	ƒD ]%\}	}||	 |  krk||	 krnn nqYz| 
|¡ W qY ty~   Y qYw qR|S r)   )r   r"   r   r3   r4   ry   Úupdater9   r2   r.   rw   r   )r$   r:   r;   r=   Úvstr?   rS   ÚblÚburD   ÚvoiÚvsiÚvn_poolÚcvn_poolÚvnÚxir   r   r'   rz   ø  s6   

€
 ÿúzComplex.vpoolc              	   C   sš   | j dkr/|D ]%}t || j ¡}|D ]}| jt||d  ƒ  | jt||d  ƒ ¡ qqdS |D ]}| jt||d  ƒ  | jt||d  ƒ ¡ q1dS )zÚ
        Convert a vertex-face mesh to a vertex-vertex mesh used by this class

        Parameters
        ----------
        vertices : list
            Vertices
        simplices : list
            Simplices
        r   r   N)r   ru   rv   r"   r   r1   )r$   ÚverticesÚ	simplicesÚsÚedgesÚer   r   r'   Úvf_to_vv  s   
ÿÿýÿzComplex.vf_to_vvc                 C   s®  |du r| j }n|}t|ƒ| j jv r| j | | jv rndS | j |  d}g }|D ]}| |j¡ q(t |¡}t |¡t |¡ }tj	t
|jd ƒ| jd dD ]f}d}	tj	|ddD ]4}
| j t||
d  ƒ | j t||
d  ƒ jvrŽ| j t||
d  ƒ | j t||
d  ƒ jvrŽd}	 nqZ|t|gƒ }|	r¡| j|ddr¡d}	|	rµ|t|gƒ }|  |||¡rµd} nqO|rÌ|D ]}
| j |  | j t||
 ƒ ¡ qº| j | j | ¡ |S )	a™  
        Adds a vertex at coords v_x to the complex that is not symmetric to the
        initial triangulation and sub-triangulation.

        If near is specified (for example; a star domain or collections of
        cells known to contain v) then only those simplices containd in near
        will be searched, this greatly speeds up the process.

        If near is not specified this method will search the entire simplicial
        complex structure.

        Parameters
        ----------
        v_x : tuple
            Coordinates of non-symmetric vertex
        near : set or list
            List of vertices, these are points near v to check for
        NFr   r   )ÚrTrr   )Úproj)r"   r   r   r#   r   r.   ÚnpÚarrayru   rv   ÚrangeÚshaper   r9   Údeg_simplexÚ
in_simplexr1   )r$   Úv_xÚnearÚstarÚfound_nnÚS_rowsrU   ÚAÚs_iÚvalid_simplexrD   ÚSÚA_j0r   r   r'   Úconnect_vertex_non_symm3  sV   


ÿÿÿ€€ zComplex.connect_vertex_non_symmc           	   
   C   s’   t  |dd¡|d  }t  t j |¡¡}|dkrd}|du r"|| }t| jd ƒD ]}d| | }t  t j t  ||d¡¡¡}||krDq) dS dS )a‰  Check if a vector v_x is in simplex `S`.

        Parameters
        ----------
        S : array_like
            Array containing simplex entries of vertices as rows
        v_x :
            A candidate vertex
        A_j0 : array, optional,
            Allows for A_j0 to be pre-calculated

        Returns
        -------
        res : boolean
            True if `v_x` is in `S`
        r   éÿÿÿÿNr   FT)rÎ   ÚdeleteÚsignÚlinalgÚdetrÐ   r   )	r$   rÜ   rÔ   rÝ   ÚA_11Úsign_det_A_11ÚdÚdet_A_jjÚsign_det_A_j0r   r   r'   rÓ   €  s   ÿzComplex.in_simplexc                 C   s4   |du r|dd… |d  }t j |¡dkrdS dS )aF  Test a simplex S for degeneracy (linear dependence in R^dim).

        Parameters
        ----------
        S : np.array
            Simplex with rows as vertex vectors
        proj : array, optional,
            If the projection S[1:] - S[0] is already
            computed it can be added as an optional argument.
        Nr   r   r   TF)rÎ   râ   rã   )r$   rÜ   rÍ   r   r   r'   rÒ   °  s
   zComplex.deg_simplex)NNr   NNr   )T)NNTFrZ   r)   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r*   rV   rg   ro   ri   rl   r¶   r   r8   rz   rË   rÞ   rÓ   rÒ   r   r   r   r'   r      s2    f
ÿG
 (
ÿ
s
(
   >
$

M0r   )rì   r2   r[   ru   r¹   Ú	functoolsr   ÚnumpyrÎ   Ú_vertexr   r   r   r   r   r   r'   Ú<module>   s    