+
    �°³jˆ7  ã                   óÐ  € R t ^ RIHt ^ RIHtHt ^ RIt^ RIH	t	 . ROt
RtRt]! ]4       U Uu/ uF  w  rV ]V^,
          ,          bK  	  upp tR t]	! R4      ]P                   RR l4       4       t]P                   R 4       t]	! R4      ]P                   ! R	R
7      R 4       4       t]	! R4      ]P                   R 4       4       t]	! R4      ]P                   R 4       4       tR# u upp i )z*Functions for analyzing triads of a graph.)Údefaultdict)ÚcombinationsÚpermutationsN)Únot_implemented_forc                óV   a € W^3W!^3W^3W1^3W#^3W2^ 33p\        V 3R lV 4       4      # )záReturns the integer code of the given triad.

This is some fancy magic that comes from Batagelj and Mrvar's paper. It
treats each edge joining a pair of `v`, `u`, and `w` as a bit in
the binary representation of an integer.

c              3   óL   <"  € T F  w  rq2SV,          9   g   K  Vx € K  	  R # 5i©N© )Ú.0ÚuÚvÚxÚGs   &   €Ú[/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/triads.pyÚ	<genexpr>Ú_tricode.<locals>.<genexpr>~   s   øé € Ð4¡‘W�Q˜1¨q°­t©)�qŠq£ùs   ƒ$š
$)Úsum)r   r   r   ÚwÚcomboss   f&&& r   Ú_tricoder   u   s@   ø€ ð �Qˆi˜! ˜ Q¨1 I°°a¨y¸1À¸*ÀqÈRÀjÐQ€FÜÔ4¡Ó4Ó4Ð4ó    Ú
undirectedc           	     ó
  aa a!a"€ \        V P                  V4      4      o!Ve%   \        V4      \        S!4      8w  d   \        R4      h\        V 4      oS\        S!4      ,
          p\	        S!4       UUu/ uF  w  r4WCbK	  	  pppV'       d8   V P
                  S!,
          pVP                  V3R l\	        V4       4       4       V  Uu/ uFJ  qDV P                  V,          P                  4       V P                  V,          P                  4       ,          bKL  	  ppV  Uu/ uFJ  qDV P                  V,          P                  4       V P                  V,          P                  4       ,          bKL  	  upo V'       d–   X Uu/ uFJ  qDV P                  V,          P                  4       V P                  V,          P                  4       ,          bKL  	  upo"\        V!V"3R lV 4       4      pV^,          p	\        V V!3R lV 4       4      p
V
^,          p\         Uu/ uF  qÌ^ bK  	  ppS! EFJ  pW~,          pS V,          pV'       d	   ^ ;p;p;ppV EF¿  pVV,          W^,          8:  d   K  VV,          pVV,          VV0,
          pV F}  pVV,          VV,          8  g9   W^,          VV,          u;8  d   VV,          8  g   K=  M KA  WçV,          9  g   KP  \        WVV4      pV\        V,          ;;,          ^,          uu&   K  	  VV9   d.   VR;;,          S\        V4      ,
          ^,
          ,          uu&   M,VR;;,          S\        V4      ,
          ^,
          ,          uu&   V'       g   EK#  VS!9  g   EK-  S"V,          pX\        VVS!,
          ,          4      ,          pX\        VV,
          S!,
          4      ,          pS V,          pX\        VVS!,
          ,          4      ,          pX\        VV,
          S!,
          4      ,          pEKÂ  	  V'       g   EKö  VR;;,          X	XX^,          ,           ,
          ,          uu&   VR;;,          XXX^,          ,           ,
          ,          uu&   EKM  	  SS^,
          ,          S^,
          ,          ^,          pW"^,
          ,          V^,
          ,          ^,          pVV,
          pV\        VP                  4       4      ,
          VR&   V# u uppi u upi u upi u upi u upi )a…  Determines the triadic census of a directed graph.

The triadic census is a count of how many of the 16 possible types of
triads are present in a directed graph. If a list of nodes is passed, then
only those triads are taken into account which have elements of nodelist in them.

Parameters
----------
G : digraph
   A NetworkX DiGraph
nodelist : list
    List of nodes for which you want to calculate triadic census

Returns
-------
census : dict
   Dictionary with triad type as keys and number of occurrences as values.

