Computes the layers of nodes constructed by a directed or undirected breadth-first search.
Remarks
The first of these layers contains all coreNodes from which a breadth-first search to the other nodes starts.
Each layer i contains nodes that have a path of length i to at least one of the coreNodes. Nodes that are unreachable because there is no path to them, or the path's length exceeds layerCount have a layer index of -1
instead.
The search can be directed or undirected. In a directed search the edges can be traversed either forwards (from source to target) or backwards.
Examples
// configure the algorithm
const algorithm = new Bfs({
// specify the nodes of the 0-th layer to start from
coreNodes: centerNode
})
// run the algorithm
const result = algorithm.run(graph)
// add labels to indicate the layer
result.nodeLayerIds.forEach(({ key: node, value: id }) =>
graph.addLabel(node, String(id))
)
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.analysis.Bfs
See Also
Constructors
Creates a new Bfs instance.
Parameters
A map of options to pass to the method.
- coreNodes - ItemCollection<INode>
A collection of nodes to start from. This option sets the coreNodes property on the created object.
- traversalDirection - TraversalDirection
A value indicating whether to follow only incoming, only outgoing, both only incoming and only outgoing, or any edges independent of their direction. This option sets the traversalDirection property on the created object.
- layerCount - number
The number of layers to return. This option sets the layerCount property on the created object.
- subgraphNodes - ItemCollection<INode>
The collection of nodes which define a subset of the graph for the algorithms to work on. This option sets the subgraphNodes property on the created object.
- subgraphEdges - ItemCollection<IEdge>
The collection of edges which define a subset of the graph for the algorithms to work on. This option sets the subgraphEdges property on the created object.
Properties
Gets or sets a collection of nodes to start from.
Remarks
Gets or sets the collection of edges which define a subset of the graph for the algorithms to work on.
Remarks
If nothing is set, all edges of the graph will be processed.
If only the excludes are set all edges in the graph except those provided in the excludes are processed.
Note that edges which start or end at nodes which are not in the subgraphNodes are automatically not considered by the algorithm.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.
Examples
Gets or sets the collection of nodes which define a subset of the graph for the algorithms to work on.
Remarks
If nothing is set, all nodes of the graph will be processed.
If only the excludes are set all nodes in the graph except those provided in the excludes are processed.
ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.
Examples
Gets or sets a value indicating whether to follow only incoming, only outgoing, both only incoming and only outgoing, or any edges independent of their direction.
Remarks
When BOTH is used, the node layers for SUCCESSOR and for PREDECESSOR are calculated and for each node the smaller of both layers is used. This may result in some layers staying empty for the combined layer assignment.
Default is UNDIRECTED.
Methods
Returns the layers of nodes constructed by a breadth-first search.
Complexity
O(|V| + |E|)
Parameters
A map of options to pass to the method.
- graph - IGraph
- The input graph to run the algorithm on.
Returns
Throws
- Exception({ name: 'InvalidOperationError' })
- if no coreNodes are provided.
- Exception({ name: 'InvalidOperationError' })
- If the algorithm can't create a valid result due to an invalid graph structure or wrongly configured properties.