Class BFS
java.lang.Object
org.biopax.paxtools.query.algorithm.BFS
- Direct Known Subclasses:
CycleBreaker
Implements breadth-first search. Takes a set of source nodes, distance limit and labels nodes
towards one direction, with their breadth distances.
- Author:
- Ozgun Babur, Merve Cakir
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanBackward traversal direction.static final intColor black indicates that the node was processed.protected Map<GraphObject, Integer> Color labels.protected DirectionWhether the direction is FORWARD, it is REVERSE otherwise.protected Map<GraphObject, Integer> Distance labels.static final booleanBackward traversal direction.static final booleanForward traversal direction.static final intColor gray indicates that the node is in queue waiting to be procecessed.protected intStop distance.protected LinkedList<Node> BFS queue.BFS starts from source nodes.BFS will not further traverse neighbors of any node in the stopSet.static final booleanForward traversal direction.static final intColor white indicates the node is not processed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intGets color tag of the nodeintgetLabel(GraphObject go) Gets the distance label of the object.protected voidinitMaps()Initializes maps used during query.protected booleanisEquivalentInTheSet(Node node, boolean direction, Set<Node> set) Checks if an equivalent of the given node is in the set.protected booleanisEquivalentInTheSet(Node node, Set<Node> set) Checks if an equivalent of the given node is in the set.protected voidlabelEquivRecursive(Node node, boolean up, int dist, boolean enqueue, boolean head) Labels equivalent nodes recursively.protected voidprocessNode(Node current) Processes a node.run()Executes the algorithm.protected voidSets color tagprotected voidsetLabel(GraphObject go, int label) Sets the distance label.
-
Field Details
-
dist
Distance labels. Missing label interpreted as infinitive. -
colors
Color labels. Missing color interpreted as white. -
sourceSet
BFS starts from source nodes. They get the label 0. -
stopSet
BFS will not further traverse neighbors of any node in the stopSet. -
direction
Whether the direction is FORWARD, it is REVERSE otherwise. -
limit
protected int limitStop distance. -
queue
BFS queue. -
FORWARD
public static final boolean FORWARDForward traversal direction.- See Also:
-
BACKWARD
public static final boolean BACKWARDBackward traversal direction.- See Also:
-
UPWARD
public static final boolean UPWARDForward traversal direction.- See Also:
-
DOWNWARD
public static final boolean DOWNWARDBackward traversal direction.- See Also:
-
WHITE
public static final int WHITEColor white indicates the node is not processed.- See Also:
-
GRAY
public static final int GRAYColor gray indicates that the node is in queue waiting to be procecessed.- See Also:
-
BLACK
public static final int BLACKColor black indicates that the node was processed.- See Also:
-
-
Constructor Details
-
BFS
Constructor with all parameters.- Parameters:
sourceSet- Seed of BFSstopSet- Nodes that won't be traverseddirection- Direction of the traversallimit- Distance limit
-
BFS
public BFS()Empty constructor for other possible uses.
-
-
Method Details
-
run
Executes the algorithm.- Returns:
- BFS tree
-
initMaps
protected void initMaps()Initializes maps used during query. -
processNode
Processes a node.- Parameters:
current- The current node
-
labelEquivRecursive
Labels equivalent nodes recursively.- Parameters:
node- Node to label equivalentsup- Traversing direction. Up means towards parents, if false then towards childrendist- The labelenqueue- Whether to enqueue equivalentshead- Where to enqueue. Head or tail.
-
isEquivalentInTheSet
Checks if an equivalent of the given node is in the set.- Parameters:
node- Node to check equivalentsset- Node set- Returns:
- true if an equivalent is in the set
-
isEquivalentInTheSet
Checks if an equivalent of the given node is in the set.- Parameters:
node- Node to check equivalentsdirection- Direction to go to get equivalentsset- Node set- Returns:
- true if an equivalent is in the set
-
getColor
Gets color tag of the node- Parameters:
node- Node to get color tag- Returns:
- color tag
-
setColor
Sets color tag- Parameters:
node- node to set color tagcolor- the color tag
-
getLabel
Gets the distance label of the object.- Parameters:
go- object to get the distance- Returns:
- the distance label
-
setLabel
Sets the distance label.- Parameters:
go- object to set the distance labellabel- the distance label
-