Examples
--------
>>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1), (3, 4), (4, 1), (4, 2)])
>>> triadic_census = nx.triadic_census(G)
>>> for key, value in triadic_census.items():
...     print(f"{key}: {value}")
003: 0
012: 0
102: 0
021D: 0
021U: 0
021C: 0
111D: 0
111U: 0
030T: 2
030C: 2
201: 0
120D: 0
120U: 0
120C: 0
210: 0
300: 0

Notes
-----
This algorithm has complexity $O(m)$ where $m$ is the number of edges in
the graph.

For undirected graphs, the triadic census can be computed by first converting
the graph into a directed graph using the ``G.to_directed()`` method.
After this conversion, only the triad types 003, 102, 201 and 300 will be
present in the undirected scenario.

Raises
------
ValueError
    If `nodelist` contains duplicate nodes or nodes not in `G`.
    If you want to ignore this you can preprocess with `set(nodelist) & G.nodes`

See also
--------
triad_graph

References
----------
.. [1] Vladimir Batagelj and Andrej Mrvar, A subquadratic triad census
    algorithm for large sparse networks with small maximum degree,
    University of Ljubljana,
    http://vlado.fmf.uni-lj.si/pub/networks/doc/triads/triads.pdf

z3nodelist includes duplicate nodes or nodes not in Gc              3   ó<   <"  € T F  w  rW!S,           3x € K  	  R # 5ir   r	   )r
   ÚiÚnÚNs   &  €r   r   Ú!triadic_census.<locals>.<genexpr>Õ   s   øé € Ð?Ñ(>¡ �!˜•U•Ó(>ùs   ƒc              3   óX   <"  € T F  pSV,           F  q"S9  g   K  ^x € K  	  K!  	  R# 5i©é   Nr	   )r
   r   ÚnbrÚnodesetÚsgl_nbrss   &  €€r   r   r   à   ó&   øé € ÐV™[˜°H¸Q·K°K¨SÈgÑCU—!’!±K‘!›[ùó   ƒ*œ*c              3   óX   <"  € T F  pSV,           F  q"S9  g   K  ^x € K  	  K!  	  R# 5ir   r	   )r
   r   r!   Údbl_nbrsr"   s   &  €€r   r   r   â   r$   r%   Ú102Ú012Ú003)ÚsetÚnbunch_iterÚlenÚ
ValueErrorÚ	enumerateÚnodesÚupdateÚpredÚkeysÚsuccr   ÚTRIAD_NAMESr   ÚTRICODE_TO_NAMEÚvalues)#r   ÚnodelistÚNnotr   r   ÚmÚnot_nodesetÚnbrsÚsglÚsgl_edges_outsideÚdblÚdbl_edges_outsideÚnameÚcensusr   ÚvnbrsÚ	dbl_vnbrsÚsgl_unbrs_bdyÚsgl_unbrs_outÚdbl_unbrs_bdyÚdbl_unbrs_outr   ÚunbrsÚ	neighborsr   ÚcodeÚ	sgl_unbrsÚ	dbl_unbrsÚtotal_trianglesÚtriangles_without_nodesetÚtotal_censusr   r'   r"   r#   s#   &&                             @@@@r   Útriadic_censusrQ   �   sá  û€ ôP �!—-‘- Ó)Ó*€GØÒ¤ H£´°W³Ô =ÜÐNÓOÐOäˆA‹€AØŒs�7‹|Õ€Dô $ GÔ,Ô-Ñ,‘$�!ˆŠÑ,€AÑ-ßà—g‘g Õ'ˆØ	�‰Ô?¬	°+Ô(>Ó?Ô?ñ
 =>Ó>¹A°qˆq�v‰v�a�y�~‰~Ó !§&¡&¨¥)§.¡.Ó"2Õ2Ò2¹A€DÐ>Ù@AÓBÁ¸1�1—6‘6˜!•9—>‘>Ó# a§f¡f¨Q¥i§n¡nÓ&6Õ6Ò6ÁÑB€HçÙDOÓPÁK¸q�q—v‘v˜a•y—~‘~Ó'¨!¯&©&°­)¯.©.Ó*:Õ:Ò:ÁKÑPˆäÕV™[ÓVÓVˆØ 1�HÐÜÕV™[ÓVÓVˆØ 1�HÐõ #.Ó.¡+˜$�AŠg¡+€FÐ.äˆØ•ˆØ˜Q•Kˆ	ßàLMÐMˆMÐM˜MÐM¨M¸MÜˆAØ��t�q•tŒ|ÙØ˜•GˆEØ �¨1¨a¨&Õ0ˆIã�Ø�Q•4˜!˜A�$”; 1¥4¨!¨A­$Ö#5°°1µ×#5Ò#5¸!ÈÅ7Ö:JÜ# A¨!¨QÓ/�DØœ?¨4Õ0×1°QÕ6Õ1ñ ð �IŒ~Ø�u— ¤S¨£^Õ!3°aÕ!7Õ7”à�u— ¤S¨£^Õ!3°aÕ!7Õ7“÷
 Št˜ ×(Ø$ Q�K�	Ø¤ Y°¸µÕ%@Ó!AÕA�Ø¤ Y°Õ%6¸Õ%@Ó!AÕA�Ø$ Q�K�	Ø¤ Y°¸µÕ%@Ó!AÕA�Ø¤ Y°Õ%6¸Õ%@Ó!AÕA“ñ5 ÷8 Š4à�5�MÐ.°-À-ÐSTÕBTÕ2TÕUÕU‹MØ�5�MÐ.°-À-ÐSTÕBTÕ2TÕUÕUŽMñK ðR ˜A �E•{ a¨!¥eÕ,°Õ2€OØ!%°­Õ!2°d¸QµhÕ!?ÀAÕ EÐØ"Ð%>Õ>€LØ ¤3 v§}¡}£Ó#7Õ7€Fˆ5�Mà€MùóK 	.ùò ?ùÚBùò Qùò /s!   Á2S(ÃAS.ÄAS3Å:AS8ÈS=c                óf  a € \        S \        P                  4      '       d�   S P                  4       ^8X  d{   \        P                  ! S 4      '       d_   \
        ;QJ d-    V 3R lS P                  4        4       F  '       g   K   RM"	  RM! V 3R lS P                  4        4       4      '       g   R# R# )a0  Returns True if the graph G is a triad, else False.

Parameters
----------
G : graph
   A NetworkX Graph

Returns
-------
istriad : boolean
   Whether G is a valid triad

Examples
--------
>>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1)])
>>> nx.is_triad(G)
True
>>> G.add_edge(0, 1)
>>> nx.is_triad(G)
False
c              3   óL   <"  € T F  qV3SP                  4       9   x € K  	  R # 5ir   )Úedges)r
   r   r   s   & €r   r   Úis_triad.<locals>.<genexpr>2  s   øé € Ð>±I¨q˜1�v §¡£Ö*³Iùs   ƒ!$TF)Ú
