Class WeaklyConnectedComponentsAlgorithm
- java.lang.Object
-
- org.insa.graphs.algorithm.AbstractAlgorithm<WeaklyConnectedComponentObserver>
-
- org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentsAlgorithm
-
public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<WeaklyConnectedComponentObserver>
-
-
Field Summary
-
Fields inherited from class org.insa.graphs.algorithm.AbstractAlgorithm
data, observers
-
-
Constructor Summary
Constructors Constructor Description WeaklyConnectedComponentsAlgorithm(WeaklyConnectedComponentsData data)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.ArrayList<Node>
bfs(java.util.ArrayList<java.util.HashSet<java.lang.Integer>> ugraph, boolean[] marked, int cur)
Apply a breadth first search algorithm on the given undirected graph (adjacency list), starting at node cur, and marking nodes in marked.protected java.util.ArrayList<java.util.HashSet<java.lang.Integer>>
createUndirectedGraph()
protected WeaklyConnectedComponentsSolution
doRun()
Abstract method that should be implemented by child class.WeaklyConnectedComponentsData
getInputData()
protected void
notifyEndComponent(java.util.ArrayList<Node> nodes)
Notify all observers that the algorithm has computed a new component.protected void
notifyNewNodeInComponent(Node node)
Notify all observers that a new node has been found for the current component.protected void
notifyStartComponent(Node curNode)
Notify all observers that the algorithm is entering a new component.WeaklyConnectedComponentsSolution
run()
Run the algorithm and return the solution.-
Methods inherited from class org.insa.graphs.algorithm.AbstractAlgorithm
addObserver, getObservers
-
-
-
-
Constructor Detail
-
WeaklyConnectedComponentsAlgorithm
public WeaklyConnectedComponentsAlgorithm(WeaklyConnectedComponentsData data)
- Parameters:
data
- Input data for this algorithm.
-
-
Method Detail
-
run
public WeaklyConnectedComponentsSolution run()
Description copied from class:AbstractAlgorithm
Run the algorithm and return the solution. This methods internally time the call to doRun() and update the result of the call with the computed solving time.- Overrides:
run
in classAbstractAlgorithm<WeaklyConnectedComponentObserver>
- Returns:
- The solution found by the algorithm (may not be a feasible solution).
-
getInputData
public WeaklyConnectedComponentsData getInputData()
- Overrides:
getInputData
in classAbstractAlgorithm<WeaklyConnectedComponentObserver>
- Returns:
- Input for this algorithm.
-
notifyStartComponent
protected void notifyStartComponent(Node curNode)
Notify all observers that the algorithm is entering a new component.- Parameters:
curNode
- Starting node for the component.
-
notifyNewNodeInComponent
protected void notifyNewNodeInComponent(Node node)
Notify all observers that a new node has been found for the current component.- Parameters:
node
- New node found for the current component.
-
notifyEndComponent
protected void notifyEndComponent(java.util.ArrayList<Node> nodes)
Notify all observers that the algorithm has computed a new component.- Parameters:
nodes
- List of nodes in the component.
-
createUndirectedGraph
protected java.util.ArrayList<java.util.HashSet<java.lang.Integer>> createUndirectedGraph()
- Returns:
- An adjacency list for the undirected graph equivalent to the stored graph.
-
bfs
protected java.util.ArrayList<Node> bfs(java.util.ArrayList<java.util.HashSet<java.lang.Integer>> ugraph, boolean[] marked, int cur)
Apply a breadth first search algorithm on the given undirected graph (adjacency list), starting at node cur, and marking nodes in marked.- Parameters:
marked
-cur
-- Returns:
-
doRun
protected WeaklyConnectedComponentsSolution doRun()
Description copied from class:AbstractAlgorithm
Abstract method that should be implemented by child class.- Specified by:
doRun
in classAbstractAlgorithm<WeaklyConnectedComponentObserver>
- Returns:
- The solution found, must not be null (use an infeasible or unknown status if necessary).
-
-