|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Algorithm
Algorithms are used to compute properties on graphs or graph elements. These properties could be a measure, color, spanning tree, etc... Algorithms are divided into two steps :
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.
Method Summary | |
---|---|
void |
compute()
Run the algorithm. |
void |
init(org.graphstream.graph.Graph graph)
Initialization of the algorithm. |
Method Detail |
---|
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)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |