;iDdZddlZddlmZddlmZmZd dZd dZdZ dS) zg altgraph.GraphUtil - Utility classes and functions ================================================== N)deque)Graph GraphErrorFctj}|s%|r||z}n||dz z}||krtdt|}|D]}|| t j|}t j|} || kr|s2||| |sK||| ||krnz|S)z Generates and returns a :py:class:`~altgraph.Graph.Graph` instance with *node_num* nodes randomly connected by *edge_num* edges. z1inconsistent arguments to 'generate_random_graph') rrrangeadd_noderandomchoice edge_by_nodeadd_edgenumber_of_edges) node_numedge_num self_loops multi_edgesg max_edgesnodesnodeheadtails FC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\altgraph/GraphUtil.pygenerate_random_graphr s  A R  2 8+II HqL1I i  PQQ Q (OOE 4}U##}U## 4<< <  >>$ % % 1+ 1  4    ( * * " Hctj}g}t|D]X}t|dz|D]B}|||||||CYt|||zD]}|||||kret j|} || kr|s6||| r|sO||| |||ke| |D],} |||| -|S)a Generates and returns a :py:class:`~altgraph.Graph.Graph` instance that will have *steps* \* *growth_num* nodes and a scale free (powerlaw) connectivity. Starting with a fully connected graph with *growth_num* nodes at every step *growth_num* nodes are added to the graph and are connected to existing nodes with a probability proportional to the degree of these existing nodes. r) rrappendr r out_degreer r r out_nbrs) steps growth_numrrgraphstoreijrnbrs rgenerate_scale_free_graphr'5s KMME E :  !!q1uj)) ! !A LLOOO LLOOO NN1a  ! j%*"455 tt$$z11-&&Cs{{:{!!$,, [  NN4 % % %t$$z11>>$''  C LL    LL      Lrc"|httc}}t||fg}|j}|j}|j}|r|\} } || } | )|D]$} | | s| n%| } || D]X} || }| | ur|| |f||vr,|||| |fY|fd|D}||fS)a Perform a walk in a depth-first order starting at *head*. Returns (visited, removes, orphans). * visited: the set of visited nodes * removes: the list of nodes where the node data does not all *filters* * orphans: tuples of (last_good, node), where node is not in removes, is directly reachable from a node in *removes* and *last_good* is the closest upstream node that is not in *removes*. Nc&g|] \}}|v ||fSr*).0lgtlremovess r z filter_stack..s+EEEHR2W3D3DBx3D3D3Dr)setr node_data out_edgesrpopaddr)r"rfiltersvisitedorphansstackget_data get_edgesget_tail last_goodrdatafiltfuncedgerr.s @r filter_stackr@`sc""&suuGWg D$<. ! !EHIzH 0))++ 4x~~  # ! !x~~KK%%%E! IdOO 0 0D8D>>D$$ Y-...7"" D!!! i.///! 0$FEEEEEEG GW $$r)FF) __doc__r collectionsraltgraphrrrr'r@r*rrrDs  &&&&&&&&& & & & R((((V+%+%+%+%+%r