
    Vh#                         d dl Z d dlmZmZmZ d dlmZ d dlZd dlZ	d dl
mZmZ d Z G d d      Zd Zd	 Zd
 Zd Zd Z G d d      Z G d d      Zd Z G d d      Z G d d      Zy)    N)chainislicetee)inf)FORWARDREVERSEc                    t        |       dk(  ry t        j                  d      }t        j                  d      }t        j                         }| D ]  }t        j
                  ||        t        j                  |d      }|j                  j                  |j                         d d      }|j                  d   |z
  t        |       k(  sJ y )	Nr   numpyscipyT)orientedF)tol	hermitian   )lenpytestimportorskipnxGraph	add_cycleincidence_matrixlinalgmatrix_ranktoarrayshape)basisnpspHbincranks          U/home/dcms/DCMS/lib/python3.12/site-packages/networkx/algorithms/tests/test_cycles.pycheck_independentr#      s    
5zQ			W	%B			W	%B

A 
Q


a$
/C99  DE JD99Q<$#e*,,,    c                   v    e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zy)
TestCyclesc                     t        j                         }t        j                  |g d       t        j                  |g d       t        j                  |g d       |j                  dd       || _        y )Nr   r         r   r*         r   r            r1   	   )r   r   r   add_edgeG)clsr4   s     r"   setup_classzTestCycles.setup_class   sL    HHJ
Q%
Q%
Q(	

1ar$   c                     t        |      t              k7  ry||z   t        fdt              D              S )NFc              3   4   K   | ]  }||z    k(    y wN ).0ir   lns     r"   	<genexpr>z3TestCycles.is_cyclic_permutation.<locals>.<genexpr>)   s      71QQ<1$7s   )r   anyrange)selfar   r=   r>   s     `@@r"   is_cyclic_permutationz TestCycles.is_cyclic_permutation$   s8    Fq6Q;E7eAh777r$   c                 4   | j                   }t        j                  |d      }t        d |D              }|g dg dg dgk(  sJ t        j                  |d      }t        d |D              }|g dg dg dgk(  sJ t        j                  |d      }t        d	 |D              }|g dg dg dgk(  sJ t        j                  |d
       t        j                  |d      }t        d |d d D              t        |d         gz   }|g dg dg dg dgk(  sJ y )Nr   c              3   2   K   | ]  }t        |        y wr9   sortedr;   cs     r"   r?   z.TestCycles.test_cycle_basis.<locals>.<genexpr>.        /q/   r(   r.   r+   r   c              3   2   K   | ]  }t        |        y wr9   rG   rI   s     r"   r?   z.TestCycles.test_cycle_basis.<locals>.<genexpr>1   rK   rL   r2   c              3   2   K   | ]  }t        |        y wr9   rG   rI   s     r"   r?   z.TestCycles.test_cycle_basis.<locals>.<genexpr>4   rK   rL   ABCc              3   2   K   | ]  }t        |        y wr9   rG   rI   s     r"   r?   z.TestCycles.test_cycle_basis.<locals>.<genexpr>9   s     4q4rL   )ABC)r4   r   cycle_basisrH   r   rB   r4   cysort_cys       r"   test_cycle_basiszTestCycles.test_cycle_basis+   s   FF^^Aq!/B//<,GGGG^^Aq!/B//<,GGGG^^Aq!/B//<,GGGG
Q^^Aq!4BsG44r"v7GG<,XXXXr$   c                     t        j                  t        j                        5  t        j                         }t        j
                  |d      }d d d        y # 1 sw Y   y xY wNr   )r   raisesr   NetworkXNotImplementedDiGraphrU   rB   r4   rW   s      r"   test_cycle_basis2zTestCycles.test_cycle_basis2<   sD    ]]2445 	&

A1%B	& 	& 	&   +AA!c                     t        j                  t        j                        5  t        j                         }t        j
                  |d      }d d d        y # 1 sw Y   y xY wr[   )r   r\   r   r]   
MultiGraphrU   r_   s      r"   test_cycle_basis3zTestCycles.test_cycle_basis3A   sD    ]]2445 	&A1%B	& 	& 	&ra   c                    t        j                  d      }|j                  t        j                  t        dd                   t        j                  |      }ddd}t        j
                  ||      }t        j                  |      D cg c]"  }|D cg c]  }|j                  ||       c}$ }}}||k(  sJ y c c}w c c}}w )Nr-   r*   r1   r   r   r   r   )r   cycle_graphupdaterA   rU   relabel_nodesget)rB   r4   cbGpermr   cycr>   cbHs           r"   test_cycle_basis_orderedz#TestCycles.test_cycle_basis_orderedF   s    NN1	a,-nnQ|Q%8:q8IJ,1A,JJczz -Js   	CB>.C>Cc                     t        j                         }t        j                  |g d       t        j                  |g d       t        j                  |      }t	        d |D              }|dgg dg dg dgk(  sJ y)	z-Tests the function for graphs with self loopsr(   )r   r   r/   r)   c              3   2   K   | ]  }t        |        y wr9   rG   rI   s     r"   r?   z8TestCycles.test_cycle_basis_self_loop.<locals>.<genexpr>W   rK   rL   r   r   r   r)   )r   r)   r*   )r   r)   r/   N)r   r   r   rU   rH   rV   s       r"   test_cycle_basis_self_loopz%TestCycles.test_cycle_basis_self_loopQ   s`    HHJ
