o
    ßË·e &  ã                   @   sJ   d Z ddlZddlZddlm  mZ ddlm	Z	 ej
ZG dd„ dƒZdS )z#
Threshold Graphs
================
é    N)Úgraph_could_be_isomorphicc                   @   sœ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%S )&ÚTestGeneratorThresholdc                 C   sº   t  d¡}t |¡sJ ‚t tdd„ | ¡ D ƒƒ¡sJ ‚t  d¡}t |¡s(J ‚t tdd„ | ¡ D ƒƒ¡s8J ‚g d¢}t |¡rCJ ‚g d¢}t |¡sNJ ‚t j 	|¡}t |¡s[J ‚d S )Né
   c                 s   ó    | ]\}}|V  qd S ©N© ©Ú.0ÚnÚdr   r   ú_/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/algorithms/tests/test_threshold.pyÚ	<genexpr>   ó   € zLTestGeneratorThreshold.test_threshold_sequence_graph_test.<locals>.<genexpr>c                 s   r   r   r   r   r   r   r   r      r   )é   é   r   é   r   r   ©r   r   r   r   )
ÚnxÚ
star_graphÚnxtÚis_threshold_graphÚis_threshold_sequenceÚlistÚdegreeÚcomplete_graphÚ
generatorsÚhavel_hakimi_graph)ÚselfÚGÚdegr   r   r   Ú"test_threshold_sequence_graph_test   s   
 
 z9TestGeneratorThreshold.test_threshold_sequence_graph_testc           	      C   s
  g d¢}t j |¡}t t¡ tj|ddd W d   ƒ n1 s"w   Y  t |¡}t |¡}d 	|¡dks:J ‚tj|dd}t |¡}|g d¢ksNJ ‚tj|dd}t |¡}|g d	¢ksbJ ‚d 	t 
|¡¡dksnJ ‚t||ƒsuJ ‚t||ƒs|J ‚t||ƒsƒJ ‚d S )
Nr   T©Úwith_labelsÚcompactÚ Úddid©r"   ©©r   r   ©r   r   )r   Úi©r   r   ©r#   )r   r   r   )r   r   r   ÚpytestÚraisesÚ
ValueErrorr   Úcreation_sequenceÚthreshold_graphÚjoinÚ	uncompactr   )	r   r   r   Úcs0ÚH0Úcs1ÚH1Úcs2ÚH2r   r   r   Útest_creation_sequences"   s$   ÿ



z.TestGeneratorThreshold.test_creation_sequencesc                 C   sP   t  g d¢¡g d¢ksJ ‚t  g d¢¡g d¢ksJ ‚t tt jg d¢¡s&J ‚d S )N©r   r   r   r*   r   r   ©r   r   r   ©g      @ç      ð?g       @)r   Úmake_compactr-   r.   Ú	TypeError©r   r   r   r   Útest_make_compact9   s   z(TestGeneratorThreshold.test_make_compactc                 C   sv   t  g d¢¡g d¢ksJ ‚t  g d¢¡g d¢ksJ ‚t  t  g d¢¡¡t  g d¢¡ks-J ‚t tt jg d¢¡s9J ‚d S )Nr<   r;   )r   r   r*   r   r'   r=   )r   r3   r-   r.   r@   rA   r   r   r   Útest_uncompact>   s   ÿþz%TestGeneratorThreshold.test_uncompactc                 C   s6   t  g d¢¡g d¢ksJ ‚t tt jg d¢¡sJ ‚d S )Nr<   )ç      à?rD   rD   g      Ð?ç      è?rE   r=   )r   Úcreation_sequence_to_weightsr-   r.   r@   rA   r   r   r   Ú!test_creation_sequence_to_weightsF   s   ÿz8TestGeneratorThreshold.test_creation_sequence_to_weightsc                 C   sx   g d¢}t  t¡ tj|ddd W d   ƒ n1 sw   Y  tj|ddg d¢ks.J ‚tj|dddgks:J ‚d S )Nr   Tr!   r&   ))r   r   r(   r)   r+   r,   é   )r-   r.   r/   r   Úweights_to_creation_sequence)r   r   r   r   r   Ú!test_weights_to_creation_sequenceS   s   ÿz8TestGeneratorThreshold.test_weights_to_creation_sequencec                 C   s&   t  ¡ }| dd¡ t |¡rJ ‚d S )Nr   r   )r   ÚGraphÚadd_edger   Úfind_alternating_4_cycle)r   r   r   r   r   Útest_find_alternating_4_cycle_   s   z4TestGeneratorThreshold.test_find_alternating_4_cyclec                 C   sl  g d¢}t j |¡}tj|dd}dD ]\}}t |||¡t  |||¡ks'J ‚qt |d¡}t dd„ |D ƒd¡}||ks?J ‚i }t|ƒD ]\}	}
||	 d	 }|
||< qE|t  |d¡ks^J ‚t g d
¢dd¡ddgksmJ ‚t g d¢dd¡ddgks|J ‚t	 
ttjg d¢dd¡sŠJ ‚t	 
ttjg d¢dd¡s˜J ‚t	 
ttjg d¢dd¡s¦J ‚t g d¢dd¡dgks´J ‚d S )Nr   Tr&   ))r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   c                 S   s   g | ]\}}|‘qS r   r   )r	   ÚvÚtr   r   r   Ú
<listcomp>l   ó    z=TestGeneratorThreshold.test_shortest_path.<locals>.<listcomp>r   r   r;   r   r<   r=   ÚaÚb)r   r   r   r   r0   Úshortest_pathÚshortest_path_lengthÚ	enumerateÚ"single_source_shortest_path_lengthr-   r.   r@   r/   )r   r   r   r6   r
   ÚmÚsplÚspl2ÚspldÚjÚplr   r   r   Útest_shortest_pathd   s&   "
 z)TestGeneratorThreshold.test_shortest_pathc                 C   sn   t  g d¢d¡g d¢ksJ ‚t  g d¢d¡g d¢ksJ ‚t  dd¡g d¢ks(J ‚t tt jg d¢d¡s5J ‚d S )Nr<   r   )r   r   r   r   r   r   r;   r=   )r   rV   r-   r.   r@   rU   rA   r   r   r   Útest_shortest_path_length|   s   z0TestGeneratorThreshold.test_shortest_path_lengthc                 C   sN   t t dd¡ƒdksJ ‚tjddddg d¢ksJ ‚t ttjdd¡s%J ‚d S )Nr   rD   é*   ©Úseed)
