
    Oh                     B    d Z ddlZddlmZ ddlmZmZ ddZddZd Z	y)	zg
altgraph.GraphUtil - Utility classes and functions
==================================================
    N)deque)Graph
GraphErrorc                    t        j                          }|s |r| | z  }n| | dz
  z  }||kD  rt        d      t        |       }|D ]  }|j                  |        	 t	        j
                  |      }t	        j
                  |      }	||	k(  r|s3|j                  ||	      |sH|j                  ||	       |j                         |k\  r	 |S p)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
             d/mnt/c/Users/Administrator/Desktop/help_/test_env/lib/python3.12/site-packages/altgraph/GraphUtil.pygenerate_random_graphr      s    
 	A 8+I HqL1IiPQQ(OE 	

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


4(*H#     c                 v   t        j                          }g }t        |      D ]J  }t        |dz   |      D ]6  }|j                  |       |j                  |       |j                  ||       8 L t        || |z        D ]  }|j	                  |       |j                  |      |k  rYt        j                  |      }	||	k(  r|s1|j                  ||	      r|sF|j                  ||	       |j                  |      |k  rY|j                  |      D ]$  }	|j                  |       |j                  |	       &  |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   )
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   s3    KKME E: !q1uj) 	!ALLOLLONN1a 	!! j%*"45 tt$z1--&C s{: !!$,[NN4% t$z1 >>$' 	CLLLL	& Lr   c                    |ht               t               }}}t        ||fg      }| j                  }| j                  }| j                  }	|r|j                         \  }
} ||      }|$|D ]  } ||      r|j                  |        n |}
 ||      D ]J  } |	|      }|
|ur|j                  |
|f       ||vs'|j                  |       |j                  |
|f       L |r|D cg c]  \  }}||vs||f }}}|||fS c c}}w )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%   " "&sugWGD$<.!EHIzzH
))+	4~# !~KK%!
 !	dO 	0DD>D$Y-.7"D!i./	0 $ )0EHR2W3DBxEGEGW$$ Fs   *D7D)FF)
__doc__r
   collectionsr   altgraphr   r   r   r'   r<    r   r   <module>rA      s&   
   &&R(V+%r   