Q%
Q%^^A/B//A3	9i@@@@r$   c                     g d}t        j                  |      }t        t        j                  |            }dgg dddgddgdgg}t	        |      t	        |      k(  sJ |D ]  t         fd|D              rJ  y )N)r   r   r   r   r   r)   r   r)   r)   r   r)   r   r)   r)   r   rr   r)   r   c              3   B   K   | ]  }j                  |        y wr9   rD   r;   rcrJ   rB   s     r"   r?   z0TestCycles.test_simple_cycles.<locals>.<genexpr>a        FRt11!R8F   )r   r^   rH   simple_cyclesr   r@   )rB   edgesr4   cccarJ   s   `    @r"   test_simple_cycleszTestCycles.test_simple_cyclesZ   s    HJJuB$$Q'(c9q!fq!fqc22w#b'!!! 	GAF2FFFF	Gr$   c                 z    t        j                  dg      }t        t        j                  |            dggk(  sJ y )Nru   r   )r   r   listr   rB   r4   s     r"   test_simple_cycles_singletonz'TestCycles.test_simple_cycles_singletonc   s4    HHfXB$$Q'(aSE111r$   c                     t        j                         }t        j                  |ddg       t        t        j                  |            }t        |      dk(  sJ y )NrC   r   )r   r^   r   r   r   r   rB   r4   rJ   s      r"   test_unsortablezTestCycles.test_unsortableg   sF     JJL
Qa!!!!$%1v{{r$   c                     t        j                         }t        j                  |g d       t        t        j                  |            t              dk(  sJ  j                  d   g d      sJ t        j                  |g d       t        t        j                  |            }t        |      dk(  sJ g dg dg}|D ]  t         fd|D              rJ  y )N)r   r)   r*   r   r   )
         r)   c              3   B   K   | ]  }j                  |        y wr9   r}   r~   s     r"   r?   z6TestCycles.test_simple_cycles_small.<locals>.<genexpr>z   r   r   )r   r^   r   rH   r   r   rD   r@   )rB   r4   r   r   rJ   s   `   @r"   test_simple_cycles_smallz#TestCycles.test_simple_cycles_smallo   s    JJL
Q	"2##A&'1v{{))!A$	:::
Q%B$$Q'(2w!||& 	GAF2FFFF	Gr$   c                 r    t        j                         }t        t        j                  |            g k(  sJ y r9   )r   r^   r   r   r   s     r"   test_simple_cycles_emptyz#TestCycles.test_simple_cycles_empty|   s+    JJLB$$Q'(B...r$   c                 n   t        j                         }t        d|dz         D ])  }|j                  d|       |j                  ||dz          + |j                  d|z  dz   d       t        |dz   d|z  dz         D ]/  }|j                  |d|z  dz          |j                  ||dz          1 |j                  d|z  dz   |dz          t        d|z  dz   d|z  dz         D ]2  }|j                  d|z  dz   |       |j                  |d|z  dz          4 |j                  d|z  dz   d|z  dz          |S )Nr)   r   r*   )r   r^   rA   r3   )rB   kr4   r>   s       r"   worst_case_graphzTestCycles.worst_case_graph   s=    JJLq!a% 	!AJJq!JJq!a% 	! 	


1q519a q1ua!eai( 	!AJJq!a%!)$JJq!a% 	! 	


1q519a!e$q1uqy!a%!), 	%AJJq1uqy!$JJq!a%!)$	% 	


1q519a!eai(r$   c                     t        dd      D ]D  }| j                  |      }t        t        t	        j
                  |                  }|d|z  k(  rDJ  y )Nr*   r   )rA   r   r   r   r   r   )rB   r   r4   r=   s       r"   test_worst_case_graphz TestCycles.test_worst_case_graph   sQ    q" 	A%%a(AD))!,-.AA::	r$   c                 p    t        dd      D ]  } j                  |      }t        t        j                  |            }t        t        j
                  |            }t        |      t        |      k(  sJ |D ]  t         fd|D              rJ  |D ]  t         fd|D              rJ   y )Nr)   r   c              3   B   K   | ]  }j                  |        y wr9   r}   )r;   rrJ   rB   s     r"   r?   z;TestCycles.test_recursive_simple_and_not.<locals>.<genexpr>   s     I455a;Ir   c              3   B   K   | ]  }j                  |        y wr9   r}   r;   rJ   r   rB   s     r"   r?   z;TestCycles.test_recursive_simple_and_not.<locals>.<genexpr>   s     I455b!<Ir   )rA   r   rH   r   r   recursive_simple_cyclesr   r@   )rB   r   r4   r   rccrJ   r   s   `    @@r"   test_recursive_simple_and_notz(TestCycles.test_recursive_simple_and_not   s    q" 	JA%%a(A((+,B33A67Cr7c#h&&& JISIIIIJ JIbIIIIJ	Jr$   c                     t        j                         }g d}|j                  |       t        t        j                  |            }t        |      dk(  sJ t        t        j                  |            }t        |      t        |      k(  sJ |D ]  t         fd|D              rJ  |D ]  t         fd|D              rJ  y )N)rw   )r   r*   rf   r   r*   rz   )r)   r,   r*   r)   r*   r,   )r,   r   )r,   r   r,   r-   r-   r   r-   r   )r-   r)   )r-   r*      c              3   B   K   | ]  }j                  |        y wr9   r}   r~   s     r"   r?   zATestCycles.test_simple_graph_with_reported_bug.<locals>.<genexpr>   s     GRt11!R8Gr   c              3   B   K   | ]  }j                  |        y wr9   r}   r   s     r"   r?   zATestCycles.test_simple_graph_with_reported_bug.<locals>.<genexpr>   s     EQt11"a8Er   )r   r^   add_edges_fromrH   r   r   r   r@   )rB   r4   r   r   r   rJ   r   s   `    @@r"   #test_simple_graph_with_reported_bugz.TestCycles.test_simple_graph_with_reported_bug   s    JJL
