networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersYieldsBackRef
bfs_beam_edges(G, source, value, width=None)

The beam search is a generalized breadth-first search in which only the "best" w neighbors of the current node are enqueued, where w is the beam width and "best" is an application-specific heuristic. In general, a beam search with a small beam width might not visit each node in the graph.

Parameters

G : NetworkX graph
source : node

Starting node for the breadth-first search; this function iterates over only those edges in the component reachable from this node.

value : function

A function that takes a node of the graph as input and returns a real number indicating how "good" it is. A higher value means it is more likely to be visited sooner during the search. When visiting a new node, only the width neighbors with the highest :None:None:`value` are enqueued (in decreasing order of :None:None:`value`).

width : int (default = None)

The beam width for the search. This is the number of neighbors (ordered by :None:None:`value`) to enqueue when visiting each new node.

Iterates over edges in a beam search.

Yields

edge

Edges in the beam search starting from :None:None:`source`, given as a pair of nodes.

Examples

To give nodes with, for example, a higher centrality precedence during the search, set the :None:None:`value` function to return the centrality value of the node:

>>> G = nx.karate_club_graph()
... centrality = nx.eigenvector_centrality(G)
... source = 0
... width = 5
... for u, v in nx.bfs_beam_edges(G, source, centrality.get, width):
...  print((u, v)) ... (0, 2) (0, 1) (0, 8) (0, 13) (0, 3) (2, 32) (1, 30) (8, 33) (3, 7) (32, 31) (31, 28) (31, 25) (25, 23) (25, 24) (23, 29) (23, 27) (29, 26)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.traversal.beamsearch.bfs_beam_edges

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/traversal/beamsearch.py#8
type: <class 'function'>
Commit: