public final class Bfs extends Object
Breadth first search starts at a given set of nodes and explores the neighboring nodes first, before visiting the next level neighbors.
A breadth first search run can be either directed or undirected. All methods require a list of nodes that are considered
as the core nodes from which the breadth first search starts. These nodes can be identified either with a NodeList
or with a IDataProvider
that returns true
for core nodes and false
for all other nodes. The
output is given as an array of NodeList
s each of which contains the nodes of a particular layer.
Example for a BFS run. The marked node is the core node from which BFS starts while node labels indicate the resulting layers.
Modifier and Type | Method and Description |
---|---|
static NodeList[] |
getLayers(Graph graph,
IDataProvider isCoreNode)
Returns the layers of nodes constructed by a breadth first search.
|
static NodeList[] |
getLayers(Graph graph,
IDataProvider isCoreNode,
INodeMap layerIDMap)
Returns the layers of nodes constructed by a breadth first search.
|
static NodeList[] |
getLayers(Graph graph,
NodeList coreNodes)
Returns the layers of nodes calculated by a breadth first search.
|
static NodeList[] |
getLayers(Graph graph,
NodeList coreNodes,
BfsDirection direction,
INodeMap layerIDMap)
Returns the layers of nodes constructed by a directed/undirected breadth first search where the maximum number of layers
is restricted.
|
static NodeList[] |
getLayers(Graph graph,
NodeList coreNodes,
BfsDirection direction,
INodeMap layerIDMap,
int maxLayers)
Returns the layers of nodes constructed by a directed/undirected breadth first search where the maximum number of layers
is restricted.
|
static NodeList[] |
getLayers(Graph graph,
NodeList coreNodes,
boolean directed,
INodeMap layerIDMap)
Returns the layers of nodes constructed by a directed/undirected breadth first search where the maximum number of layers
is restricted.
|
static NodeList[] |
getLayers(Graph graph,
NodeList coreNodes,
boolean directed,
INodeMap layerIDMap,
int maxLayers)
Returns the layers of nodes constructed by a directed/undirected breadth first search where the maximum number of layers
is restricted.
|
static NodeList[] |
getLayers(Graph graph,
NodeList coreNodes,
INodeMap layerIDMap)
Returns the layers of nodes constructed by a breadth first search.
|
public static final NodeList[] getLayers(Graph graph, IDataProvider isCoreNode)
The first of these layers contains all nodes for which the given IDataProvider
returns
true
. These nodes are the core nodes from which an undirected breadth first search to the other nodes
starts.
In the i
-th layer are previously unassigned nodes that are connected to nodes in the (i-1)
-th layer.
isCoreNode.getBool(node)
defined for all nodes in graphgraph
- the given graphisCoreNode
- the IDataProvider
that contains the nodes from which the BFS starts; core nodes are marked with a true
valueNodeList
s each of which contains the nodes of a particular layerpublic static final NodeList[] getLayers(Graph graph, IDataProvider isCoreNode, INodeMap layerIDMap)
The first of these layers contains all nodes for which the given IDataProvider
returns true
. These nodes
are the core nodes from which an undirected breadth first search to the other nodes starts. The algorithm fills the
provided INodeMap
with an integer indicating the layer of each node.
In the i
-th layer are previously unassigned nodes that are connected to nodes in the (i-1)
-th layer.
isCoreNode.getBool(node)
defined for all nodes in graphgraph
- the given graphisCoreNode
- the IDataProvider
that contains the nodes from which the BFS starts; core nodes are marked with a true
valuelayerIDMap
- the INodeMap
that will be filled during the BFS execution and holds the zero-based index of the BFS layer to
which each node belongs or -1
if the node is not reachableNodeList
s each of which contains the nodes of a particular layerpublic static final NodeList[] getLayers(Graph graph, NodeList coreNodes)
The first of these layers contains all nodes within the given
NodeList
. These nodes are the core nodes from which an undirected breadth first search to the other nodes
starts.
In the i
-th layer are previously unassigned nodes that are connected to nodes in the (i-1)
-th layer.
O(graph.N() + graph.E())
graph
- the given graphcoreNodes
- the list of core nodes from which the BFS startsNodeList
s each of which contains the nodes of a particular layerpublic static final NodeList[] getLayers(Graph graph, NodeList coreNodes, BfsDirection direction, INodeMap layerIDMap)
The first of these layers contains all nodes within the given NodeList
. These nodes are the core nodes from
which a breadth first search to the other nodes starts. The algorithm fills the provided INodeMap
with an
integer indicating the layer of each node.
In the i
-th layer are previously unassigned nodes that are connected to nodes in the (i-1)
-th layer.
IllegalArgumentException
- if the given direction is not supportedNodeList
may only contain a subset of nodes (i.e., only
those with layer <= max layer).O(graph.N() + graph.E())
graph
- the given graphcoreNodes
- the list of core nodesdirection
- one of the predefined direction specifierslayerIDMap
- the INodeMap
that will be filled during the BFS execution and holds the zero-based index of the BFS layer to
which each node belongs or -1
if the node is not reachableNodeList
s each of which contains the nodes of a particular layerpublic static final NodeList[] getLayers(Graph graph, NodeList coreNodes, BfsDirection direction, INodeMap layerIDMap, int maxLayers)
The first of these layers contains all nodes within the given NodeList
. These nodes are the core nodes from
which a breadth first search to the other nodes starts. The algorithm fills the provided INodeMap
with an
integer indicating the layer of each node.
In the i
-th layer are previously unassigned nodes that are connected to nodes in the (i-1)
-th layer.
IllegalArgumentException
- if the given direction is not supportedNodeList
may only contain a subset of nodes (i.e., only
those with layer <= max layer).O(graph.N() + graph.E())
graph
- the given graphcoreNodes
- the list of core nodesdirection
- one of the predefined direction specifierslayerIDMap
- the INodeMap
that will be filled during the BFS execution and holds the zero-based index of the BFS layer to
which each node belongs or -1
if the node is not reachablemaxLayers
- the number of layers that will be returned or 0
if all layers are requiredNodeList
s each of which contains the nodes of a particular layerpublic static final NodeList[] getLayers(Graph graph, NodeList coreNodes, boolean directed, INodeMap layerIDMap)
The first of these layers contains all nodes within the given NodeList
. These nodes are the core nodes from
which either a directed or undirected breadth first search to the other nodes starts. The algorithm fills the provided INodeMap
with an integer indicating the layer of each node.
In the i
-th layer are previously unassigned nodes that are connected to nodes in the (i-1)
-th layer.
NodeList
may only contain a subset of nodes (i.e., only
those with layer <= max layer).O(graph.N() + graph.E())
graph
- the given graphcoreNodes
- the list of core nodes from which the BFS startsdirected
- true
if the graph should be considered directed, false
otherwiselayerIDMap
- the INodeMap
that will be filled during the BFS execution and holds the zero-based index of the BFS layer to
which each node belongs or -1
if the node is not reachableNodeList
s each of which contains the nodes of a particular layerpublic static final NodeList[] getLayers(Graph graph, NodeList coreNodes, boolean directed, INodeMap layerIDMap, int maxLayers)
The first of these layers contains all nodes within the given NodeList
. These nodes are the core nodes from
which either a directed or undirected breadth first search to the other nodes starts. The algorithm fills the provided INodeMap
with an integer indicating the layer of each node.
In the i
-th layer are previously unassigned nodes that are connected to nodes in the (i-1)
-th layer.
NodeList
may only contain a subset of nodes (i.e., only
those with layer <= max layer).O(graph.N() + graph.E())
graph
- the given graphcoreNodes
- the list of core nodes from which the BFS startsdirected
- true
if the graph should be considered directed, false
otherwiselayerIDMap
- the INodeMap
that will be filled during the BFS execution and holds the zero-based index of the BFS layer to
which each node belongs or -1
if the node is not reachablemaxLayers
- the number of layers that will be returned or 0
if all layers are requiredNodeList
s each of which contains the nodes of a particular layerpublic static final NodeList[] getLayers(Graph graph, NodeList coreNodes, INodeMap layerIDMap)
The first of these layers contains all nodes within the given NodeList
. These nodes are the core nodes from
which an undirected breadth first search to the other nodes starts. The algorithm fills the provided INodeMap
with an integer indicating the layer of each node.
In the i
-th layer are previously unassigned nodes that are connected to nodes in the (i-1)
-th layer.
isCoreNode.getBool(node)
defined for all nodes in graphgraph
- the given graphcoreNodes
- the list of core nodes from which the BFS startslayerIDMap
- the INodeMap
that will be filled during the BFS execution and holds the zero-based index of the BFS layer to
which each node belongs or -1
if the node is not reachableNodeList
s each of which contains the nodes of a particular layer