ó ŸĂŇYc@sÂdZdZdddddddd d d d d ddddddddddddgZddlZddlmZmZmZm Z ddl m Z dd„Z dd„Zdd „Zdd!„Zdd"„Zdd#„Zdd$„Zdd%„Zdd&„Zdd'„Zdd(„Zd)„Zdd*„Zdd+„Zdd,„Zdd-„Zdd.„Zdd/„Zd0„Zdd1„Z dd2„Z!dd3„Z"dd4„Z#dd5„Z$dd6„Z%dS(7sI Various small and named graphs, together with some compact generators. s=Aric Hagberg (hagberg@lanl.gov) Pieter Swart (swart@lanl.gov)tmake_small_grapht LCF_grapht bull_grapht chvatal_grapht cubical_graphtdesargues_grapht diamond_graphtdodecahedral_grapht frucht_grapht heawood_graphthoffman_singleton_grapht house_grapht house_x_graphticosahedral_graphtkrackhardt_kite_graphtmoebius_kantor_graphtoctahedral_grapht pappus_graphtpetersen_graphtsedgewick_maze_graphttetrahedral_graphttruncated_cube_graphttruncated_tetrahedron_grapht tutte_graphi˙˙˙˙N(t empty_grapht cycle_grapht path_graphtcomplete_graph(t NetworkXErrorcCs4|dk r'|jƒr'tdƒ‚nt||ƒS(sd Return a small undirected graph described by graph_description. See make_small_graph. sDirected Graph not supportedN(tNonet is_directedRR(tgraph_descriptiont create_using((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pytmake_small_undirected_graph0scCsX|d}|d}|d}t||ƒ}|jƒ}|dkrŽ|d}t|ƒ|krptdƒ‚n|jg|D]'}||D]} | d|f^q‹q}ƒn|dkrK|d} x„| D]y} | dd} | dd} | dks%| |dks%| dks%| |dkr4tdƒ‚qË|j| | ƒqËWn||_|S(sQ Return the small graph described by graph_description. graph_description is a list of the form [ltype,name,n,xlist] Here ltype is one of "adjacencylist" or "edgelist", name is the name of the graph and n the number of nodes. This constructs a graph of n nodes with integer labels 0,..,n-1. If ltype="adjacencylist" then xlist is an adjacency list with exactly n entries, in with the j'th entry (which can be empty) specifies the nodes connected to vertex j. e.g. the "square" graph C_4 can be obtained by >>> G=nx.make_small_graph(["adjacencylist","C_4",4,[[2,4],[1,3],[2,4],[1,3]]]) or, since we do not need to add edges twice, >>> G=nx.make_small_graph(["adjacencylist","C_4",4,[[2,4],[3],[4],[]]]) If ltype="edgelist" then xlist is an edge list written as [[v1,w2],[v2,w2],...,[vk,wk]], where vj and wj integers in the range 1,..,n e.g. the "square" graph C_4 can be obtained by >>> G=nx.make_small_graph(["edgelist","C_4",4,[[1,2],[3,4],[2,3],[4,1]]]) Use the create_using argument to choose the graph class/type. iiit adjacencylistisinvalid graph_descriptiontedgelist(RtnodestlenRtadd_edges_fromtadd_edgetname(RR tltypeR(tntGR$tadjlisttvtuR#tetv1tv2((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR;s(      >   8 c Csé|dk r'|jƒr'tdƒ‚n|dkr@td|ƒSt||ƒ}d|_tt|ƒƒ}|t|ƒ}|dkrŠ|SxXt |ƒD]J}||t|ƒ}|||} ||||} |j | | ƒq—W|S(s\ Return the cubic graph specified in LCF notation. LCF notation (LCF=Lederberg-Coxeter-Fruchte) is a compressed notation used in the generation of various cubic Hamiltonian graphs of high symmetry. See, for example, dodecahedral_graph, desargues_graph, heawood_graph and pappus_graph below. n (number of nodes) The starting graph is the n-cycle with nodes 0,...,n-1. (The null graph is returned if n < 0.) shift_list = [s1,s2,..,sk], a list of integer shifts mod n, repeats integer specifying the number of times that shifts in shift_list are successively applied to each v_current in the n-cycle to generate an edge between v_current and v_current+shift mod n. For v1 cycling through the n-cycle a total of k*repeats with shift cycling through shiftlist repeats times connect v1 with v1+shift mod n The utility graph $K_{3,3}$ >>> G = nx.LCF_graph(6, [3, -3], 3) The Heawood graph >>> G = nx.LCF_graph(14, [5, -5], 7) See http://mathworld.wolfram.com/LCFNotation.html for a description and references. sDirected Graph not supportediRiN( RRRRRR(tsortedtlistR%trangeR'( R*t shift_listtrepeatsR R+R$t n_extra_edgestitshiftR0R1((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRrs $    cCsRdddddgdddgdddgdgdggg}t||ƒ}|S(sReturn the Bull graph. R"s Bull Graphiiiii(R!(R t descriptionR+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRłs 6cCs‘dddddddgdd d gd dd gdd dgd d gd dgd dgd dgd gd dgggg g}t||ƒ}|S(sReturn the ChvĂĄtal graph.R"s Chvatal Graphi iiii iiiii i (R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRżs3$c Cs…ddddddgdddgddd gddd gdd dgddd gdd dgddd ggg}t||ƒ}|S( s,Return the 3-regular Platonic Cubical graph.R"sPlatonic Cubical Graphiiiiiiii(R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRÍs09cCs.tdddddgd|ƒ}d|_|S(s Return the Desargues graph.iiiű˙˙˙i i÷˙˙˙sDesargues Graph(RR((R R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRÚs! cCsOdddddgdddgdddgddggg}t||ƒ}|S(sReturn the Diamond graph. R"s Diamond Graphiiii(R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRás 3c Cs@tdddddddddddg d|ƒ}d|_|S( s) Return the Platonic Dodecahedral graph. ii iiiü˙˙˙iů˙˙˙isDodecahedral Graph(RR((R R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRís3 c CsŒtd|ƒ}|jddgddgddgddgddgd d gd d gdd gdd gddgd d gg ƒd |_|S(s–Return the Frucht Graph. The Frucht Graph is the smallest cubical graph whose automorphism group consists only of the identity element. iiiiiii iii ii s Frucht Graph(RR&R((R R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRôs E+ cCs(tdddgd|ƒ}d|_|S(s) Return the Heawood graph, a (3,6) cage. iiiű˙˙˙is Heawood Graph(RR((R R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR s c CsCtjƒ}xtdƒD] }xtdƒD]ó}|jd||fd||ddfƒ|jd||fd||ddfƒ|jd||fd||ddfƒ|jd||fd||ddfƒxBtdƒD]4}|jd||fd||||dfƒqçWq,WqWtj|ƒ}d|_|S(s#Return the Hoffman-Singleton Graph.itpentagonit pentagramisHoffman-Singleton Graph(tnxtGraphR4R'tconvert_node_labels_to_integersR((R+R8tjtk((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR s ****( c CsXdddddgddgdddgdddgddggg}t||ƒ}|S(s5Return the House graph (square with triangle on top).R"s House Graphiiiii(R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR s <c Csdddddddgdddgddddgddddgddggg}t||ƒ}|S(s<Return the House graph with a cross inside the house square.R"sHouse-with-X-inside Graphiiiii(R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR 's HcCsŁddddddddgddd dgd d dd gd d d d gdd d dgd dggdd d dgd gd gdggg g}t||ƒ}|S(s&Return the Platonic Icosahedral graph.R"sPlatonic Icosahedral Graphi iiii iiii ii (R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR 3s?*cCsŻdddddddgddd d gdddgdddd dd gddd gdddd d gddd dd gdd d gd dgd gg g}t||ƒ}|S( s= Return the Krackhardt Kite Social Network. A 10 actor social network introduced by David Krackhardt to illustrate: degree, betweenness, centrality, closeness, etc. The traditional labeling is: Andre=1, Beverley=2, Carol=3, Diane=4, Ed=5, Fernando=6, Garth=7, Heather=8, Ike=9, Jane=10. R"sKrackhardt Kite Social Networki iiiiiiiii (R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRAs KHcCs(tdddgd|ƒ}d|_|S(s Return the Moebius-Kantor graph.iiiű˙˙˙isMoebius-Kantor Graph(RR((R R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRWs c Cs[dddddddgdddgddgddgdgggg}t||ƒ}|S(s%Return the Platonic Octahedral graph.R"sPlatonic Octahedral Graphiiiii(R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR^s ?cCs1tdddddddgdƒ}d|_|S(s Return the Pappus graph.iiiiů˙˙˙iű˙˙˙is Pappus Graph(RR((R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRjs$ cCsddddddgddd gdd d gddd gd ddgdd d gdd dgdddgd dd gdd d gg g}t||ƒ}|S( sReturn the Petersen graph.R"sPetersen Graphi iiiiiiiii (R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRqsT-cCs˝td|ƒ}|jtdƒƒ|jddgddgddggƒ|jddgddggƒ|jdd gddggƒ|jd dgd dgd dggƒd |_|S( sČ Return a small maze with a cycle. This is the maze used in Sedgewick,3rd Edition, Part 5, Graph Algorithms, Chapter 18, e.g. Figure 18.2 and following. Nodes are numbered 0,..,7 iiiiiiiiisSedgewick Maze(Rtadd_nodes_fromR4R&R((R R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR~s(( cCstd|ƒ}d|_|S(s1 Return the 3-regular Platonic Tetrahedral graph.isPlatonic Tetrahedral graph(RR((R R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRs cCsŮddddddgddgd dgd d gd gd dgdd gddgdgddgddgdgdgddgdgddgddgdgdgdgdgdgdgggg}t||ƒ}|S(s*Return the skeleton of the truncated cube.R"sTruncated Cube Graphiiiii iiii iiiii i i iiiiiii(R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR—s'!c Cs>td|ƒ}|jdddddddgƒd|_|S(s:Return the skeleton of the truncated Platonic tetrahedron.i iii iiii iiiii sTruncated Tetrahedron Graph(ii(ii (ii(ii (ii (ii(ii (RR&R((R R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyR¨s" c1Cs~ddddddgddgd d gd d gd dgddgddgddgddgd dgdgddgddgddgdgddgd d!gd d"gdgd#dgd$d%gdd&gd'gd(dgd)d*gdd+gdgd,gdd*gd-gd+dgd*gggddgd.gddgdgggd%d!gd/gd"dgd!gggg.g}t||ƒ}|S(0sReturn the Tutte graph.R"s Tutte's Graphi.iiiiii i iiii"iiiii ii i'i&i(i ii$ii#iiii-i,iii*ii)iii!i iii%i+(R!(R R:R+((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pyRąs0-'**$-(&t__doc__t __author__t__all__tnetworkxR=tnetworkx.generators.classicRRRRtnetworkx.exceptionRRR!RRRRRRRRRR R R R R RRRRRRRRRR(((so/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/generators/small.pytsj  " 7 A