r   r*   r   r   r   r*   r*   r*   r   r   g      ø?)Úlenr   Úrandom_threshold_sequencer-   r.   r/   rA   r   r   r   Útest_random_threshold_sequence   s   z5TestGeneratorThreshold.test_random_threshold_sequencec                 C   ó2   t  dd¡g d¢ksJ ‚t tt jdd¡sJ ‚d S ©Nr   r   )r   r*   r   )r   Úright_d_threshold_sequencer-   r.   r/   rA   r   r   r   Útest_right_d_threshold_sequence    ó   z6TestGeneratorThreshold.test_right_d_threshold_sequencec                 C   rg   rh   )r   Úleft_d_threshold_sequencer-   r.   r/   rA   r   r   r   Útest_left_d_threshold_sequence¤   rk   z5TestGeneratorThreshold.test_left_d_threshold_sequencec                 C   s  g d¢}t j|dd}t  |¡}t  |¡}||ksJ ‚t  t  g d¢¡¡}|dd„ dD ƒks0J ‚t  g d¢¡}|dd„ dD ƒksBJ ‚t  ttd	ƒƒ¡}|d
d„ dD ƒksVJ ‚t  d	¡}|dd„ dD ƒksfJ ‚t  d¡}dd„ dD ƒ}tdd„ t||ƒD ƒƒdk s‚J ‚d S )N)
r   rH   r   r   é   é   rn   rH   rn   ro   r   )Ú	threshold)r   r   r   r   r   r   r   c                 S   ó   g | ]}|d  ‘qS ©g      À?r   ©r	   Úsr   r   r   rQ   °   ó    ÿzBTestGeneratorThreshold.test_weights_thresholds.<locals>.<listcomp>)rH   rH   rH   r   rn   rn   r   r   r   ro   ro   ro   r   r   é   rv   rv   c                 S   rq   rr   r   rs   r   r   r   rQ   µ   ru   Úddidiiidididic                 S   rq   ©gš™™™™™¹?r   rs   r   r   r   rQ   º   rR   )rn   rn   rH   ro   r   r   r   rv   r   é   r   é	   r   c                 S   rq   rx   r   rs   r   r   r   rQ   ½   rR   Úddidiiididididc                 S   s   g | ]}|d  ‘qS )é   r   rs   r   r   r   rQ   À   rR   )ro   ro   rn   rv   rH   rH   rH   ry   r   rz   r   r   r   é   c                 s   ó     | ]\}}t || ƒV  qd S r   ©Úabs©r	   Úcr   r   r   r   r   Á   ó   € zATestGeneratorThreshold.test_weights_thresholds.<locals>.<genexpr>ç›+¡†›„=)r   rI   rF   r3   r   rW   ÚsumÚzip)r   ÚwseqÚcsr8   Úwsr   r   r   Útest_weights_thresholds¨   s(   

ÿÿ

$z.TestGeneratorThreshold.test_weights_thresholdsc                 C   sÎ   t  dgdgdgdgdgdœ¡}| dd¡ | dd¡ | dd¡ | dd¡ | dd¡ t |¡g d¢ks9J ‚t |¡}t |¡sEJ ‚t| ¡ ƒg d	¢ksQJ ‚tj	t
| ¡ ƒd
d}t |¡|kseJ ‚d S )Nr   r   rH   rn   ro   )r   r   r   rH   rn   rv   )r   r   r   ro   )r   r   r   rH   rn   rv   Tr&   )r   rK   rL   r   rM   Úfind_threshold_graphr   ÚsortedÚnodesr0   Údictr   Úfind_creation_sequence)r   r   ÚTGrˆ   r   r   r   Útest_finding_routinesÃ   s    
z,TestGeneratorThreshold.test_finding_routinesc                 C   s   d}t  |¡}t  d¡t |¡ksJ ‚tt  |¡ƒtdd„ | ¡ D ƒƒks'J ‚t  |¡}|tt 	|¡ 
¡ ƒks9J ‚t|ƒd t  	|¡ksFJ ‚t  |¡}tt |¡ 
¡ ƒ}tdd„ t||ƒD ƒƒtjdddksiJ ‚t |¡ 
¡ }t  |¡}td	d„ t||ƒD ƒƒd
k s…J ‚t  |¡g d¢ksJ ‚tt  |¡d ƒdk sJ ‚t  d¡dks¦J ‚t  d¡dks¯J ‚t  d¡dks¸J ‚t  d¡g d¢ksÃJ ‚t  d¡g d¢ksÎJ ‚d S )NÚddiiddidc                 s   r   r   r   r   r   r   r   r   Ú   r   zXTestGeneratorThreshold.test_fast_versions_properties_threshold_graphs.<locals>.<genexpr>r   c                 s   r~   r   r   r   r   r   r   r   â   rƒ   r   gH¯¼šò×z>r   c                 s   r~   r   r   r   r   r   r   r   æ   rƒ   r„   )r   r   r   r   rn   rv   rv   ry   g! 1,úâ?gê-™—q=Údiiiddigš™™™™™é¿Údidg      ð¿Údddr>   Údddiii)r   r   r   r   r   r   Údddiiid)r   r   r   r   rH   rH   rv   )r   r1   Údensityr   rŒ   Údegree_sequencer   Útriangle_sequencer   Ú	trianglesÚvaluesr…   Úcluster_sequenceÚ
clusteringr†   r-   ÚapproxÚbetweenness_centralityÚbetweenness_sequenceÚeigenvaluesr€   Údegree_correlation)r   rˆ   r   ÚtsÚc1Úc2Úb1Úb2r   r   r   Ú.test_fast_versions_properties_threshold_graphsÖ   s(   
(

*
 zETestGeneratorThreshold.test_fast_versions_properties_threshold_graphsc                 C   s<   t  dd¡}t  dd¡}t  |dd¡}t j|dddd}d S )Nrn   rv   r>   r   rb   )r   rl   ri   Úswap_d)r   rt   Ús1r   r   r   Útest_tg_creation_routinesò   s   z0TestGeneratorThreshold.test_tg_creation_routinesc                    sf   t  d¡‰ ˆ jj}t  d¡ d}t |¡}t |¡\}}ˆ jj‡ fdd„|D ƒddd t	 
|¡}d S )	NÚnumpyÚscipyr’   c                    s   g | ]}ˆ   ||¡‘qS r   )Údot)r	   Úlv©Únpr   r   rQ      s    z<TestGeneratorThreshold.test_eigenvectors.<locals>.<listcomp>r>   g•Ö&è.>)Úrtol)r-   ÚimportorskipÚlinalgÚeigvalsr   r1   ÚeigenvectorsÚtestingÚassert_allcloser   Úlaplacian_matrix)r   Úeigenvalrˆ   r   ÚtgevalÚtgevecÚlaplr   r±   r   Útest_eigenvectorsø   s   


 z(TestGeneratorThreshold.test_eigenvectorsc                 C   s`   d}t  |¡}tjtjjt j|t ¡ dsJ ‚t j|t ¡ d}t	| 
¡ ƒt	| 
¡ ƒks.J ‚d S )Nr’   )Úcreate_using)r   r1   r-   r.   r   Ú	exceptionÚNetworkXErrorÚDiGraphÚ
MultiGraphrŒ   Úedges)r   rˆ   r   ÚMGr   r   r   Útest_create_using  s   

ü z(TestGeneratorThreshold.test_create_usingN)Ú__name__Ú
__module__Ú__qualname__r    r:   rB   rC   rG   rJ   rN   r_   r`   rf   rj   rm   rŠ   r‘   r©   r¬   r¿   rÇ   r   r   r   r   r      s&    r   )Ú__doc__r-   Únetworkxr   Únetworkx.algorithms.thresholdÚ
algorithmsrp   r   Ú(networkx.algorithms.isomorphism.isomorphr   Úconvert_node_labels_to_integersÚcnltir   r   r   r   r   Ú<module>   s    