ó žÃÒYc%@ s¡dZddlmZddlmZddlmZyddlmZWn!ek rmddlm ZnXddl Z ddl m Z mZd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-g%Zd.„Zdd/„Zddd0„Zd1„Zd2„Zd3„Zd4„Zd5„Zd6„Zd7„Zd8„Zd9„Zd:„Zd;„Zd<„Zd=„Z d>„Z!d?„Z"d@„Z#edAƒdB„ƒZ$dC„Z%dD„Z&e'dE„Z(ddF„Z)ddG„Z*dH„Z+ddI„Z,dJ„Z-dK„Z.dL„Z/dM„Z0edNƒdO„ƒZ1ddPdQ„Z2ddPdR„Z3dS„Z4dT„Z5e6e6ddU„Z7dV„Z8dS(Ws>Functional interface to graph methods and assorted utilities. iÿÿÿÿ(tdivision(tCounter(tchain(t zip_longest(t izip_longestN(tpairwisetnot_implemented_fortnodestedgestdegreetdegree_histogramt neighborstnumber_of_nodestnumber_of_edgestdensityt is_directedtinfotfreezet is_frozentsubgraphtinduced_subgrapht edge_subgraphtrestricted_viewt reverse_viewt to_directedt to_undirectedtadd_startadd_patht add_cycletcreate_empty_copytset_node_attributestget_node_attributestset_edge_attributestget_edge_attributest all_neighborst non_neighborst non_edgestcommon_neighborst is_weightedtis_negatively_weightedtis_emptytselfloop_edgestnodes_with_selfloopstnumber_of_selfloopscC s |jƒS(s(Return an iterator over the graph nodes.(R(tG((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR(scC s |j|ƒS(s Return an edge view of edges incident to nodes in nbunch. Return all edges if nbunch is unspecified or nbunch=None. For digraphs, edges=out_edges (R(R,tnbunch((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR-scC s|j||ƒS(s~Return a degree view of single node or of nbunch of nodes. If nbunch is ommitted, then return degrees of *all* nodes. (R (R,R-tweight((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR 7scC s |j|ƒS(s,Return a list of nodes connected to node n. (R (R,tn((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR >scC s |jƒS(s(Return the number of nodes in the graph.(R (R,((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR CscC s |jƒS(s)Return the number of edges in the graph. (R (R,((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR HscC sct|ƒ}t|ƒ}|dks0|dkr4dS|||d}|jƒs_|d9}n|S(s"Return the density of a graph. The density for undirected graphs is .. math:: d = \frac{2m}{n(n-1)}, and for directed graphs is .. math:: d = \frac{m}{n(n-1)}, where `n` is the number of nodes and `m` is the number of edges in `G`. Notes ----- The density is 0 for a graph without edges and 1 for a complete graph. The density of multigraphs can be higher than 1. Self loops are counted in the total number of edges so graphs with self loops can have density higher than 1. iii(R R R(R,R/tmtd((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRMs    cC sOtd„|jƒDƒƒ}gtt|ƒdƒD]}|j|dƒ^q3S(suReturn a list of the frequency of each degree value. Parameters ---------- G : Networkx graph A graph Returns ------- hist : list A list of frequencies of degrees. The degree values are the index in the list. Notes ----- Note: the bins are width one, hence len(list) can be large (Order(number_of_edges)) cs s|]\}}|VqdS(N((t.0R/R1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys ƒsii(RR trangetmaxtget(R,tcountsti((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR pscC s |jƒS(s" Return True if graph is directed.(R(R,((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR‡scG stjdƒ‚dS(sCDummy method for raising errors when trying to modify frozen graphssFrozen graph can't be modifiedN(tnxt NetworkXError(targs((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pytfrozenŒscC s^t|_t|_t|_t|_t|_t|_t|_t|_t|_ t |_|S(sÚModify graph to prevent further change by adding or removing nodes or edges. Node and edge data can still be modified. Parameters ---------- G : graph A NetworkX graph Examples -------- >>> G = nx.path_graph(4) >>> G = nx.freeze(G) >>> try: ... G.add_edge(4, 5) ... except nx.NetworkXError as e: ... print(str(e)) Frozen graph can't be modified Notes ----- To "unfreeze" a graph you must make a copy by creating a new graph object: >>> graph = nx.path_graph(4) >>> frozen_graph = nx.freeze(graph) >>> unfrozen_graph = nx.Graph(frozen_graph) >>> nx.is_frozen(unfrozen_graph) False See Also -------- is_frozen ( R;tadd_nodetadd_nodes_fromt remove_nodetremove_nodes_fromtadd_edgetadd_edges_fromt remove_edgetremove_edges_fromtcleartTrue(R,((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR‘s#          cC s$y |jSWntk rtSXdS(sŽReturn True if graph is frozen. Parameters ---------- G : graph A NetworkX graph See Also -------- freeze N(R;tAttributeErrortFalse(R,((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRÁs   c sBt|ƒ}t|ƒ‰‡fd†|Dƒ}|j||dS(sAdd a star to Graph G. The first node in nodes is the middle of the star. It is connected to all other nodes. Parameters ---------- nodes : iterable container A container of nodes. attr : keyword arguments, optional (default= no attributes) Attributes to add to every edge in star. See Also -------- add_path, add_cycle Examples -------- >>> G = nx.Graph() >>> nx.add_star(G, [0, 1, 2, 3]) >>> nx.add_star(G, [10, 11, 12], weight=2) c3 s|]}ˆ|fVqdS(N((R2R/(tv(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys ìsN(titertnextRA(R,RtattrtnlistR((RHso/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRÓs  cK s|jt|ƒ|dS(sûAdd a path to the Graph G. Parameters ---------- nodes : iterable container A container of nodes. A path will be constructed from the nodes (in order) and added to the graph. attr : keyword arguments, optional (default= no attributes) Attributes to add to every edge in path. See Also -------- add_star, add_cycle Examples -------- >>> G = nx.Graph() >>> nx.add_path(G, [0, 1, 2, 3]) >>> nx.add_path(G, [10, 11, 12], weight=7) N(RAR(R,RRK((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRðscK s |jt|dtƒ|dS(s,Add a cycle to the Graph G. Parameters ---------- nodes: iterable container A container of nodes. A cycle will be constructed from the nodes (in order) and added to the graph. attr : keyword arguments, optional (default= no attributes) Attributes to add to every edge in cycle. See Also -------- add_path, add_star Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> nx.add_cycle(G, [0, 1, 2, 3]) >>> nx.add_cycle(G, [10, 11, 12], weight=7) tcyclicN(RARRE(R,RRK((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRscC s |j|ƒS(s8Return the subgraph induced on nodes in nbunch. Parameters ---------- G : graph A NetworkX graph nbunch : list, iterable A container of nodes that will be iterated through once (thus it should be an iterator or be iterable). Each element of the container should be a valid node type: any hashable type except None. If nbunch is None, return all edges data in the graph. Nodes in nbunch that are not in the graph will be (quietly) ignored. Notes ----- subgraph(G) calls G.subgraph() (R(R,R-((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR scC s‹tjj|j|ƒƒ}|jƒrY|jƒrFtjj||ƒStjj||ƒS|jƒrxtjj ||ƒStjj ||ƒS(sÒReturn a SubGraph view of `G` showing only nodes in nbunch. The induced subgraph of a graph on a set of nodes N is the graph with nodes N and edges from G which have both ends in N. Parameters ---------- G : NetworkX Graph nbunch : node, container of nodes or None (for all nodes) Returns ------- subgraph : SubGraph View A read-only view of the subgraph in `G` induced by the nodes. Changes to the graph `G` will be reflected in the view. Notes ----- To create a mutable subgraph with its own copies of nodes edges and attributes use `subgraph.copy()` or `Graph(subgraph)` For an inplace reduction of a graph to a subgraph you can remove nodes: `G.remove_nodes_from(n in G if n not in set(nbunch))` If you are going to compute subgraphs of your subgraphs you could end up with a chain of views that can be very slow once the chain has about 15 views in it. If they are all induced subgraphs, you can short-cut the chain by making them all subgraphs of the original graph. The graph class method `G.subgraph` does this when `G` is a subgraph. In contrast, this function allows you to choose to build chains or not, as you wish. The returned subgraph is a view on `G`. Examples -------- >>> import networkx as nx >>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> H = G.subgraph([0, 1, 2]) >>> list(H.edges) [(0, 1), (1, 2)] ( R8tfilterst show_nodest nbunch_itert is_multigraphRt graphviewstSubMultiDiGrapht SubMultiGrapht SubDiGraphtSubGraph(R,R-t induced_nodes((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR7s)   cC stj}tj}t|ƒ}tƒ}x|D]}|j|d ƒq.W|j|ƒ}|jƒr´|jƒr’|j|ƒ}|j |||ƒS|j |ƒ}|j |||ƒS|jƒrâ|j |ƒ}|j |||ƒS|j|ƒ}|j|||ƒS(sReturns a view of the subgraph induced by the specified edges. The induced subgraph contains each edge in `edges` and each node incident to any of those edges. Parameters ---------- G : NetworkX Graph edges : iterable An iterable of edges. Edges not present in `G` are ignored. Returns ------- subgraph : SubGraph View A read-only edge-induced subgraph of `G`. Changes to `G` are reflected in the view. Notes ----- To create a mutable subgraph with its own copies of nodes edges and attributes use `subgraph.copy()` or `Graph(subgraph)` If you create a subgraph of a subgraph recursively you can end up with a chain of subgraphs that becomes very slow with about 15 nested subgraph views. Luckily the edge_subgraph filter nests nicely so you can use the original graph (`subgraph.root_graph`) as G in this function to avoid chains. We do not rule out chains programmatically so that odd cases like an `edge_subgraph` of a `restricted_view` can be created. Examples -------- >>> import networkx as nx >>> G = nx.path_graph(5) >>> H = G.edge_subgraph([(0, 1), (3, 4)]) >>> list(H.nodes) [0, 1, 3, 4] >>> list(H.edges) [(0, 1), (3, 4)] i(R8RNRRtsettupdateRORQRtshow_multidiedgesRStshow_multiedgesRTt show_diedgesRUt show_edgesRV(R,RtnxftnxgRteRWt induced_edges((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRjs$)        cC sÍtj}tj}|j|ƒ}|jƒr}|jƒr[|j|ƒ}|j|||ƒS|j|ƒ}|j |||ƒS|jƒr«|j |ƒ}|j |||ƒS|j |ƒ}|j |||ƒS(sSReturns a view of `G` with hidden nodes and edges. The resulting subgraph filters out node `nodes` and edges `edges`. Filtered out nodes also filter out any of their edges. Parameters ---------- G : NetworkX Graph nodes : iterable An iterable of nodes. Nodes not present in `G` are ignored. edges : iterable An iterable of edges. Edges not present in `G` are ignored. Returns ------- subgraph : SubGraph View A read-only restricted view of `G` filtering out nodes and edges. Changes to `G` are reflected in the view. Notes ----- To create a mutable subgraph with its own copies of nodes edges and attributes use `subgraph.copy()` or `Graph(subgraph)` If you create a subgraph of a subgraph recursively you may end up with a chain of subgraph views. Such chains can get quite slow for lengths near 15. To avoid long chains, try to make your subgraph based on the original graph (`subgraph.root_graph`). We do not rule out chains programatically so that odd cases like an `edge_subgraph` of a `restricted_view` can be created. Examples -------- >>> import networkx as nx >>> G = nx.path_graph(5) >>> H = nx.restricted_view(G, [0], [(1, 2), (3, 4)]) >>> list(H.nodes) [1, 2, 3, 4] >>> list(H.edges) [(2, 3)] (R8RNRRt hide_nodesRQRthide_multidiedgesRSthide_multiedgesRTt hide_diedgesRUt hide_edgesRV(R,RRR^R_th_nodesth_edges((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR§s*     t undirectedcC s,|jƒrtjj|ƒStjj|ƒS(smProvide a reverse view of the digraph with edges reversed. Identical to digraph.reverse(copy=False) (RQR8RRtMultiReverseViewt ReverseView(tdigraph((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRás cC s,|jƒrtjj|ƒStjj|ƒS(scReturn a directed view of the graph `graph`. Identical to graph.to_directed(as_view=True) (RQR8RRtMultiDiGraphViewt DiGraphView(tgraph((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRìs cC s,|jƒrtjj|ƒStjj|ƒS(shReturn an undirected view of the graph `graph`. Identical to graph.to_undirected(as_view=True) (RQR8RRtMultiGraphViewt GraphView(Ro((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRös cC sE|jƒ}|j|jd|ƒƒ|rA|jj|jƒn|S(s Return a copy of the graph G with all of the edges removed. Parameters ---------- G : graph A NetworkX graph with_data : bool (default=True) Propagate Graph and Nodes data to the new graph. See Also ----- empty_graph tdata(t fresh_copyR=RRoRY(R,t with_datatH((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRs  cC sÉd}|dkrK|d|j7}t|ƒjg}|ddj|ƒ7}|d|jƒ7}|d|jƒ7}|jƒ}t|ƒdkrÅ|jƒr t d„|j ƒDƒƒt |ƒ}|d |7}t d „|j ƒDƒƒt |ƒ}|d |7}qHt t |jƒƒjƒƒ}|d t |ƒt |ƒ7}qÅnz||krptjd |fƒ‚n|d|7}|d|j|ƒ7}|d7}|djd„|j|ƒDƒƒ7}|S(sÄPrint short summary of information for the graph G or the node n. Parameters ---------- G : Networkx graph A graph n : node (any hashable) A node in the graph G ts Name: %s s Type: %s t,sNumber of nodes: %d sNumber of edges: %d ics s|]\}}|VqdS(N((R2R/R1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys +ssAverage in degree: %8.4f cs s|]\}}|VqdS(N((R2R/R1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys -ssAverage out degree: %8.4fsAverage degree: %8.4fsnode %s not in graphs'Node % s has the following properties: s Degree: %d s Neighbors: t cs s|]}t|ƒVqdS(N(tstr(R2tnbr((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys 9sN(tNonetnamettypet__name__tjoinR R tlenRtsumt in_degreetfloatt out_degreetdictR tvaluesR8R9R (R,R/Rt type_nametnnodestdegts((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyRs.    &&$  &cC sà|dk r“yNxG|jƒD]9\}}y|||j||>> G = nx.path_graph(3) >>> bb = nx.betweenness_centrality(G) >>> isinstance(bb, dict) True >>> nx.set_node_attributes(G, bb, 'betweenness') >>> G.nodes[1]['betweenness'] 1.0 If you provide a list as the second argument, updates to the list will be reflected in the node attribute for each node:: >>> G = nx.path_graph(3) >>> labels = [] >>> nx.set_node_attributes(G, labels, 'labels') >>> labels.append('foo') >>> G.nodes[0]['labels'] ['foo'] >>> G.nodes[1]['labels'] ['foo'] >>> G.nodes[2]['labels'] ['foo'] If you provide a dictionary of dictionaries as the second argument, the entire dictionary will be used to update node attributes:: >>> G = nx.path_graph(3) >>> attrs = {0: {'attr1': 20, 'attr2': 'nothing'}, 1: {'attr2': 3}} >>> nx.set_node_attributes(G, attrs) >>> G.nodes[0]['attr1'] 20 >>> G.nodes[0]['attr2'] 'nothing' >>> G.nodes[1]['attr2'] 3 >>> G.nodes[2] {} N(R{titemsRtKeyErrorRFRY(R,R†R|R/RHR1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR=sB      c s‡fd†|jjƒDƒS(sxGet node attributes from graph Parameters ---------- G : NetworkX Graph name : string Attribute name Returns ------- Dictionary of attributes keyed by node. Examples -------- >>> G = nx.Graph() >>> G.add_nodes_from([1, 2, 3], color='red') >>> color = nx.get_node_attributes(G, 'color') >>> color[1] 'red' c s/i|]%\}}ˆ|kr|ˆ|“qS(((R2R/R1(R|(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys §s (RR‹(R,R|((R|so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR‘sc C sÁ|dk ry´|jƒrrx¡|jƒD]C\\}}}}y||||||>> G = nx.path_graph(3) >>> bb = nx.edge_betweenness_centrality(G, normalized=False) >>> nx.set_edge_attributes(G, bb, 'betweenness') >>> G.edges[1, 2]['betweenness'] 2.0 If you provide a list as the second argument, updates to the list will be reflected in the edge attribute for each edge:: >>> labels = [] >>> nx.set_edge_attributes(G, labels, 'labels') >>> labels.append('foo') >>> G.edges[0, 1]['labels'] ['foo'] >>> G.edges[1, 2]['labels'] ['foo'] If you provide a dictionary of dictionaries as the second argument, the entire dictionary will be used to update edge attributes:: >>> G = nx.path_graph(3) >>> attrs = {(0, 1): {'attr1': 20, 'attr2': 'nothing'}, ... (1, 2): {'attr2': 3}} >>> nx.set_edge_attributes(G, attrs) >>> G[0][1]['attr1'] 20 >>> G[0][1]['attr2'] 'nothing' >>> G[1][2]['attr2'] 3 RrN(R{RQR‹RŒRFRRERY( R,R†R|tuRHtkeytvalueRrR1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR ªs6>  "     " "   c sM|jƒr'|jdtdtƒ}n|jdtƒ}‡fd†|DƒS(sGet edge attributes from graph Parameters ---------- G : NetworkX Graph name : string Attribute name Returns ------- Dictionary of attributes keyed by edge. For (di)graphs, the keys are 2-tuples of the form: (u, v). For multi(di)graphs, the keys are 3-tuples of the form: (u, v, key). Examples -------- >>> G = nx.Graph() >>> nx.add_path(G, [1, 2, 3], color='red') >>> color = nx.get_edge_attributes(G, 'color') >>> color[(1, 2)] 'red' tkeysRrc s5i|]+}ˆ|dkr|dˆ|d “qS(iÿÿÿÿ((R2tx(R|(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys (s (RQRRE(R,R|R((R|so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR! s cC sC|jƒr0t|j|ƒ|j|ƒƒ}n|j|ƒ}|S(srReturns all of the neighbors of a node in the graph. If the graph is directed returns predecessors as well as successors. Parameters ---------- graph : NetworkX graph Graph to find neighbors. node : node The node whose neighbors will be returned. Returns ------- neighbors : iterator Iterator of neighbors (RRt predecessorst successorsR (RotnodeR†((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR"+s $c s0tt||ƒƒ|hB‰‡fd†|DƒS(sXReturns the non-neighbors of the node in the graph. Parameters ---------- graph : NetworkX graph Graph to find neighbors. node : node The node whose neighbors will be returned. Returns ------- non_neighbors : iterator Iterator of nodes in the graph that are not neighbors of the node. c3 s!|]}|ˆkr|VqdS(N((R2tnnode(tnbors(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys Us(RXR (RoR”((R–so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR#Dscc s˜|jƒrEx…|D]+}x"t||ƒD]}||fVq)WqWnOt|ƒ}x@|r“|jƒ}x'|t||ƒD]}||fVq{WqTWdS(sýReturns the non-existent edges in the graph. Parameters ---------- graph : NetworkX graph. Graph to find non-existent edges. Returns ------- non_edges : iterator Iterator of edges that are not in the graph. N(RR#RXtpop(RoRRHR((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR$Xs     tdirectedc sZˆˆkrtjdƒ‚nˆˆkr<tjdƒ‚n‡‡‡fd†ˆˆDƒS(sôReturn the common neighbors of two nodes in a graph. Parameters ---------- G : graph A NetworkX undirected graph. u, v : nodes Nodes in the graph. Returns ------- cnbors : iterator Iterator of common neighbors of u and v in the graph. Raises ------ NetworkXError If u or v is not a node in the graph. Examples -------- >>> G = nx.complete_graph(5) >>> sorted(nx.common_neighbors(G, 0, 1)) [2, 3, 4] su is not in the graph.sv is not in the graph.c3 s7|]-}|ˆˆkr|ˆˆfkr|VqdS(N((R2tw(R,RRH(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys ”s(R8R9(R,RRH((R,RRHso/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR%qs   R.c sˆ|dk rR|j|Œ}|dkrHdj|ƒ}tj|ƒ‚nˆ|kSt|ƒrbtSt‡fd†|jdt ƒDƒƒS(s Returns True if `G` has weighted edges. Parameters ---------- G : graph A NetworkX graph. edge : tuple, optional A 2-tuple specifying the only edge in `G` that will be tested. If None, then every edge in `G` is tested. weight: string, optional The attribute name used to query for edge weights. Returns ------- bool A boolean signifying if `G`, or the specified edge, is weighted. Raises ------ NetworkXError If the specified edge does not exist. Examples -------- >>> G = nx.path_graph(4) >>> nx.is_weighted(G) False >>> nx.is_weighted(G, (2, 3)) False >>> G = nx.DiGraph() >>> G.add_edge(1, 2, weight=1) >>> nx.is_weighted(G) True sEdge {!r} does not exist.c3 s$|]\}}}ˆ|kVqdS(N((R2RRHRr(R.(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys ÉsRrN( R{t get_edge_datatformatR8R9R(RGtallRRE(R,tedgeR.Rrtmsg((R.so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR&—s'    c sˆ|dk rb|j|Œ}|dkrHdj|ƒ}tj|ƒ‚nˆ|koa|ˆdkSt‡fd†|jdtƒDƒƒS(sÿReturns True if `G` has negatively weighted edges. Parameters ---------- G : graph A NetworkX graph. edge : tuple, optional A 2-tuple specifying the only edge in `G` that will be tested. If None, then every edge in `G` is tested. weight: string, optional The attribute name used to query for edge weights. Returns ------- bool A boolean signifying if `G`, or the specified edge, is negatively weighted. Raises ------ NetworkXError If the specified edge does not exist. Examples -------- >>> G = nx.Graph() >>> G.add_edges_from([(1, 3), (2, 4), (2, 6)]) >>> G.add_edge(1, 2, weight=4) >>> nx.is_negatively_weighted(G, (1, 2)) False >>> G[2][4]['weight'] = -2 >>> nx.is_negatively_weighted(G) True >>> G = nx.DiGraph() >>> edges = [('0', '3', 3), ('0', '1', -5), ('1', '0', -2)] >>> G.add_weighted_edges_from(edges) >>> nx.is_negatively_weighted(G) True sEdge {!r} does not exist.ic3 s4|]*\}}}ˆ|ko+|ˆdkVqdS(iN((R2RRHRr(R.(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys þsRrN(R{RšR›R8R9tanyRRE(R,RR.RrRž((R.so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR'Ìs+  cC st|jjƒƒ S(sšReturns True if `G` has no edges. Parameters ---------- G : graph A NetworkX graph. Returns ------- bool True if `G` has no edges, and False otherwise. Notes ----- An empty graph can have nodes but not edges. The empty graph with zero nodes is known as the null graph. This is an $O(n)$ operation where n is the number of nodes in the graph. (RŸtadjR†(R,((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR(scC sd„|jjƒDƒS(sîReturns an iterator over nodes with self loops. A node with a self loop has an edge with both ends adjacent to that node. Returns ------- nodelist : iterator A iterator over nodes with self loops. See Also -------- selfloop_edges, number_of_selfloops Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1, 1) >>> G.add_edge(1, 2) >>> list(nx.nodes_with_selfloops(G)) [1] cs s'|]\}}||kr|VqdS(N((R2R/tnbrs((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys 1s(R R‹(R,((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR*sc s]ˆtkro|jƒrU|tkr;d„|jjƒDƒSd„|jjƒDƒSqYd„|jjƒDƒSnêˆtk rù|jƒrÖ|tkr³‡‡fd†|jjƒDƒS‡‡fd†|jjƒDƒSqY‡‡fd†|jjƒDƒSn`|jƒrB|tkr(d„|jjƒDƒSd„|jjƒDƒSnd „|jjƒDƒSd S( sºReturns an iterator over selfloop edges. A selfloop edge has the same node at both ends. Parameters ---------- data : string or bool, optional (default=False) Return selfloop edges as two tuples (u, v) (data=False) or three-tuples (u, v, datadict) (data=True) or three-tuples (u, v, datavalue) (data='attrname') keys : bool, optional (default=False) If True, return edge keys with each edge. default : value, optional (default=None) Value used for edges that dont have the requested attribute. Only relevant if data is not True or False. Returns ------- edgeiter : iterator over edge tuples An iterator over all selfloop edges. See Also -------- nodes_with_selfloops, number_of_selfloops Examples -------- >>> G = nx.MultiGraph() # or Graph, DiGraph, MultiDiGraph, etc >>> ekey = G.add_edge(1, 1) >>> ekey = G.add_edge(1, 2) >>> list(nx.selfloop_edges(G)) [(1, 1)] >>> list(nx.selfloop_edges(G, data=True)) [(1, 1, {})] >>> list(nx.selfloop_edges(G, keys=True)) [(1, 1, 0)] >>> list(nx.selfloop_edges(G, keys=True, data=True)) [(1, 1, 0, {})] cs sP|]F\}}||kr||jƒD]\}}||||fVq)qdS(N(R‹(R2R/R¡tkR1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys _s cs sG|]=\}}||kr||jƒD]}|||fVq)qdS(N(R†(R2R/R¡R1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys cs cs s4|]*\}}||kr||||fVqdS(N((R2R/R¡((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys gsc3 s\|]R\}}||kr||jƒD])\}}||||jˆˆƒfVq)qdS(N(R‹R5(R2R/R¡R¢R1(Rrtdefault(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys ks c3 sS|]I\}}||kr||jƒD] }|||jˆˆƒfVq)qdS(N(R†R5(R2R/R¡R1(RrR£(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys os c3 s@|]6\}}||kr||||jˆˆƒfVqdS(N(R5(R2R/R¡(RrR£(so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys sscs sA|]7\}}||kr||D]}|||fVq#qdS(N((R2R/R¡R¢((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys xs cs sD|]:\}}||kr||jƒD]}||fVq)qdS(N(R†(R2R/R¡R1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys |s cs s-|]#\}}||kr||fVqdS(N((R2R/R¡((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys €sN(RERQR R‹RG(R,RrRR£((RrR£so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR)4s0(        cC std„tj|ƒDƒƒS(s§Return the number of selfloop edges. A selfloop edge has the same node at both ends. Returns ------- nloops : int The number of selfloops. See Also -------- nodes_with_selfloops, selfloop_edges Examples -------- >>> G = nx.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc >>> G.add_edge(1, 1) >>> G.add_edge(1, 2) >>> nx.number_of_selfloops(G) 1 cs s|] }dVqdS(iN((R2t_((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pys ™s(RR8R)(R,((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyR+ƒs(9t__doc__t __future__Rt collectionsRt itertoolsRRt ImportErrorRtnetworkxR8tnetworkx.utilsRRt__all__RR{RR R R R RR RR;RRRRRRRRRRRRRERRRRR R!R"R#R$R%R&R'R(R*RGR)R+(((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/classes/function.pyt sv              #    0      3 = :  & T  b    &56  O