" 	
B$$Q'(2w"}}R//232w#c(""" 	HAG3GGGG	H 	FBE"EEEE	Fr$   N)__name__
__module____qualname__classmethodr6   rD   rY   r`   rd   ro   rs   r   r   r   r   r   r   r   r   r   r:   r$   r"   r&   r&      se     8Y"&
&
	AG2G/$	JFr$   r&   c                 N    t        |       \  }}t        |d        t        ||      S r9   )r   nextzip)iterablerC   r   s      r"   pairwiser      s$    x=DAqDMq!9r$   c           	      @    t        t        | t        | d                  S Nr   )r   r   r   rJ   s    r"   cycle_edgesr      s    E!VAq\*++r$   c                 *    t        t        |             S r9   )	frozensetr   r   s    r"   directed_cycle_edgesetr      s    [^$$r$   c                     t        |       dk(  rt        t        |             S t        t        t        t        |                   S r   r   r   r   mapr   s    r"   undirected_cycle_edgesetr      s2    
1v{Q((SKN344r$   c                     t        |       dk  rt        t        |             S t        t        t        t        |                   S )Nr)   r   r   s    r"   multigraph_cycle_edgesetr      s2    
1v{Q((YA788r$   c                       e Zd Zed        Zed        Zed        Zd Z	 	 	 ddZ	 	 	 ddZ	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestCycleEnumerationc                 ,    t        j                  |       S r9   )r   complete_graphr>   s    r"   KzTestCycleEnumeration.K   s      ##r$   c                 H    t        j                  |       j                         S r9   )r   r   to_directedr   s    r"   DzTestCycleEnumeration.D   s      #//11r$   c                 f    | j                         rt        S | j                         rt        S t        S r9   )is_directedr   is_multigraphr   r   )gs    r"   edgeset_functionz%TestCycleEnumeration.edgeset_function   s'    ==?))__++++r$   c	                    |t        |      |kD  rt        d| d|       |dk(  r"||v rt        d| d      t        |      ||<   n%||v r|j                  |       nt        d| d      t	        fd|D              st        | d| d	      |rBt        j                  |      j                        t        |      kD  rt        | d
| d      y y )Ncomputed cycle z exceeds length bound computedz has already been found!zexpected cycle z was not computedc              3   <   K   | ]  } j                   |   y wr9   has_edge)r;   er   s     r"   r?   z3TestCycleEnumeration.check_cycle.<locals>.<genexpr>  s     .a:1::q>.s   z claimed cycle z is not a cycle of gz cycle z is not chordless)r   RuntimeErrortuplepopallsubgraphr   )	rB   r   rJ   escachesource
original_clength_bound	chordlesss	    `       r"   check_cyclez TestCycleEnumeration.check_cycle   s   #A(=!*-CL>R  ZU{"%j\1IJ  "*-b	U{		""_ZL@Q#RSS.2..(/*5IJ  QZZ]001CF:&<MNOO ;9r$   Nc                 d   |"|rt         j                  nt         j                  }t        t	        t        |                  }t        j                  d      }|j                  |       t        t        ||            }t        t        ||            }	t        j                  ||d      }
| j                  |
      }i }|||d<   i } ||
fi |D ]4  }|D cg c]  }|	|   	 }} ||      }| j                  |
|||d|||       6 t        |t              r)t        |      |k7  rt!        d| dt        |             y |D ]4  }|D cg c]  }||   	 }} ||      }| j                  |
|||d|||       6 t        |      r$|j#                         D ]  }t!        d	| d
       y y c c}w c c}w )N*   T)copyr   r   z	expected z cycles, got expectedr   z, is valid but not in the expected cycle set!)r   chordless_cyclesr   r   rA   r   randomRandomshuffledictr   ri   r   r   
isinstanceintr   values)rB   r   expected_cyclesr   r   	algorithmrelabelrnglabelunlabelhedgesetparamscycle_cacherJ   xr   r   s                     r"   check_cycle_algorithmz*TestCycleEnumeration.check_cycle_algorithm  s    /8++b>N>NI uSV}%mmBGSG_%s7A'QD1''*#%1F>"1'' 	A./0'!*0J0B1b+z:|Y	 os+;?2"0c+>N=OP  ) 	J#-.aq.A.B1b+z:|Y	 { '') "%aS(TU  ' 1 /s   F(F-c                 X    t        ||      D ]  \  }}| j                  |||||        y )N)r   r   r   )r   r   )rB   g_familycycle_countsr   r   r   r   
num_cycless           r"   (check_cycle_enumeration_integer_sequencez=TestCycleEnumeration.check_cycle_enumeration_integer_sequence?  s@     !<8 	MAz&&)## ' 	r$   c                    t        j                         }t        j                  |t        d             t        j                  |t        d      d d d          |j	                  dd       g d}| j                  ||d       | j                  ||dd       |D cg c]  }t        |      dk  s| }}| j                  ||dd	       y c c}w )
Nr-   rQ   r   ))r   rx   r)   r*   r   Tr   r)   r   r   r   )r   r^   r   rA   r3   r   r   )rB   r   r   rJ   s       r"   $test_directed_chordless_cycle_digonsz9TestCycleEnumeration.test_directed_chordless_cycle_digonsP  s    JJL
Qa!
Qa2'	

1a8""1o"F""1oTU"V&5DQ!1DD""1oTU"V Es   C0Cc                     t        j                  g d      }dgdgg}| j                  ||d       |j                  g d       dgdgddgg}| j                  ||d       y )	N))r   r   r{   rx   rx   r   r)   Tr  )r  r   r   r   r*   r,   )r   rc   r   r   )rB   r4   r   s      r"   +test_chordless_cycles_multigraph_self_loopsz@TestCycleEnumeration.test_chordless_cycles_multigraph_self_loops]  sk    MM:;3*""1o"F	9:3aV,""1o"Fr$   c                    t        j                  g d      }ddg}| j                  ||d       t        j                         }t        j                  |t	        d             t        j                  |t	        dd             |j                  d	d
       g d}| j                  ||d       |j                  d
