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.
SourceBase.ElementType
Modifier and Type | Field and Description |
---|---|
protected double |
beta
Probability to "rewire" an edge.
|
protected int |
current
Current rewired node, used to allo nextEvents() iteration.
|
protected int |
k
Base degree of each node.
|
protected int |
n
The number of nodes to generate.
|
addEdgeLabels, addNodeLabels, directed, edgeAttributeRange, edgeAttributes, internalGraph, nodeAttributeRange, nodeAttributes, random, randomlyDirected
attrSinks, eltsSinks, eventProcessing, eventQueue, sourceId, sourceTime
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.
|
protected int |
chooseNewNode(int avoid,
int old) |
protected String |
edgeId(int from,
int to) |
void |
end()
End the graph generation by finalizing it.
|
boolean |
nextEvents()
Perform the next step in generating the graph.
|
protected String |
nodeId(int id) |
addEdge, addEdgeAttribute, addEdgeLabels, addNode, addNode, addNodeAttribute, addNodeLabels, clearKeptData, delEdge, delNode, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, setEdgeAttributesRange, setNodeAttributesRange, setRandomSeed, setUseInternalGraph
addAttributeSink, addElementSink, addSink, attributeSinks, clearAttributeSinks, clearElementSinks, clearSinks, elementSinks, manageEvents, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSink
protected int n
protected int k
protected double beta
protected int current
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
protected int chooseNewNode(int avoid, int old)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses