o
    ˷e                     @   s   d Z ddlZddlmZ ddlZdddZdZej	dded	Z
ee
Zee ee
 Zd
d ZdZejZeZee
eeeZee Zede de  eje
ed	ZddddddZeje
efi e eje
eegddd e  dS )z
===========
Beam Search
===========

Beam search with dynamic beam width.

The progressive widening beam search repeatedly executes a beam search
with increasing beam width until the target node is found.
    N   c           
      C   st   ||r|S t t t| }t|D ] }|td| }t| |||D ]\}}	||	r3|	    S q%qtd)a  Progressive widening beam search to find a node.

    The progressive widening beam search involves a repeated beam
    search, starting with a small beam width then extending to
    progressively larger beam widths if the target node is not
    found. This implementation simply returns the first node found that
    matches the termination condition.

    `G` is a NetworkX graph.

    `source` is a node in the graph. The search for the node of interest
    begins here and extends only to those nodes in the (weakly)
    connected component of this node.

    `value` is a function that returns a real number indicating how good
    a potential neighbor node is when deciding which neighbor nodes to
    enqueue in the breadth-first search. Only the best nodes within the
    current beam width will be enqueued at each step.

    `condition` is the termination condition for the search. This is a
    function that takes a node as input and return a Boolean indicating
    whether the node is the target. If no node matches the termination
    condition, this function raises :exc:`NodeNotFound`.

    `initial_width` is the starting beam width for the beam search (the
    default is one). If no node matching the `condition` is found with
    this beam width, the beam search is restarted from the `source` node
    with a beam width that is twice as large (so the beam width
    increases exponentially). The search terminates after the beam width
    exceeds the number of nodes in the graph.

       z+no node satisfied the termination condition)	mathceillog2lenrangepownxbfs_beam_edgesNodeNotFound)
Gsourcevalue	conditioninitial_widthlog_miwidthuv r   }/var/www/ideatree/venv/lib/python3.10/site-packages/../../../share/doc/networkx-2.8.6/examples/algorithms/plot_beam_search.pyprogressive_widening_search   s   #
r   Y   d   g      ?)seedc                 C   s   t |  tkS )N)
centralityavg_centrality)r   r   r   r   has_high_centralityW   s   r   zfound node z with centrality blue   greyg?)
node_color	node_size
edge_color
linewidthsr   r)nodelistr$   r#   )r   )__doc__r   matplotlib.pyplotpyplotpltnetworkxr
   r   r   gnp_random_graphr   eigenvector_centralityr   sumvaluesr   r   r   r   getr   r   
found_nodecprintspring_layoutposoptionsdrawdraw_networkx_nodesshowr   r   r   r   <module>   s4    

?
