ó
    …~iÿ  ã                   ó„   • S r SSKJr  SSKrSSKJrJrJr  SSK	J
r
  S/r\
" S5      \R                  " SS	9S
 5       5       rg)z2Function for computing a junction tree of a graph.é    )ÚcombinationsN)Úchordal_graph_cliquesÚcomplete_to_chordal_graphÚmoral)Únot_implemented_forÚjunction_treeÚ
multigraphT)Úreturns_graphc                 ól  • [         R                  " 5       nU R                  5       (       a  [        R                  " U 5      n [        U 5      u  p#[        U5       Vs/ s H  n[        [        U5      5      PM     nnUR                  USS9  [        US5       H{  n[        US   5      n[        US   5      nUR                  U5      (       a  M7  [        [        UR                  U5      5      5      n	UR                  US   US   [        U	5      U	S9  M}     [         R                   " U5      n
[#        U
R%                  SS95       Hg  nU
R'                  US   S	   S	S9  U
R                  US   US   S	   5        U
R                  US   US   S	   5        U
R)                  US   US   5        Mi     U
$ s  snf )
u  Returns a junction tree of a given graph.

A junction tree (or clique tree) is constructed from a (un)directed graph G.
The tree is constructed based on a moralized and triangulated version of G.
The tree's nodes consist of maximal cliques and sepsets of the revised graph.
The sepset of two cliques is the intersection of the nodes of these cliques,
e.g. the sepset of (A,B,C) and (A,C,E,F) is (A,C). These nodes are often called
"variables" in this literature. The tree is bipartite with each sepset
connected to its two cliques.

Junction Trees are not unique as the order of clique consideration determines
which sepsets are included.

The junction tree algorithm consists of five steps [1]_:

1. Moralize the graph
2. Triangulate the graph
3. Find maximal cliques
4. Build the tree from cliques, connecting cliques with shared
   nodes, set edge-weight to number of shared variables
5. Find maximum spanning tree


Parameters
----------
G : networkx.Graph
    Directed or undirected graph.

Returns
-------
junction_tree : networkx.Graph
    The corresponding junction tree of `G`.

Raises
------
NetworkXNotImplemented
    Raised if `G` is an instance of `MultiGraph` or `MultiDiGraph`.

References
----------
.. [1] Junction tree algorithm:
   https://en.wikipedia.org/wiki/Junction_tree_algorithm

.. [2] Finn V. Jensen and Frank Jensen. 1994. Optimal
   junction trees. In Proceedings of the Tenth international
   conference on Uncertainty in artificial intelligence (UAIâ€™94).
   Morgan Kaufmann Publishers Inc., San Francisco, CA, USA, 360â€“366.
Úclique)Útypeé   r   é   )ÚweightÚsepsetT)Údatar   )ÚnxÚGraphÚis_directedr   Úmoral_graphr   r   ÚtupleÚsortedÚadd_nodes_fromr   ÚsetÚ
isdisjointÚintersectionÚadd_edgeÚlenÚmaximum_spanning_treeÚlistÚedgesÚadd_nodeÚremove_edge)ÚGÚclique_graphÚchordal_graphÚ_ÚiÚcliquesÚedgeÚ
set_edge_0Ú
set_edge_1r   r   s              Úc/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/algorithms/tree/decomposition.pyr   r      s“  € ôh —8’8“:€Là‡}�}‡�Ü×Ò˜aÓ ˆÜ0°Ó3Ñ€Mä)>¸}Ô)MÓNÒ)M AŒu”V˜A“YÖÑ)M€GÐNØ×Ñ ¨hÐÑ7ä˜W aÖ(ˆÜ˜˜a™“\ˆ
Ü˜˜a™“\ˆ
Ø×$Ñ$ Z×0Ó0Üœ6 *×"9Ñ"9¸*Ó"EÓFÓGˆFØ×!Ñ! $ q¡'¨4°©7¼3¸v»;ÈvÐ!ÓVñ )ô ×,Ò,¨\Ó:€Mä�]×(Ñ(¨dÐ(Ð3Ö4ˆØ×Ñ˜t A™w xÑ0°xÐÑ@Ø×Ñ˜t A™w¨¨Q©°Ñ(9Ô:Ø×Ñ˜t A™w¨¨Q©°Ñ(9Ô:Ø×!Ñ! $ q¡'¨4°©7Ö3ñ	 5ð Ðùò% Os   ÁF1)Ú__doc__Ú	itertoolsr   Únetworkxr   Únetworkx.algorithmsr   r   r   Únetworkx.utilsr   Ú__all__Ú_dispatchabler   © ó    r-   Ú<module>r7      sM   ðÙ 9å "ã ß WÑ WÝ .àÐ
€ñ �\Ó"Ø×Ò Ñ%ñJó &ó #ñJr6   