ó žÃÒYc@sŸdZddlZddlmZddlmZdjddgƒZd d d d gZ d „Z d„Z eddƒd„ƒZ eddƒd„ƒZ dS(sI ======================= Distance-regular graphs ======================= iÿÿÿÿN(tnot_implemented_fori(tdiameters s"Dheeraj M R s%Aric Hagberg tis_distance_regulartis_strongly_regulartintersection_arraytglobal_parameterscCs.yt|ƒtSWntjk r)tSXdS(sReturns True if the graph is distance regular, False otherwise. A connected graph G is distance-regular if for any nodes x,y and any integers i,j=0,1,...,d (where d is the graph diameter), the number of vertices at distance i from x and distance j from y depends only on i,j and the graph distance between x and y, independently of the choice of x and y. Parameters ---------- G: Networkx graph (undirected) Returns ------- bool True if the graph is Distance Regular, False otherwise Examples -------- >>> G=nx.hypercube_graph(6) >>> nx.is_distance_regular(G) True See Also -------- intersection_array, global_parameters Notes ----- For undirected and simple graphs only References ---------- .. [1] Brouwer, A. E.; Cohen, A. M.; and Neumaier, A. Distance-Regular Graphs. New York: Springer-Verlag, 1989. .. [2] Weisstein, Eric W. "Distance-Regular Graph." http://mathworld.wolfram.com/Distance-RegularGraph.html N(RtTruetnxt NetworkXErrortFalse(tG((sz/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/distance_regular.pyRs ( cs+‡fd†tˆdgdg|ƒDƒS(sƒReturn global parameters for a given intersection array. Given a distance-regular graph G with integers b_i, c_i,i = 0,....,d such that for any 2 vertices x,y in G at a distance i=d(x,y), there are exactly c_i neighbors of y at a distance of i-1 from x and b_i neighbors of y at a distance of i+1 from x. Thus, a distance regular graph has the global parameters, [[c_0,a_0,b_0],[c_1,a_1,b_1],......,[c_d,a_d,b_d]] for the intersection array [b_0,b_1,.....b_{d-1};c_1,c_2,.....c_d] where a_i+b_i+c_i=k , k= degree of every vertex. Parameters ---------- b : list c : list Returns ------- iterable An iterable over three tuples. Examples -------- >>> G = nx.dodecahedral_graph() >>> b, c = nx.intersection_array(G) >>> list(nx.global_parameters(b, c)) [(0, 0, 3), (1, 0, 2), (1, 1, 1), (1, 1, 1), (2, 0, 1), (3, 0, 0)] References ---------- .. [1] Weisstein, Eric W. "Global Parameters." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/GlobalParameters.html See Also -------- intersection_array c3s0|]&\}}|ˆd|||fVqdS(iN((t.0txty(tb(sz/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/distance_regular.pys osi(tzip(Rtc((Rsz/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/distance_regular.pyRFs)tdirectedt multigraphcCs*t|jƒƒ}t|ƒ\}}x8|D]0\}}||krUtjdƒ‚n|}q+Wttj|ƒƒ}tg|D]}t||jƒƒ^q~ƒ}i}i} x |D]} x|D]} y|| | } Wn t k rýtjdƒ‚nXt g|| D]$}||| | dkr |^q ƒ} t g|| D]$}||| | dkrG|^qGƒ}| j | | ƒ| ks¤|j | |ƒ|kr¶tjdƒ‚n||| <| | | >> G=nx.icosahedral_graph() >>> nx.intersection_array(G) ([5, 2, 1], [1, 2, 5]) References ---------- .. [1] Weisstein, Eric W. "Intersection Array." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/IntersectionArray.html See Also -------- global_parameters sGraph is not distance regular.isGraph is not distance regulari( titertdegreetnextRRtdicttall_pairs_shortest_path_lengthtmaxtvaluestKeyErrortlentgettrange(R Rt_tktknextt path_lengthtnRtbinttcinttutvtiRRtj((sz/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/distance_regular.pyRrs0%  /   ;;0 (cCst|ƒot|ƒdkS(s=Returns True if and only if the given graph is strongly regular. An undirected graph is *strongly regular* if * it is regular, * each pair of adjacent vertices has the same number of neighbors in common, * each pair of nonadjacent vertices has the same number of neighbors in common. Each strongly regular graph is a distance-regular graph. Conversely, if a distance-regular graph has diameter two, then it is a strongly regular graph. For more information on distance-regular graphs, see :func:`is_distance_regular`. Parameters ---------- G : NetworkX graph An undirected graph. Returns ------- bool Whether `G` is strongly regular. Examples -------- The cycle graph on five vertices is strongly regular. It is two-regular, each pair of adjacent vertices has no shared neighbors, and each pair of nonadjacent vertices has one shared neighbor:: >>> import networkx as nx >>> G = nx.cycle_graph(5) >>> nx.is_strongly_regular(G) True i(RR(R ((sz/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/distance_regular.pyRµs4(t__doc__tnetworkxRtnetworkx.utilsRtdistance_measuresRtjoint __author__t__all__RRRR(((sz/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/distance_regular.pyt s     / ,C