d	       g d}| j                  ||d       dg}| j                  ||dd       |j                  d	d
       ddg}| j                  ||d       t        j                  d t	        d      D              }g }| j                  ||d       y )N)rx   r  r   r   r   r   rw   )r   r)   r*   r,   r-   )r   r)   r*   r,   r-   Tr  r-   r,   r2   r0   r*   )r   r   r)   r*   r,   )r*   r,   r-   r/   r0   r,   r-   r/   r0   r1   )r  r*   r0   r  r  r  r  r  c              3   D   K   | ]  }t        |      D ]  }||f 
  y wr9   rA   )r;   r<   js      r"   r?   zPTestCycleEnumeration.test_directed_chordless_cycle_undirected.<locals>.<genexpr>}  s$     C!%(CQ1vCvC    r   )r   r^   r   r   rA   r3   remove_edge)rB   r   r   s      r"   (test_directed_chordless_cycle_undirectedz=TestCycleEnumeration.test_directed_chordless_cycle_undirectedf  s/   JJOP*O<""1o"FJJL
Qa!
Qa$	

1aM""1o"F	

1aD""1o"F!(""1oTU"V	a*O<""1o"FJJCuRyCC""1o"Fr$   c           	         t        j                         }t        j                  |t        d             t        j                  |t        dd             g t        d      g t        dd      g}| j	                  ||d       | j	                  ||D cg c]  }t        |      dk  s| c}dd       |j                  dd       |j                  g t        dd	             | j	                  ||d       | j	                  ||D cg c]  }t        |      dk  s| c}dd       |j                  dd       ddg|d
<   | j	                  ||d       | j	                  ||D cg c]  }t        |      dk  s| c}dd       |j                          |j                  dd       | j	                  ||d       | j	                  ||D cg c]  }t        |      dk  s| c}dd       y c c}w c c}w c c}w c c}w )Nr-   r,      Tr  r   r   r0   r*   r1   rQ   )
r   r^   r   rA   r   r   r3   appendr   r  rB   r4   r   rJ   s       r"   test_chordless_cycles_directedz3TestCycleEnumeration.test_chordless_cycles_directed  s   JJL
Qa!
Qa%eAhK5B<1""1h$"?""83as1v{3!t 	# 	
 	


1a%1+'""1h$"?""83as1v{3!t 	# 	
 	


1a1v""1h$"?""83as1v{3!t 	# 	
 		a""1h$"?""83as1v{3!t 	# 	
) 4 4 4 4s0   G2
'G2
G7
G7
'G<
;G<
H
#H
c                 D   t        d      D cg c]  }| j                  |       }}t        d      D cg c]  }||z  |z
  dz   }}| j                  ||d       t        d      D cg c]  }||z  |z
  dz   }}| j                  ||d       y c c}w c c}w c c}w )Nr   r)   Tr  r   )rA   r   r  )rB   r>   r   r   s       r"   &test_directed_chordless_cycle_dicliquez;TestCycleEnumeration.test_directed_chordless_cycle_diclique  s    ',Ry1!DFF1I115:2Y?AEAI!+??55o 	6 	
 6;2Y?AEAI!+??55oA 	6 	
 2?
 @s   BB*Bc                    t        j                  d t        d      D              }t        j                  |t        d             t        d      D cg c]  }|f }}| j	                  ||d       | j	                  ||d       t        j
                  |      }|j                  d t        ddd	      D               t        ddd	      D cg c]  }|f }}| j	                  ||d       y c c}w c c}w )
Nc              3   $   K   | ]  }||f 
 y wr9   r:   r;   r<   s     r"   r?   zMTestCycleEnumeration.test_directed_chordless_loop_blockade.<locals>.<genexpr>  s     1!1v1   r   Tr  r   r  c              3   $   K   | ]  }||f 
 y wr9   r:   r  s     r"   r?   zMTestCycleEnumeration.test_directed_chordless_loop_blockade.<locals>.<genexpr>  s     9A!Q9r   r   r)   )r   r^   rA   r   r   MultiDiGraphr   )rB   r   r<   r   s       r"   %test_directed_chordless_loop_blockadez:TestCycleEnumeration.test_directed_chordless_loop_blockade  s    JJ1uRy11
Qb	").r3AA433""1o"F""1oA"FOOA	9q"a99).q"a9AA499""1o"F 4 :s   
C.
C3c                    t        dd      D cg c]  }| j                  |       }}g d}| j                  ||d       d }t        dd      D cg c]  }| j                  |       }}|D cg c]  }d|z  	 }}| j                  ||d|       d }g d	}t        d
d      D cg c]  }| j                  |       }}| j                  ||d|       |D cg c]  }d|z  	 }}t        d
d      D cg c]  }| j                  |       }}| j                  ||d|       g d}t        d
d      D cg c]  }| j                  |       }}| j                  ||       g d}t        d      D cg c]  }| j                  |       }}| j                  ||       y c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w )Nr)   r  )r   r   r,   r   r   #   8   T   x         r*   r  c              ;   Z   K   d t        j                  | fi |D        E d {    y 7 w)Nc              3   >   K   | ]  }t        |      d k(  s|  ywr*   Nr   rI   s     r"   r?   zfTestCycleEnumeration.test_simple_cycles_notable_clique_sequences.<locals>.triangles.<locals>.<genexpr>       PaCFaKP   r   r   r   kwargss     r"   	triangleszSTestCycleEnumeration.test_simple_cycles_notable_clique_sequences.<locals>.triangles  $     P2#3#3A#@#@PPP   !+)+)r   r   c              ;   Z   K   d t        j                  | fi |D        E d {    y 7 w)Nc              3   >   K   | ]  }t        |      d k(  s|  yw)r,   Nr.  rI   s     r"   r?   zhTestCycleEnumeration.test_simple_cycles_notable_clique_sequences.<locals>.four_cycles.<locals>.<genexpr>  r/  r0  r1  r2  s     r"   four_cycleszUTestCycleEnumeration.test_simple_cycles_notable_clique_sequences.<locals>.four_cycles  r5  r6  )r   r   r   r*      -   i      iz  iv  i  r   r,   r:  )r   r   r-   r   r'  i  i=	  r1   )r   r   r   r   r0   %      i  rA   r   r  r   )rB   r>   r   r   r4  r   r9  s          r"   +test_simple_cycles_notable_clique_sequencesz@TestCycleEnumeration.test_simple_cycles_notable_clique_sequences  s   ',Q|4!DFF1I44?55hQ 	6 	
	Q (-Q|4!DFF1I44#+,aAE,,55hQ) 	6 	
	Q A',Q|4!DFF1I4455hQ+ 	6 	

 $,,aAE,,',Q|4!DFF1I4455hQ+ 	6 	

 0',Q{3!DFF1I3355hI 2',Qx0!DFF1I0055hIS 5 5, 5 -4 4
 1s/   F"F'0F,(F1F67F;8G 5Gc                    t        j                         }t        j                  |t        d             g t        d      g}| j	                  ||d       t        j                  |t        d             g t        t        d            }| j	                  ||d       t        j                  |t        d             g }| j	                  ||d       t        j                         }t        j                  |t        d             g t        d      g}| j	                  ||d       t        j                  |t        d             | j	                  |g d       t        j                  |t        d             | j	                  |g d       t        j                         }t        j                  |t        d             t        j                  |t        d      d d d          g t        t        d            }| j	                  ||d       t        j                  |t        d             | j	                  |g d       y )Nr-   Tr  rQ   )r   rc   r   rA   r   r   r"  )rB   r   r   s      r"   1test_directed_chordless_cycle_parallel_multiedgeszFTestCycleEnumeration.test_directed_chordless_cycle_parallel_multiedges  s   MMO
