public class WattsStrogatzGenerator extends BaseGenerator
This generator creates small-world graphs of arbitrary size.
This model generates a ring of n nodes where each node is connected to its k nearest neighbours in the ring (k/2 on each side, which means k must be even). Then it process each node of the ring in order following the ring, and "rewiring" each of their edges toward the not yet processed nodes with randomly chosen nodes with a probability beta.
You must provide values for n, k and beta at construction time. You must ensure that k is event, that n >> k >> log(n) >> 1. Furthermore, beta being a probability it must be between 0 and 1.
By default, the generator will produce a placement for nodes using the ``xyz`` attribute.
This generator will produce the ring of nodes once begin()
has been
called. Then calling nextEvents()
will rewire one node at a time
return true until each node is processed, in which case it returns false.
You must then call end()
.
Graph graph = new SingleGraph("This is a small world!"); Generator gen = new WattsStrogatzGenerator(20, 2, 0.5); gen.addSink(graph); gen.begin(); while(gen.nextEvents()) {} gen.end(); graph.display(false); // Node position is provided.
This generator is based on the Watts-Strogatz model.
Constructor and Description |
---|
WattsStrogatzGenerator(int n,
int k,
double beta)
New Watts-Strogatz generator.
|
Modifier and Type | Method and Description |
---|---|
void |
begin()
Begin the graph generation.
|
void |
end()
End the graph generation by finalizing it.
|
boolean |
nextEvents()
Perform the next step in generating the graph.
|
addEdgeAttribute, addEdgeAttribute, addEdgeAttribute, addEdgeLabels, addNodeAttribute, addNodeAttribute, addNodeAttribute, addNodeLabels, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, setRandomSeed, setUseInternalGraph
addAttributeSink, addElementSink, addSink, attributeSinks, clearAttributeSinks, clearElementSinks, clearSinks, elementSinks, removeAttributeSink, removeElementSink, removeSink, sendAttributeChangedEvent, sendAttributeChangedEvent, sendEdgeAdded, sendEdgeAdded, sendEdgeAttributeAdded, sendEdgeAttributeAdded, sendEdgeAttributeChanged, sendEdgeAttributeChanged, sendEdgeAttributeRemoved, sendEdgeAttributeRemoved, sendEdgeRemoved, sendEdgeRemoved, sendGraphAttributeAdded, sendGraphAttributeAdded, sendGraphAttributeChanged, sendGraphAttributeChanged, sendGraphAttributeRemoved, sendGraphAttributeRemoved, sendGraphCleared, sendGraphCleared, sendNodeAdded, sendNodeAdded, sendNodeAttributeAdded, sendNodeAttributeAdded, sendNodeAttributeChanged, sendNodeAttributeChanged, sendNodeAttributeRemoved, sendNodeAttributeRemoved, sendNodeRemoved, sendNodeRemoved, sendStepBegins, sendStepBegins
public WattsStrogatzGenerator(int n, int k, double beta)
n
- The number of nodes to generate.k
- The base degree of each node.beta
- Probability to "rewire" an edge.public void begin()
Generator
Generator.nextEvents()
method to add elements to the graph.public boolean nextEvents()
Generator
public void end()
BaseGenerator
Generator.nextEvents()
method returned false (or even if you stop before), this method must be
called to finish the graph.
In addition, BaseGenerator adds a "clear" operations that removes all the
kept edges and nodes identifiers and the associated data.end
in interface Generator
end
in class BaseGenerator