ó
    …~i'  ã                   óÖ   • S r SSKJr  SSKrSSKJr  / SQr\" SSS9S	 5       r\" SS
S9\R                  " SSSS9S 5       5       r
\R                  " SSS9S 5       rS rSS jrSS jrg)aÈ  
*****
Pydot
*****

Import and export NetworkX graphs in Graphviz dot format using pydot.

Either this module or nx_agraph can be used to interface with graphviz.

Examples
--------
>>> G = nx.complete_graph(5)
>>> PG = nx.nx_pydot.to_pydot(G)
>>> H = nx.nx_pydot.from_pydot(PG)

See Also
--------
 - pydot:         https://github.com/erocarrera/pydot
 - Graphviz:      https://www.graphviz.org
 - DOT Language:  http://www.graphviz.org/doc/info/lang.html
é    )ÚgetpreferredencodingN)Ú	open_file)Ú	write_dotÚread_dotÚgraphviz_layoutÚpydot_layoutÚto_pydotÚ
from_pydoté   Úw)Úmodec                 óX   • [        U 5      nUR                  UR                  5       5        g)zÛWrite NetworkX graph G to Graphviz dot format on path.

Parameters
----------
G : NetworkX graph

path : string or file
   Filename or file handle for data output.
   Filenames ending in .gz or .bz2 will be compressed.
N)r	   ÚwriteÚ	to_string)ÚGÚpathÚPs      ÚV/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/drawing/nx_pydot.pyr   r   &   s"   € ô 	�‹€AØ‡J�Jˆq�{‰{‹}ÔØ
ó    ÚrÚpydot_read_dotT)ÚnameÚgraphsÚreturns_graphc                 óh   • SSK nU R                  5       nUR                  U5      n[        US   5      $ )aQ  Returns a NetworkX :class:`MultiGraph` or :class:`MultiDiGraph` from the
dot file with the passed path.

If this file contains multiple graphs, only the first such graph is
returned. All graphs _except_ the first are silently ignored.

Parameters
----------
path : str or file
    Filename or file handle to read.
    Filenames ending in .gz or .bz2 will be decompressed.

Returns
-------
G : MultiGraph or MultiDiGraph
    A :class:`MultiGraph` or :class:`MultiDiGraph`.