Qa!eAhK=""1h$"?
Qa!+[q*+""1h$"?
Qa!""1h$"?OO
Qa!eAhK=""1h$"?
Qa!""1bD"9
Qa!""1bD"9OO
Qa!
Qa2'+[q*+""1h$"?
Qa!""1bD"9r$   c           	         t        j                         }t        j                  |t        d             t        j                  |t        dd             g t        d      g t        dd      g}| j	                  ||d       | j	                  ||D cg c]  }t        |      dk  s| c}dd       |j                  dd       |j                  g t        dd	             |j                  g d
       | j	                  ||d       | j	                  ||D cg c]  }t        |      dk  s| c}dd       y c c}w c c}w )Nr-   r,   r  Tr  r  r0   r*   r1   )r,   r*   r0   r1   r2   r      )r   r   r   rA   r   r   r3   r  r  s       r"   test_chordless_cycles_graphz0TestCycleEnumeration.test_chordless_cycles_graph  s   HHJ
Qa!
Qa%eAhK5B<1""1h$"?""83as1v{3!t 	# 	
 	


1a%1+'/0""1h$"?""83as1v{3!t 	# 	
 4 4s   D>
'D>
E
/E
c           
      (   d}|dz  dk(  sJ t        j                         }t        |      D ]7  }|dz  s|j                  ||dz   |z         |j                  ||dz   |z         9 g t        d|d      gt        d|d      D cg c]"  }t        ||dz         D cg c]  }||z  	 c}$ c}}z   }| j	                  ||d       | j	                  ||D cg c]  }t        |      dk  s| c}dd       d	}|dz  dk(  sJ t        j                         }t        |      D ]8  }|j                  ||dz   |z         |dz  r!|j                  |dz   |z  |       : g t        |dz
  d
d
      gt        d|d      D cg c]"  }t        ||dz         D cg c]  }||z  	 c}$ c}}z   }| j	                  ||d       | j	                  ||D cg c]  }t        |      dk  s| c}dd       y c c}w c c}}w c c}w c c}w c c}}w c c}w )Ni  r)   r   r   r*   Tr  r  d   )r   r   rA   r3   r   r   r^   )rB   r>   r4   vr<   r   r   rJ   s           r"   'test_chordless_cycles_giant_hamiltonianz<TestCycleEnumeration.test_chordless_cycles_giant_hamiltonian  s%    1uzzHHJq 	'Aq5

1q1uk*JJq1q5A+&	'
 &eAq!n%&6;Aq!n*
12E!QUO,qQU,*
 
 	""1h$"?""83as1v{3!t 	# 	
 1uzzJJLq 	+AJJq1q5A+&q5

AEQ;*	+
 ,eAE2r*+,6;Aq!n0
12E!QUO,qQU,0
 
 	""1h$"?""83as1v{3!t 	# 	
9 -*

 4* -0

 4sH   G9G4'G9G?
*G?
 H	H"H	H