isinstanceÚnxÚGraphÚorderÚis_directedÚanyr0   )r   s   fr   Úis_triadr\     sd   ø€ ô. �!”R—X‘X×ÒØ�7‰7‹9˜Œ>œbŸnšn¨Q×/Ò/ß“3Ô>°A·G±G´IÓ>—3—3’3Ô>°A·G±G´IÓ>×>Ò>ÙÙr   T)Úreturns_graphc              #  ó–   "  € \        V P                  4       ^4      pV F$  pV P                  V4      P                  4       x € K&  	  R# 5i)a»  A generator of all possible triads in G.

Parameters
----------
G : digraph
   A NetworkX DiGraph

Returns
-------
all_triads : generator of DiGraphs
   Generator of triads (order-3 DiGraphs)

Examples
--------
>>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1), (3, 4), (4, 1), (4, 2)])
>>> for triad in nx.all_triads(G):
...     print(triad.edges)
[(1, 2), (2, 3), (3, 1)]
[(1, 2), (4, 1), (4, 2)]
[(3, 1), (3, 4), (4, 1)]
[(2, 3), (3, 4), (4, 2)]

N)r   r0   ÚsubgraphÚcopy)r   ÚtripletsÚtriplets   &  r   Ú
all_triadsrc   7  s;   é € ô4 ˜AŸG™G›I qÓ)€HÛˆØ�j‰j˜Ó!×&Ñ&Ó(Ô(ó ùs   ‚AA	c                ó�   € \        V 4      p\        \        4      pV F%  p\        V4      pW$,          P	                  V4       K'  	  V# )aR  Returns a list of all triads for each triad type in a directed graph.
There are exactly 16 different types of triads possible. Suppose 1, 2, 3 are three
nodes, they will be classified as a particular triad type if their connections
are as follows:

- 003: 1, 2, 3
- 012: 1 -> 2, 3
- 102: 1 <-> 2, 3
- 021D: 1 <- 2 -> 3
- 021U: 1 -> 2 <- 3
- 021C: 1 -> 2 -> 3
- 111D: 1 <-> 2 <- 3
- 111U: 1 <-> 2 -> 3
- 030T: 1 -> 2 -> 3, 1 -> 3
- 030C: 1 <- 2 <- 3, 1 -> 3
- 201: 1 <-> 2 <-> 3
- 120D: 1 <- 2 -> 3, 1 <-> 3
- 120U: 1 -> 2 <- 3, 1 <-> 3
- 120C: 1 -> 2 -> 3, 1 <-> 3
- 210: 1 -> 2 <-> 3, 1 <-> 3
- 300: 1 <-> 2 <-> 3, 1 <-> 3

Refer to the :doc:`example gallery </auto_examples/graph/plot_triad_types>`
for visual examples of the triad types.

Parameters
----------
G : digraph
   A NetworkX DiGraph

Returns
-------
tri_by_type : dict
   Dictionary with triad types as keys and lists of triads as values.

Examples
--------
>>> G = nx.DiGraph([(1, 2), (1, 3), (2, 3), (3, 1), (5, 6), (5, 4), (6, 7)])
>>> dict = nx.triads_by_type(G)
>>> dict["120C"][0].edges()
OutEdgeView([(1, 2), (1, 3), (2, 3), (3, 1)])
>>> dict["012"][0].edges()
OutEdgeView([(1, 2)])

References
----------
.. [1] Snijders, T. (2012). "Transitivity and triads." University of
    Oxford.
    https://web.archive.org/web/20170830032057/http://www.stats.ox.ac.uk/~snijders/Trans_Triads_ha.pdf
)rc   r   ÚlistÚ
triad_typeÚappend)r   Úall_triÚtri_by_typeÚtriadrA   s   &    r   Útriads_by_typerk   V  sE   € ôn ˜‹m€GÜœdÓ#€KÛˆÜ˜%Ó ˆØÕ× Ñ  Ö'ñ ð Ðr   c                óÔ  € \        V 4      '       g   \        P                  ! R4      h\        V P	                  4       4      pV^ 8X  d   R# V^8X  d   R# V^8X  dŠ   V P	                  4       w  r#\        V4      \        V4      8X  d   R# V^ ,          V^ ,          8X  d   R# V^,          V^,          8X  d   R# V^,          V^ ,          8X  g   V^,          V^ ,          8X  d   R# R# V^8X  dæ   \        V P	                  4       ^4       FÅ  w  r#p\        V4      \        V4      8X  d   V^ ,          V9   d    R#  R	# \        V4      P                  \        V4      4      \        V4      8X  g   Kf  V^ ,          V^ ,          V^ ,          0V^ ,          V^ ,          V^ ,          0u;8X  d"   \        V P                  4       4      8X  d	     R
#   R#  R# 	  R# V^8X  Ed    \        V P	                  4       ^4       Fß  w  r#rE\        V4      \        V4      8X  g   K!  \        V4      \        V4      8X  d    R# V^ ,          0V^ ,          0u;8X  d,   \        V4      P                  \        V4      4      8X  d     R#  V^,          0V^,          0u;8X  d,   \        V4      P                  \        V4      4      8X  d     R#  V^,          V^ ,          8X  g   KÞ   R# 	  R# V^8X  d   R# V^8X  d   R# R# )a\  Returns the sociological triad type for a triad.

