public class RandomGenerator extends BaseGenerator
This generator creates random graphs of any size n with given
average degree k and binomial degree distribution
B(n, k / (n - 1)). Calling begin()
creates a clique of size
k. Each call of nextEvents()
removes a small fraction of
existing edges, adds a new node and connects it randomly with some of the old
nodes.
After n - k steps we obtain a Erdős–Rényí random graph G(n, p) with p = k / (n - 1). In other words the result is the same as if we started with n isolated nodes and connected each pair of them with probability p.
This generator can work in "non-destructive" mode controlled by a
constructor parameter called allowRemove
with default value
true
. If this parameter is false
, existing edges
are never removed. The obtained graph has the same average degree, but
different degree distribution. This distribution is asymmetric, more
stretched than the binomial distribution, with a peak on the left of the
average degree. This mode is slightly faster and more memory-efficient. Use
it if you do not want edges to be removed and if you do not care about the
degree distribution.
This generator has the ability to add randomly chosen numerical values on
arbitrary attributes on edges or nodes of the graph, and to randomly choose a
direction for edges. For more information see BaseGenerator
.
Graph graph = new SingleGraph("Random"); Generator gen = new RandomGenerator(); gen.addSinkg(graph); gen.begin(); while (graph.getNodeCount() < 100 && gen.nextEvents()); gen.end(); graph.display();
Constructor and Description |
---|
RandomGenerator()
Creates a generator with default average degree of 1.
|
RandomGenerator(double averageDegree)
Creates a generator with given average degree.
|
RandomGenerator(double averageDegree,
boolean allowRemove)
Creates a generator with given average degree.
|
RandomGenerator(double averageDegree,
boolean allowRemove,
boolean directed)
Creates a generator with given average degree.
|
RandomGenerator(double averageDegree,
boolean allowRemove,
boolean directed,
java.lang.String nodeAttribute,
java.lang.String edgeAttribute)
Creates a generator with given average degree
|
Modifier and Type | Method and Description |
---|---|
void |
begin()
Starts the generator.
|
void |
end()
End the graph generation by finalizing it.
|
boolean |
nextEvents()
If edge removing is allowed, removes a small fraction of the existing
edges.
|
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 RandomGenerator()
public RandomGenerator(double averageDegree)
averageDegree
- The average degree of the resulting graph.java.lang.IllegalArgumentException
- if averageDegree
is negativepublic RandomGenerator(double averageDegree, boolean allowRemove)
averageDegree
- The average degree of the resulting graph.allowRemove
- If true, some existing edges are removed at each step.java.lang.IllegalArgumentException
- if averageDegree
is negativepublic RandomGenerator(double averageDegree, boolean allowRemove, boolean directed)
averageDegree
- The average degree of the resulting graph.allowRemove
- If true, some existing edges are removed at each step.directed
- If true, generated edges are directed.java.lang.IllegalArgumentException
- if averageDegree
is negativepublic RandomGenerator(double averageDegree, boolean allowRemove, boolean directed, java.lang.String nodeAttribute, java.lang.String edgeAttribute)
averageDegree
- The average degree of the resulting graph.allowRemove
- If true, some existing edges are removed at each step.directed
- If true, generated edges are directed.nodeAttribute
- An attribute with this name and a random numeric value is put
on each node.edgeAttribute
- An attribute with this name and a random numeric value is put
on each edge.java.lang.IllegalArgumentException
- if averageDegree
is negativepublic void begin()
Generator.begin()
public boolean nextEvents()
true
Generator.nextEvents()
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