Notes
-----
Use `G = nx.Graph(nx.nx_pydot.read_dot(path))` to return a :class:`Graph` instead of a
:class:`MultiGraph`.
r   N)ÚpydotÚreadÚgraph_from_dot_datar
   )r   r   ÚdataÚP_lists       r   r   r   7   s5   € ó2 à�9‰9‹;€Dð ×&Ñ& tÓ,€Fô �f˜Q‘iÓ Ð r   )r   r   c                 ó  •  U R                  5       nU(       + nU R                  5       S:X  a3  U(       a  [        R                  " 5       nOH[        R
                  " 5       nO2U(       a  [        R                  " 5       nO[        R                  " 5       nU R                  5       R                  S5      nUS:w  a  XCl
        U R                  5        HK  nUR                  5       R                  S5      nUS;   a  M*  UR                  " U40 UR                  5       D6  MM     U R                  5        GH"  nUR                  5       nUR!                  5       n	UR                  5       n
/ n/ n[#        U[$        5      (       a!  UR'                  UR                  S5      5        O,US    H#  nUR'                  UR                  S5      5        M%     [#        U	[$        5      (       a!  UR'                  U	R                  S5      5        O,U	S    H#  nUR'                  UR                  S5      5        M%     U H   nU H  nUR(                  " UU40 U
D6  M     M"     GM%     U R                  5       nU(       a  UUR*                  S'    U R-                  5       S   UR*                  S'    U R1                  5       S   UR*                  S	'   U$ ! [         a    U R                  S5      n GNÉf = f! [.        [        4 a     NWf = f! [.        [        4 a     U$ f = f)
a˜  Returns a NetworkX graph from a Pydot graph.

Parameters
----------
P : Pydot graph
  A graph created with Pydot

Returns
-------
G : NetworkX multigraph
    A MultiGraph or MultiDiGraph.

Examples
--------
>>> K5 = nx.complete_graph(5)
>>> A = nx.nx_pydot.to_pydot(K5)
>>> G = nx.nx_pydot.from_pydot(A)  # return MultiGraph

# make a Graph instead of MultiGraph
>>> G = nx.Graph(nx.nx_pydot.from_pydot(A))

NÚgraphÚ"Ú )Únoder"   ÚedgeÚnodesr   r%   r&   )Ú
get_strictÚ	TypeErrorÚget_typeÚnxÚ
MultiGraphÚGraphÚMultiDiGraphÚDiGraphÚget_nameÚstripr   Úget_node_listÚadd_nodeÚget_attributesÚget_edge_listÚ
get_sourceÚget_destinationÚ
isinstanceÚstrÚappendÚadd_edger"   Úget_node_defaultsÚ
IndexErrorÚget_edge_defaults)r   ÚstrictÚ
multiedgesÚNr   ÚpÚnÚeÚuÚvÚattrÚsÚdÚunodesÚvnodesÚsource_nodeÚdestination_nodeÚpattrs                     r   r
   r
   [   s†  € ð4$Ø—‘“ˆð ”€Jà‡z�zƒ|�wÓÞÜ—’“‰Aä—’“
‰AæÜ—’Ó!‰Aä—
’
“ˆAð �:‰:‹<×Ñ˜cÓ"€DØˆrƒzØŒð �_‰_ÖˆØ�J‰J‹L×Ñ˜sÓ#ˆØÐ)Ó)ÙØ	�
Š
�1Ñ+˜×(Ñ(Ó*Ô+ñ	 ð �_‰_×ˆØ�L‰L‹NˆØ×ÑÓˆØ×ÑÓ!ˆØˆØˆä�aœ×ÑØ�H‰H�Q—W‘W˜S“\Õ"à˜Gœ*�Ø—‘˜Ÿ™ cÓ*Ö+ñ %ô �aœ×ÑØ�H‰H�Q—W‘W˜S“\Õ"à˜Gœ*�Ø—‘˜Ÿ™ cÓ*Ö+ñ %ó ˆKÛ$%Ð Ø—
’
˜;Ð(8ÑA¸DÔAó %&ô ñ' ð0 ×ÑÓ€EÞØ ˆ�‰�ÑðØ×-Ñ-Ó/°Ñ2ˆ�‰�‰ðØ×-Ñ-Ó/°Ñ2ˆ�‰�‰ð €Høô ó $Ø—‘˜dÓ#‹ð$ûôr œ	Ð"ó Ùðûô œ	Ð"ó ØØ€Hðús5   ‚J= É: K Ê K5 Ê=KËKËK2Ë1K2Ë5L	ÌL	c           	      óÂ  • SSK nU R                  5       (       a  SnOSn[        R                  " U 5      S:H  =(       a    U R	                  5       (       + nU R
                  nU R                  R                  S0 5      nUS:X  a  UR                  " SX#S.UD6nOUR                  " SU S34X#S.UD6n UR                  " S0 U R                  S   D6   UR                  " S0 U R                  S	   D6  U R                  S
S9 Hk  u  pxUR                  5        V	V
s0 s H  u  pš[        U	5      [        U
5      _M     nn	n
[        U5      nUR                  " U40 UD6nUR!                  U5        Mm     U R	                  5       (       aŸ  U R#                  S
S
S9 H‰  u  pÚpïUR                  5        V	V
s0 s H"  u  pšU	S:w  d  M  [        U	5      [        U
5      _M$     nn	n
[        U5      [        W
5      p­UR$                  " XÚ4S[        U5      0UD6nUR'                  U5        M‹     U$ U R#                  S
S9 Hv  u  pÚnUR                  5        V	V
s0 s H  u  pš[        U	5      [        U
5      _M     nn	n
[        U5      [        W
5      p­UR$                  " XÚ40 UD6nUR'                  U5        Mx     U$ ! [         a     GNêf = f! [         a     GNÛf = fs  sn
n	f s  sn
n	f s  sn
n	f )zÙReturns a pydot graph from a NetworkX graph N.

Parameters
----------
N : NetworkX graph
  A graph created with NetworkX

Examples
--------
>>> K5 = nx.complete_graph(5)
>>> P = nx.nx_pydot.to_pydot(K5)

Notes
-----

r   NÚdigraphr"   r$   )Ú
graph_typer?   r#   r%   r&   T)r   )r   ÚkeysÚkey)r$   © )r   Úis_directedr+   Únumber_of_selfloopsÚis_multigraphr   r"   ÚgetÚDotÚset_node_defaultsÚKeyErrorÚset_edge_defaultsr'   Úitemsr9   ÚNoder3   ÚedgesÚEdger;   )rA   r   rQ   r?   r   Úgraph_defaultsr   rC   ÚnodedataÚkrF   Ústr_nodedatarB   rE   rS   ÚedgedataÚstr_edgedatar&   s                     r   r	   r	   ¹   s�  € ó" ð 	‡}�}‡�Ø‰
àˆ
Ü×#Ò# AÓ&¨!Ñ+×E°A·O±OÓ4EÔ0E€Fà�6‰6€DØ—W‘W—[‘[ ¨"Ó-€NØˆrƒzØ�IŠIÐQ ZÑQÀ.ÑQ‰à�IŠIØ�ˆv�QˆKð
Ø$.ñ
ØAOñ
ˆðØ	×ÒÑ.˜aŸg™g f™oÒ.ðØ	×ÒÑ.˜aŸg™g f™oÒ.ð —w‘w D�wÓ)‰ˆØ3;·>±>Ô3CÔDÒ3C©4¨1œ˜A›¤ A£šÑ3CˆÑDÜ�‹FˆØ�JŠJ�qÑ)˜LÑ)ˆØ	�
‰
�1Žñ	 *ð 	‡�×ÑØ#$§7¡7°¸4 7Ó#@ÑˆA�#Ø7?·~±~Ô7GÔVÒ7G©t¨qÈ1ÐPUÉ:›NœC ›F¤C¨£FšNÑ7GˆLÑVÜ�q“6œ3˜q›6ˆqØ—:’:˜aÑA¬¨C«ÐA°LÑAˆDØ�J‰J�tÖñ	 $Að €Hð  Ÿg™g¨4˜gÓ0‰NˆA�(Ø7?·~±~Ô7GÔHÒ7G©t¨qœC ›F¤C¨£FšNÑ7GˆLÑHÜ�q“6œ3˜q›6ˆqØ—:’:˜aÑ3 lÑ3ˆDØ�J‰J�tÖñ	 1ð
 €Høô5 ó Úðûô ó Úðüó Eùó Wùó Is<   Â1J- ÃJ> Ä!KÆ,KÆ<KÉ
!KÊ-
J;Ê:J;Ê>
KËKc                 ó   • [        XUS9$ )aá  Create node positions using Pydot and Graphviz.

Returns a dictionary of positions keyed by node.

Parameters
----------
G : NetworkX Graph
    The graph for which the layout is computed.
prog : string (default: 'neato')
    The name of the GraphViz program to use for layout.
    Options depend on GraphViz version but may include:
    'dot', 'twopi', 'fdp', 'sfdp', 'circo'
root : Node from G or None (default: None)
    The node of G from which to start some layout algorithms.

Returns
-------
  Dictionary of (x, y) positions keyed by node.

Examples
--------
>>> G = nx.complete_graph(4)
>>> pos = nx.nx_pydot.graphviz_layout(G)
>>> pos = nx.nx_pydot.graphviz_layout(G, prog="dot")

Notes
-----
This is a wrapper for pydot_layout.
©r   ÚprogÚroot)r   rh   s      r   r   r   ú   s   € ô< ˜!¨TÑ2Ð2r   c                 óÒ  • SSK n[        U 5      nUb  UR                  S[        U5      5        UR	                  US9n[        U[        5       S9nUS:X  aJ  [        SU S35        [        5         [        S	5        [        S
5        [        S5        [        SU S35        gUR                  U5      n[        U5      S:X  d   eUS   n0 n	U R                  5        H‹  n
[        U
5      nUR                  UR                  U5      5      n[        U[        5      (       a  US   nUR                  5       SS nUc  M`  UR                  S5      u  pï[!        U5      [!        U5      4Xš'   M�     U	$ )a|  Create node positions using :mod:`pydot` and Graphviz.

Parameters
----------
G : Graph
    NetworkX graph to be laid out.
prog : string  (default: 'neato')
    Name of the GraphViz command to use for layout.
    Options depend on GraphViz version but may include:
    'dot', 'twopi', 'fdp', 'sfdp', 'circo'
root : Node from G or None (default: None)
    The node of G from which to start some layout algorithms.

Returns
-------
dict
    Dictionary of positions keyed by node.

Examples
--------
>>> G = nx.complete_graph(4)
>>> pos = nx.nx_pydot.pydot_layout(G)
>>> pos = nx.nx_pydot.pydot_layout(G, prog="dot")

Notes
-----
If you use complex node objects, they may have the same string
representation and GraphViz could treat them as the same node.
The layout may assign both nodes a single location. See Issue #1568
If this occurs in your case, consider relabeling the nodes just
for the layout computation using something similar to::

    H = nx.convert_node_labels_to_integers(G, label_attribute="node_label")
    H_layout = nx.nx_pydot.pydot_layout(H, prog="dot")
    G_layout = {H.nodes[n]["node_label"]: p for n, p in H_layout.items()}

r   Nrj   )ri   )Úencodingr$   zGraphviz layout with z failedzTo debug what happened try:zP = nx.nx_pydot.to_pydot(G)zP.write_dot("file.dot")zAnd then run z on file.dotr   éÿÿÿÿÚ,)r   r	   Úsetr9   Ú
create_dotr   Úprintr   Úlenr'   Úget_nodeÚquote_id_if_necessaryr8   ÚlistÚget_posÚsplitÚfloat)r   ri   rj   r   r   ÚD_bytesÚDÚQ_listÚQÚnode_posrC   Ústr_nr%   ÚposÚxxÚyys                   r   r   r     sW  € óL ä�‹€AØÑØ	�‰ˆf”c˜$“iÔ ð �l‰l ˆlÐ%€Gô 	ˆGÔ2Ó4Ñ5€AàˆBƒwÜÐ% d V¨7Ð3Ô4ÜŒÜÐ+Ô,ÜÐ+Ô,ÜÐ'Ô(Ü�˜d˜V <Ð0Ô1Øð ×&Ñ& qÓ)€FÜˆv‹;˜!ÓÐÐð 	ˆq‰	€Aà€HØ�W‰WŽYˆÜ�A“ˆØ�z‰z˜%×5Ñ5°eÓ<Ó=ˆä�dœD×!Ñ!Ø˜‘7ˆDØ�l‰l‹n˜Q˜rÐ"ˆØ‹?Ø—Y‘Y˜s“^‰FˆBÜ  ›9¤e¨B£iÐ0ˆH‹Kñ ð €Or   )ÚneatoN)Ú__doc__Úlocaler   Únetworkxr+   Únetworkx.utilsr   Ú__all__r   Ú_dispatchabler   r
   r	   r   r   rT   r   r   Ú<module>r‰      s¢   ðñõ, (ã Ý $ò€ñ ˆ1�3Ññó ðñ  ˆ1�3ÑØ×ÒÐ'°ÀDÑIñ!ó Jó ð!ðD ×Ò˜¨TÑ2ñZó 3ðZòz>ôB3õBNr   