%H
4G9H	c                    d}t        j                  d t        |      D              }| j                  |g        | j                  |g d       t        |dz         D ]+  }| j                  |g |       | j                  |g |d       - y )Nr   c              3   D   K   | ]  }t        |      D ]  }||f 
  y wr9   r  )r;   r   ys      r"   r?   zMTestCycleEnumeration.test_simple_cycles_acyclic_tournament.<locals>.<genexpr>O  s$     B!qBA1vBvBr  Tr  r   r  r  )r   r^   rA   r   )rB   r>   r4   r   s       r"   %test_simple_cycles_acyclic_tournamentz:TestCycleEnumeration.test_simple_cycles_acyclic_tournamentM  s    JJBuQxBB""1b)""1bD"9q1u 	NA&&q"1&=&&q"1&M	Nr$   c                 (   t        j                  d      }t        t        d            }| j	                  ||g       |j                  dd       t        j                  |g d       | j	                  ||g       |j                  t        j                  t        dd                   t        t        dd            }| j	                  |||g       |j                  t        j                  t        dd                   t        t        dd            }h d}| j	                  ||       t        |      dk(  sJ t        j                  d      }|j                  t        j                  g d	      j                         d
}| j	                  ||       y )Nr1   r,   rQ   )r*   rI     r  >   r   r   r)   r*   r,   r-   r/   r0   r,   r-   r/   r0   r1   r2   r   rE  r1   r2   r   rE  r        r:  
r   r   r)   r*   r,   rE  r   r2   r1   r0   
r,   r-   r/   r0   r1   r:  rX  rW  r  rE  r   r   r)   r*   r,   rE  r  rW  rX  r:  r1   r0   r/   )r  r   rW  r)   rX  r,   r:  r1   r   )
r   rg   r   rA   r   r3   add_pathrh   r   r   )rB   testGcyc1cyc2cyc3r   s         r"   test_simple_cycles_graphz-TestCycleEnumeration.test_simple_cycles_graphW  s3   q!U1X""54&1q"
E?+""54&1R^^E!RL12U1b\"""54,7R^^E!RL12U1b\"
 	""5(38}..., r"R^^$ABHHI"""5(3r$   c           	      .   t        j                         }g }t        d      D ]Y  }t        j                  |t        |             |j	                  |       t        |      D ]  \  }}| j                  |||        [ t        j                         }d}g }t        d      D ]r  }|j	                  |dk  r|n|dz
         |dk(  r$t        j                  |t        |||z                ||z  }t        |      D ]  \  }}| j                  |||        t y )Nr   r  r   r)   r   )r   r^   rA   r   r  	enumerater   r   )rB   dr   r>   r   r   r   tops           r"   test_simple_cycles_boundedz/TestCycleEnumeration.test_simple_cycles_bounded  s    JJLr 	AALLE!H%OOA!(+ A1**1aa*@A	A HHJr 	AAOOQAAE2AvLLE#sQw/01HC!(+ A1**1aa*@A	Ar$   c                    t        j                  d      }t        j                  dt         j                        }t        t        j                  |d            g k(  sJ t        t        j                  |d            g k(  sJ t        t        j
                  |d            g k(  sJ t        t        j
                  |d            g k(  sJ y )Nr,   )create_usingr   r  )r   rg   r^   r   r   r   )rB   r4   DGs      r"   %test_simple_cycles_bound_corner_casesz:TestCycleEnumeration.test_simple_cycles_bound_corner_cases  s    NN1^^ABJJ7B$$QQ78B>>>B$$Ra89R???B'':;rAAAB'';<BBBr$   c                    t        j                  t              5  t        j                         }t        j
                  |d      D ]  }J  	 d d d        t        j                  t              5  t        j                         }t        j
                  |d      D ]  }J  	 d d d        t        j                  t              5  t        j                         }t        j                  |d      D ]  }J  	 d d d        t        j                  t              5  t        j                         }t        j                  |d      D ]  }J  	 d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   vxY w# 1 sw Y   y xY w)NrQ   )r   r\   
ValueErrorr   r^   r   r   r   r   s      r"   test_simple_cycles_bound_errorz3TestCycleEnumeration.test_simple_cycles_bound_error  sA   ]]:& 	

A%%a, u	
 ]]:& 	
A%%a, u	
 ]]:& 	
A((B/ u	
 ]]:& 	

A((B/ u	 		 	
	 	
	 	
	 	s/   1E-1E 1E'1E3EE$'E03E<c                 Z   t        dd      D cg c]  }| j                  |       }}g d}| j                  ||d       t        d      D cg c]  }||z  |z
  dz   }}t        d      D cg c]  }| j                  |       }}| j                  ||d       y c c}w c c}w c c}w )Nr)   r:  )r   r   r,   r   r   r%  r&  r'  r(  r)  r*  i  il  Tr  r@  )rB   r>   r   r   s       r"   test_chordless_cycles_cliquez1TestCycleEnumeration.test_chordless_cycles_clique  s    ',Q|4!DFF1I44I55h$ 	6 	

 /4Bi8QUQY1$88',Ry1!DFF1I1155h$ 	6 	
 5 91s   BB#/B()NFN)r   r   r   staticmethodr   r   r   r   r   r  r  r	  r  r  r  r#  rA  rC  rF  rK  rO  ra  rf  rj  rm  ro  r:   r$   r"   r   r      s    $ $ 2 2 , ,P: 5v "WGG6
>

