public interface Algorithm
Algorithm interface aims to define algorithms that do no handle dynamics of
the graph, whereas algorithms implementing the
DynamicAlgorithm
interface (an extended
version of Algorithm) are able to handle this dynamics.
This following is an example of an algorithm that computes max, min and average degrees of a graph:
public class DegreesAlgorithm implements Algorithm { Graph theGraph; int minDegree, maxDegree, avgDegree; public void init(Graph graph) { theGraph = graph; } public void compute() { avgDegree = 0; minDegree = Integer.MAX_VALUE; maxDegree = 0; for(Node n : theGraph.getEachNode() ) { int deg = n.getDegree(); minDegree = Math.min(minDegree, d); maxDegree = Math.max(maxDegree, d); avgDegree += d; } avgDegree /= theGraph.getNodeCount(); } public int getMaxDegree() { return maxDegree; } public int getMinDegree() { return minDegree; } public int getAverageDegree() { return avgDegree; } }
Complexity of algorithms can be specify in the documentation with the help of the "@complexity" tag.
Modifier and Type | Method and Description |
---|---|
void |
compute()
Run the algorithm.
|
void |
init(org.graphstream.graph.Graph graph)
Initialization of the algorithm.
|
void init(org.graphstream.graph.Graph graph)
compute()
method to initialize or reset the algorithm according
to the new given graph.graph
- The graph this algorithm is using.void compute()
init(Graph)
method has to be called
before computing.init(Graph)