Parameters
----------
G : digraph
   A NetworkX DiGraph with 3 nodes

Returns
-------
triad_type : str
   A string identifying the triad type

Examples
--------
>>> G = nx.DiGraph([(1, 2), (2, 3), (3, 1)])
>>> nx.triad_type(G)
'030C'
>>> G.add_edge(1, 3)
>>> nx.triad_type(G)
'120C'

Notes
-----
There can be 6 unique edges in a triad (order-3 DiGraph) (so 2^^6=64 unique
triads given 3 nodes). These 64 triads each display exactly 1 of 16
topologies of triads (topologies can be permuted). These topologies are
identified by the following notation:

{m}{a}{n}{type} (for example: 111D, 210, 102)

Here:

{m}     = number of mutual ties (takes 0, 1, 2, 3); a mutual tie is (0,1)
          AND (1,0)
{a}     = number of asymmetric ties (takes 0, 1, 2, 3); an asymmetric tie
          is (0,1) BUT NOT (1,0) or vice versa
{n}     = number of null ties (takes 0, 1, 2, 3); a null tie is NEITHER
          (0,1) NOR (1,0)
{type}  = a letter (takes U, D, C, T) corresponding to up, down, cyclical
          and transitive. This is only used for topologies that can have
          more than one form (eg: 021D and 021U).