G+JZ#:J
$.
`N14fA4C*
r$   r   c                       e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zy)TestFindCyclec                 (    g d| _         g d| _        y )Nr(   ))rQ   r   rv   rf   rf   rz   r*   r   )nodesr   )r5   s    r"   r6   zTestFindCycle.setup_class  s     	E	r$   c                     t        j                  | j                        }t        j                  t         j
                  j                  t         j                  || j                         y r9   )	r   r   r   r   r\   	exceptionNetworkXNoCycle
find_cycleru  r   s     r"   test_graph_nocyclez TestFindCycle.test_graph_nocycle  s8    HHTZZ bll22BMM1djjQr$   c                     t        j                  | j                        }|j                  dd       t	        t        j
                  || j                              }g d}||k(  sJ y )Nr)   r   rv   rx   ry   r   r   r   r3   r   ry  ru  rB   r4   r   x_s       r"   test_graph_cyclezTestFindCycle.test_graph_cycle  sK    HHTZZ 	

1aq$**-.%Bwwr$   c                     t        j                  | j                        }|j                  dd       t	        t        j
                  || j                  d             }g d}||k(  sJ y )Nr)   r   orientationr|  r}  r~  s       r"   test_graph_orientation_nonez)TestFindCycle.test_graph_orientation_none  sM    HHTZZ 	

1aq$**$?@%Bwwr$   c                     t        j                  | j                        }|j                  dd       t	        t        j
                  || j                  d            }ddt        fddt        fddt        fg}||k(  sJ y )Nr)   r   originalr  r   )r   r   r   r3   r   ry  ru  r   r~  s       r"   test_graph_orientation_originalz-TestFindCycle.test_graph_orientation_original  sf    HHTZZ 	

1aq$***EF!Wo1gAw@Bwwr$   c                     t        j                  | j                        }t        t        j                  || j
                              }ddg}||k(  sJ y )Nrv   rf   r   r^   r   r   ry  ru  r~  s       r"   test_digraphzTestFindCycle.test_digraph  sB    JJtzz"q$**-.fBwwr$   c                     t        j                  | j                        }t        t        j                  || j
                  d             }ddg}||k(  sJ y )Nr  rv   rf   r  r~  s       r"   test_digraph_orientation_nonez+TestFindCycle.test_digraph_orientation_none  sD    JJtzz"q$**$?@fBwwr$   c                     t        j                  | j                        }t        t        j                  || j
                  d            }ddt        fddt        fg}||k(  sJ y )Nr  r  r   r   r   r^   r   r   ry  ru  r   r~  s       r"   !test_digraph_orientation_originalz/TestFindCycle.test_digraph_orientation_original   sP    JJtzz"q$***EF!Wo1g/Bwwr$   c                     t        j                  | j                        }t        t        j                  || j
                              }ddg}|d   |d   k(  sJ |d   d d |d   d d k(  sJ y )Nr   r   r   )r   r   r   r   r   r)   )r   rc   r   r   ry  ru  r~  s       r"   test_multigraphzTestFindCycle.test_multigraph  sm    MM$**%q$**-.#tr!u}}tBQx2a5!9$$$r$   c                     t        j                  | j                        }t        t        j                  || j
                              }ddg}|d   |d   k(  sJ |d   d d |d   d d k(  sJ y )Nr  )r   r   r   r   r   r)   )r   r"  r   r   ry  ru  r~  s       r"   test_multidigraphzTestFindCycle.test_multidigraph  sm    OODJJ'q$**-.#tr!u}}tBQx2a5!9$$$r$   c                     t        j                  | j                        }t        t        j                  || j
                  d            }ddt        fddt        fg}||k(  sJ y )Nignorer  r   r   r  r~  s       r"   test_digraph_ignorez!TestFindCycle.test_digraph_ignore  sP    JJtzz"q$**(CD!Wo1g/Bwwr$   c                     t        j                  | j                        }t        t        j                  || j
                  d            }ddt        fddt        fg}||k(  sJ y )Nreverser  r   r   )r   r^   r   r   ry  ru  r   r~  s       r"   test_digraph_reversez"TestFindCycle.test_digraph_reverse  sP    JJtzz"q$**)DE!Wo1g/Bwwr$   c                 &   t        j                  | j                        }t        t        j                  || j
                  d            }dddt        fdddt        fg}|d   |d   k(  sJ |d   d d |d   d d k(  sJ |d   d   |d   d   k(  sJ y )Nr  r  r   r   r)   r*   )r   r"  r   r   ry  ru  r   r~  s       r"   test_multidigraph_ignorez&TestFindCycle.test_multidigraph_ignore!  s    OODJJ'q$**(CD!Q 1aG"45tr!u}}tBQx2a5!9$$$tAw"Q%("""r$   c                     t        j                  g d      }t        t        j                  |g dd            }dddt        fdddt
        fg}||k(  sJ y )N)rv   rx   rx   rr   r  r  r   r)   r   )r   r"  r   ry  r   r   r~  s       r"   test_multidigraph_ignore2z'TestFindCycle.test_multidigraph_ignore2)  sO    OO45q)BC!Q 1aG"45Bwwr$   c                     t        j                  g d      }t        j                  t         j                  j
                  t         j                  |g dd       y )N)rv   rx   r  )r,   r)   r  r  r  )r   r"  r   r\   rw  rx  ry  r   s     r"   test_multidigraph_originalz(TestFindCycle.test_multidigraph_original0  s<    
 OO<=LL((MM"	
r$   c                 .   t        j                  g d      }t        j                  t         j                  j
                  t         j                  |d       t        t        j                  |d            }|ddt        fddt        fddt        fgk(  sJ y )N)rv   rw   rx   r  r  r  r   r   r)   )
r   r^   r   r\   rw  rx  ry  r   r   r   )rB   r4   r   s      r"   test_dagzTestFindCycle.test_dag>  sr    JJ/0LL(("--
	
 qh78aG_q!Wo1gGGGGr$   c                    t        j                         }|j                  g d       t        j                  t         j
                  t         j                  |d       t        t        j                  |d            }ddg}||k(  sJ t        t        j                  |d            }ddg}||k(  sJ t        t        j                  |            }ddg}||k(  sJ y )N)rf   ry   rx   rz   r   r   r   rx   rz   r)   )r   r^   r   r   r\   rx  ry  r   r~  s       r"   test_prev_exploredz TestFindCycle.test_prev_exploredF  s     JJL	9:b(("--1Eq!$%fBwwq!$%fBwwq!"fBwwr$   c                 "   t        j                         }|j                  g d       t        j                  t         j
                  t         j                  |d       t        j                  t         j
                  t         j                  |       y )N)rx   ry   rt  r   r   r  )r   r^   r   r   r\   rx  ry  r   s     r"   test_no_cyclezTestFindCycle.test_no_cycleX  sT     JJL	9:b(("--1Eb(("--;r$   N)r   r   r   r   r6   rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r:   r$   r"   rr  rr    sm    F FR%%#
H$<r$   rr  c                 6    t        |       t        |      k(  sJ y r9   rG   )rC   r   s     r"   assert_basis_equalr  a  s    !9q	!!!r$   c                   L    e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zy
)TestMinimumCycleBasisc                     t        j                         }t        j                  |g dd       |j                  ddd       || _        y )N)r   r)   r*   r,   r   weightr)   r,   r-   )r   r   r   r3   diamond_graph)r5   Ts     r"   r6   z!TestMinimumCycleBasis.setup_classf  s7    HHJ
QQ/	

1a
"r$   c                 f    t        j                  | j                        }t        |g dg dg       y )Nr)   r,   r   )r*   r,   r)   r   minimum_cycle_basisr  r  rB   mcbs     r"   test_unweighted_diamondz-TestMinimumCycleBasis.test_unweighted_diamondm  s'    $$T%7%783I 67r$   c                 j    t        j                  | j                  d      }t        |g dg dg       y )Nr  r  r  )r,   r*   r)   r   r  r  s     r"   test_weighted_diamondz+TestMinimumCycleBasis.test_weighted_diamondq  s)    $$T%7%7I3L 9:r$   c                 6   d}t        dd|z         D ]  }t        j                  dd|      }|j                         }|j	                         }t        j
                  |      }t        j                  |      }t        |      ||z
  |z   k(  sJ t        |        y )Nr   i  g333333?seed)	rA   r   erdos_renyi_graphnumber_of_nodesnumber_of_edgesnumber_connected_componentsr  r   r#   )rB   ntrialr  rgnnodesnedgesncompr  s           r"   test_dimensionalityz)TestMinimumCycleBasis.test_dimensionalityu  s    $v. 	#D%%b#D9B'')F'')F2226E((,Cs8v6666c"	#r$   c                     t        j                  d      }t        j                  |      }t        d |D              sJ t	        |       y )Nr-   c              3   8   K   | ]  }t        |      d k(    ywr-  r.  )r;   cycles     r"   r?   z<TestMinimumCycleBasis.test_complete_graph.<locals>.<genexpr>  s     4u3u:?4s   )r   r   r  r   r#   )rB   cgr  s      r"   test_complete_graphz)TestMinimumCycleBasis.test_complete_graph  s>    q!$$R(44444#r$   c                 ^    t        j                  dd      }t        j                  |      rJ y )Nr*   )r   balanced_treer  )rB   tgs     r"   test_tree_graphz%TestMinimumCycleBasis.test_tree_graph  s+    a#))"----r$   c                    t        j                         t        t        j                              }g dg dg dg dg dg dgt	        |      t	              k(  sJ t        fd|D              sJ |D ]7  }t        fdt         j                  j                  |d	
      D              r7J  t        |       y )N)r,   r2   r0   r-   r   )r   r)   r*   r,   r   )r   r/   r1   r-   r   )r,   r*   r1   r-   r   )r   r/   r2   r,   r   )r   r)   r0   r-   r   c              3   &   K   | ]  }|v  
 y wr9   r:   r;   rJ   r   s     r"   r?   z<TestMinimumCycleBasis.test_petersen_graph.<locals>.<genexpr>       .Q1=.   c              3   H   K   | ]  \  }}j                  ||        y wr9   r   )r;   urJ  r4   s      r"   r?   z<TestMinimumCycleBasis.test_petersen_graph.<locals>.<genexpr>  s      VDAqqzz!Q'Vs   "T)cyclic)	r   petersen_graphr   r  r   r   utilsr   r#   )rB   r  rJ   r4   r   s      @@r"   test_petersen_graphz)TestMinimumCycleBasis.test_petersen_graph  s    2))!,-
 3x3x=(((.#....  	WAVBHH4E4EaPT4E4UVVVV	W 	#r$   c           	      x   d}t        j                  |      }|j                  |j                  D cg c]
  \  }}||df c}}       |j                  t        j                  |      j                  D cg c]
  \  }}||df c}}       t        j
                  |d      }t        |       y c c}}w c c}}w )Nr1   r2   r   r  r  )r   r   add_weighted_edges_fromr   rg   r  r#   )rB   Nr  r  rJ  r  s         r"   ,test_gh6787_variable_weighted_complete_graphzBTestMinimumCycleBasis.test_gh6787_variable_weighted_complete_graph  s    q!
"""((#C$!QQ1I#CD
"""..:K:Q:Q#R$!QQ1I#RS$$R9# $D#Rs   B0
6B6
c                    t        j                  d      }|j                  ddgd       g dg dg dgt        t        j                  |d            }t        |      t              k(  sJ t        fd	|D              sJ g dg dg d
gt        t        j                  |            }t        |      t              k(  sJ t        fd|D              sJ y )Nr,   )r   r)   r   )r   r*   r   distr  )r   r*   r   )r*   r)   r   r   )r   r)   r   c              3   &   K   | ]  }|v  
 y wr9   r:   r  s     r"   r?   zMTestMinimumCycleBasis.test_gh6787_and_edge_attribute_names.<locals>.<genexpr>  r  r  )r*   r)   r   c              3   &   K   | ]  }|v  
 y wr9   r:   r  s     r"   r?   zMTestMinimumCycleBasis.test_gh6787_and_edge_attribute_names.<locals>.<genexpr>  r  r  )r   rg   r  r   r  r   r   )rB   r4   r  r   s      @r"   $test_gh6787_and_edge_attribute_namesz:TestMinimumCycleBasis.test_gh6787_and_edge_attribute_names  s    NN1	!!:z":6!J|Y72))!F;<3x3x=(((.#.... y)42))!,-3x3x=(((.#....r$   N)r   r   r   r   r6   r  r  r  r  r  r  r  r  r:   r$   r"   r  r  e  s<     8;#.(/r$   r  c                      e Zd Zej                  j                  d ej                         df ej                         df ej                         df ej                         df ej                         df ej                  dd      ef ej                  d      ef ej                   e e ed             e edd                        df ej                  g d      d	ff	      d
        Zy)	TestGirth)r4   r   r,   r-   r/   r   r   r  ))r   r/   )r   r1   )r   r2   )r   r1   )r)   r1   )r)   r2   )r,   r2   )r-   r2   )r/   r1   )r/   r2   )r0   r1   r*   c                 8    t        j                  |      |k(  sJ y r9   )r   girth)rB   r4   r   s      r"   
test_girthzTestGirth.test_girth  s    @ xx{h&&&r$   N)r   r   r   r   markparametrizer   chvatal_graphtutte_graphr  heawood_graphpappus_graphrandom_labeled_treer   empty_graphr   r   r   rA   r  r:   r$   r"   r  r    s    [[R#R^^q!R !$R#R__"#R##BR0#6R^^B%RXXeKa1;uQ|3LMNPQR !	
>'?>'r$   r  )r   	itertoolsr   r   r   mathr   r   networkxr   %networkx.algorithms.traversal.edgedfsr   r   r#   r&   r   r   r   r   r   r   rr  r  r  r  r:   r$   r"   <module>r     s}     ( (    B-eF eFP,%59p
 p
pI< I<X"O/ O/d!' !'r$   