
    i                     F    S r SSKrSSKJr  SSKJrJr  SS jrSS jrS r	g)	zg
altgraph.GraphUtil - Utility classes and functions
==================================================
    N)deque)Graph
GraphErrorc                    [         R                   " 5       nU(       d#  U(       a  X -  nOX S-
  -  nX:  a  [        S5      e[        U 5      nU H  nUR                  U5        M      [        R
                  " U5      n[        R
                  " U5      n	X:X  a	  U(       d  M;  UR                  X5      b	  U(       d  MV  UR                  X5        UR                  5       U:  a   U$ M  )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')	r   r   rangeadd_noderandomchoiceedge_by_nodeadd_edgenumber_of_edges)
node_numedge_num
self_loopsmulti_edgesg	max_edgesnodesnodeheadtails
             ?C:\des-py\RoboSAPF\venv\Lib\site-packages\altgraph\GraphUtil.pygenerate_random_graphr      s    
 	A +I qL1IPQQ(OE	

4  }}U#}}U# <
 >>$%1+ 	


4(*H#     c                    [         R                   " 5       n/ n[        U5       HL  n[        US-   U5       H6  nUR                  U5        UR                  U5        UR                  Xg5        M8     MN     [        XU-  5       H  nUR	                  U5        UR                  U5      U:  ak  [        R                  " U5      n	X:X  a	  U(       d  M9  UR                  X5      (       a	  U(       d  MX  UR                  X5        UR                  U5      U:  a  Mk  UR                  U5       H%  n	UR                  U5        UR                  U	5        M'     M     U$ )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   )
r   r   appendr   r	   
out_degreer
   r   r   out_nbrs)
steps
growth_numr   r   graphstoreijr   nbrs
             r   generate_scale_free_graphr'   5   s    KKME E:q1uj)ALLOLLONN1  *  j*"45tt$z1--&C {: !!$,,[NN4% t$z1 >>$'CLLLL ( 6& Lr   c                 D   U1[        5       [        5       pTn[        X4/5      nU R                  nU R                  nU R                  n	U(       a  UR                  5       u  pU" U5      nUb+  U H#  nU" U5      (       a  M  UR                  U5          O   Un
U" U5       HK  nU	" U5      nXLa  UR                  X45        X;  d  M(  UR                  U5        UR                  X45        MM     U(       a  M  U VVs/ s H  u  nnUU;  d  M  UU4PM     nnnX4U4$ s  snnf )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*.
)setr   	node_data	out_edgesr   popaddr   )r"   r   filtersvisitedremovesorphansstackget_data	get_edgesget_tail	last_goodr   datafiltfuncedger   lgtls                     r   filter_stackr<   `   s   " "&sugGD<.!EHIzzH
))+	~#~~KK% $
 !	dODD>D$Y-."D!i./ $ %$ )0EHR2W3DxBxGEW$$ Fs   <DD)FF)
__doc__r
   collectionsr   altgraphr   r   r   r'   r<    r   r   <module>rA      s&   
   &&R(V+%r   