References
----------
.. [1] Snijders, T. (2012). "Transitivity and triads." University of
    Oxford.
    https://web.archive.org/web/20170830032057/http://www.stats.ox.ac.uk/~snijders/Trans_Triads_ha.pdf
z"G is not a triad (order-3 DiGraph)r*   r)   r(   Ú021DÚ021UÚ021CÚ111UÚ111DÚ030CÚ030TÚ201Ú120DÚ120UÚ120CÚ210Ú300N)
r\   rW   ÚNetworkXAlgorithmErrorr-   rT   r+   r   Úsymmetric_differencer0   Úintersection)r   Ú	num_edgesÚe1Úe2Úe3Úe4s   &     r   rf   rf   •  s>  € ôf �A�;Š;Ü×'Ò'Ð(LÓMÐMÜ�A—G‘G“I“€IØ�A„~ÙØ	�aŒÙØ	�aŒØ—‘“‰ˆÜˆr‹7”c˜"“gÔÙØ��U�b˜•eŒ^ÙØ��U�b˜•eŒ^ÙØ��U�b˜•eŒ^˜r !�u¨¨1­œ~Ùñ  .à	�aŒÜ& q§w¡w£y°!Ö4‰JˆB�BÜ�2‹wœ#˜b›'Ô!Ø�a•5˜B”;Ú!âÜ�R“×-Ñ-¬c°"«gÓ6¼#¸b»'ÖAØ�q•E˜2˜a�5 " Q¥%Ð(¨R°­U°B°qµE¸2¸a½5Ð,AÖSÄSÈÏÉËÃ^ÕSÚ!ð Tõ ó 5ð 
�a�Ü*¨1¯7©7«9°aÖ8‰NˆB�BÜ�2‹wœ#˜b›'Ö!ä�r“7œc "›gÔ%Ú Ø�q•E�7˜r !�u˜gÖF¬¨R«×)=Ñ)=¼cÀ"»gÓ)FÕFÚ!ð Gà�q•E�7˜r !�u˜gÖF¬¨R«×)=Ñ)=¼cÀ"»gÓ)FÕFÚ!ð Gà�a•5˜B˜q�E–>Ú!ó 9ð 
�aŒÙØ	�aŒÙñ 
r   )rQ   r\   rc   rk   rf   )@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†   r‹   r�   r�   rƒ   rˆ   r†   r‰   rˆ   rŽ   r�   r�   r†   r�   r‹   r�   r‰   r�   r�   é   )r*   r)   r(   rm   rn   ro   rq   rp   rs   rr   rt   ru   rv   rw   rx   ry   r   )Ú__doc__Úcollectionsr   Ú	itertoolsr   r   ÚnetworkxrW   Únetworkx.utilsr   Ú__all__ÚTRICODESr5   r/   r6   r   Ú_dispatchablerQ   r\   rc   rk   rf   )r   rK   s   00r   Ú<module>r™      s(  ðñ
 1å #ß 0ã Ý .ò€ðA€ðJ€ñ* <EÀXÔ;NÔOÑ;N±°�1�k $¨¥(Õ+Ò+Ñ;NÒO€ò	5ñ �\Ó"Ø×ÑóSó ó #ðSðl ×Ññó ðñ: �\Ó"Ø×Ò Ô%ñ)ó &ó #ð)ñ: �\Ó"Ø×Ññ:ó ó #ð:ñz �\Ó"Ø×Ññ]ó ó #ò]ùóK	 Ps   ®C"