org.graphstream.algorithm
Interface DynamicAlgorithm
- All Superinterfaces:
- Algorithm
- All Known Implementing Classes:
- CommunityDistribution, CommunityMeasure, CommunityRelativeMeasure, ConnectedComponents, DecentralizedCommunityAlgorithm, EpidemicCommunityAlgorithm, Leung, Modularity, NormalizedMutualInformation, RandomWalk, SyncEpidemicCommunityAlgorithm, VariationOfInformation
public interface DynamicAlgorithm
- extends Algorithm
Defines algorithms able to handle dynamics of a graph. This is an extension
of the Algorithm
so dynamic algorithms are
composed of an initialization step followed by several computation steps. A
last step, specific to dynamic algorithms, marks the termination of the
algorithm and has to be used to close the computation.
The following example computes the amount of apparitions of each node and the
average value of apparitions for nodes :
public class ApparitionAlgorithm extends SinkAdapter implements
DynamicAlgorithm {
Graph theGraph;
HashMap<String, Integer> apparitions;
double avg;
public void init(Graph graph) {
theGraph = graph;
avg = 0;
graph.addSink(this);
}
public void compute() {
avg = 0;
for (int a : apparitions.values())
avg += a;
avg /= apparitions.size();
}
public void terminate() {
graph.removeSink(this);
}
public double getAverageApparitions() {
return avg;
}
public int getApparitions(String nodeId) {
return apparitions.get(nodeId);
}
public void nodeAdded(String sourceId, long timeId, String nodeId) {
int a = 0;
if (apparitions.containsKey(nodeId))
a = apparitions.get(nodeId);
apparitions.put(nodeId, a + 1);
}
public void stepBegins(String sourceId, long timeId, double step) {
compute();
}
}
Note that in the example, the #terminate() method is used to remove the link
between graph and the algorithm. The computation here is done at every step
but can be done anywhere else, according to the algorithm requirements.
Method Summary |
void |
terminate()
Terminate the dynamic algorithm. |
terminate
void terminate()
- Terminate the dynamic algorithm.
- See Also:
Algorithm.init(org.graphstream.graph.Graph)
Copyright © 2011. All Rights Reserved.