K iz dZddlmZddlZddlmZddgZedejdZ ejd Z y) z Dominance algorithms. )reduceN)not_implemented_forimmediate_dominatorsdominance_frontiers undirectedc ||vrtjd||i ttj||}t |Dcic]\}}|| c}}|j |j  fd}d}|rBd}|D]8}t| fd|j|D}| vs ||k7s2| |<d}:|rB Scc}}w)a1Returns the immediate dominators of all nodes of a directed graph. Parameters ---------- G : a DiGraph or MultiDiGraph The graph where dominance is to be computed. start : node The start node of dominance computation. Returns ------- idom : dict keyed by nodes A dict containing the immediate dominators of each node reachable from `start`. Raises ------ NetworkXNotImplemented If `G` is undirected. NetworkXError If `start` is not in `G`. Notes ----- Except for `start`, the immediate dominators are the parents of their corresponding nodes in the dominator tree. Examples -------- >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)]) >>> sorted(nx.immediate_dominators(G, 1).items()) [(1, 1), (2, 1), (3, 1), (4, 3), (5, 1)] References ---------- .. [1] Cooper, Keith D., Harvey, Timothy J. and Kennedy, Ken. "A simple, fast dominance algorithm." (2006). https://hdl.handle.net/1911/96345 zstart is not in Gc||k7r>||kr|}||kr||kDr|}||kDr||k7r>|SN)uvdfnidoms c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/networkx/algorithms/dominance.py intersectz'immediate_dominators..intersectCsl1fa&3q6/Ga&3q6/a&3q6/Ga&3q6/1f TFc3,K|] }|vs| ywr r ).0r rs r z'immediate_dominators..Os)L!t)!)Ls ) nx NetworkXErrorlistdfs_postorder_nodes enumeratepopreverserpred) Gstartorderir rchangednew_idomrrs @@rrr sX A~233 5>D ''51 2E%e, -DAq1a4 -C IIK MMOG  Ai)LQVVAY)LMH}Q8 3"Q    K+ .s C c:tj||}|Dcic] }|t}}|D]b}t|j|dk\s|j|D]2}||vs|||k7s||j |||}|||k7r"4d|Scc}w)aReturns the dominance frontiers of all nodes of a directed graph. Parameters ---------- G : a DiGraph or MultiDiGraph The graph where dominance is to be computed. start : node The start node of dominance computation. Returns ------- df : dict keyed by nodes A dict containing the dominance frontiers of each node reachable from `start` as lists. Raises ------ NetworkXNotImplemented If `G` is undirected. NetworkXError If `start` is not in `G`. Examples -------- >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)]) >>> sorted((u, sorted(df)) for u, df in nx.dominance_frontiers(G, 1).items()) [(1, []), (2, [5]), (3, [5]), (4, [5]), (5, [])] References ---------- .. [1] Cooper, Keith D., Harvey, Timothy J. and Kennedy, Ken. "A simple, fast dominance algorithm." (2006). https://hdl.handle.net/1911/96345 )rrsetlenradd)rrrr dfr s rrrWsL  " "1e ,D !q!SU( !B ! $ qvvay>Q VVAY $9tAw,1 !  GtAw, $$ I "sB) __doc__ functoolsrnetworkxrnetworkx.utilsr__all__ _dispatchablerrr rrr0sd. !#8 9\"E#EP//r