public class RandomEuclideanGenerator extends BaseGenerator implements org.graphstream.stream.Pipe
This generator creates random graphs of any size. Links of such graphs are created according to a threshold. If the Euclidean distance between two nodes is less than a given threshold, then a link is created between those 2 nodes.
Calling begin()
put one unique node in the graph, then
nextEvents()
will add a new node each time it is called and connect
this node to its neighbors according to the threshold planar Euclidean
distance.
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.
A list of attributes can be given for nodes and edges. In this case each new node or edge added will have this attribute and the value will be a randomly chosen number. The range in which these numbers are chosen can be specified.
By default, edges are not oriented. It is possible to ask orientation, in which case the direction is chosen randomly.
By default, the graph is generated in the plane (2 dimensions) . Cartesian coordinates on nodes will be generated at random. So, each node will automatically be given two attributes: "x" and "y". If a dimension is specified, then |dimension| attributes are generated, and the 2-norm distance (Euclidean distance) is considered in that dimension between the nodes.
If the dimension is 2, then attributes "x" and "y" are defined for each node. If dimension is 3, then attributes "x", "y" and "z" are used. For other values of dimension, |dimension| attributes are defined ("xi" with "i" \in |dimension|) .
Graph graph = new SingleGraph("random euclidean"); Generator gen = new RandomEuclideanGenerator(); gen.addSink(graph); gen.begin(); for(int i=0; i<1000; i++) { gen.nextEvents(); } gen.end(); graph.display(false);
Constructor and Description |
---|
RandomEuclideanGenerator()
New random Euclidean graph generator.
|
RandomEuclideanGenerator(int dimension)
New random Euclidean graph generator.
|
RandomEuclideanGenerator(int dimension,
boolean directed,
boolean randomlyDirectedEdges)
New random Euclidean graph generator.
|
RandomEuclideanGenerator(int dimension,
boolean directed,
boolean randomlyDirectedEdges,
String nodeAttribute,
String edgeAttribute)
New random Euclidean graph generator.
|
Modifier and Type | Method and Description |
---|---|
void |
begin()
Start the generator.
|
void |
edgeAdded(String sourceId,
long timeId,
String edgeId,
String fromNodeId,
String toNodeId,
boolean directed) |
void |
edgeAttributeAdded(String sourceId,
long timeId,
String edgeId,
String attribute,
Object value) |
void |
edgeAttributeChanged(String sourceId,
long timeId,
String edgeId,
String attribute,
Object oldValue,
Object newValue) |
void |
edgeAttributeRemoved(String sourceId,
long timeId,
String edgeId,
String attribute) |
void |
edgeRemoved(String sourceId,
long timeId,
String edgeId) |
void |
end()
End the graph generation by finalizing it.
|
void |
graphAttributeAdded(String sourceId,
long timeId,
String attribute,
Object value) |
void |
graphAttributeChanged(String sourceId,
long timeId,
String attribute,
Object oldValue,
Object newValue) |
void |
graphAttributeRemoved(String sourceId,
long timeId,
String attribute) |
void |
graphCleared(String sourceId,
long timeId) |
boolean |
nextEvents()
Step of the generator.
|
void |
nodeAdded(String sourceId,
long timeId,
String nodeId) |
void |
nodeAttributeAdded(String sourceId,
long timeId,
String nodeId,
String attribute,
Object value) |
void |
nodeAttributeChanged(String sourceId,
long timeId,
String nodeId,
String attribute,
Object oldValue,
Object newValue) |
void |
nodeAttributeRemoved(String sourceId,
long timeId,
String nodeId,
String attribute) |
void |
nodeRemoved(String sourceId,
long timeId,
String nodeId) |
void |
setThreshold(double threshold)
Set the threshold that defines whether or not a link is created between
to notes.
|
void |
stepBegins(String sourceId,
long timeId,
double step) |
addEdgeAttribute, addEdgeLabels, addNodeAttribute, addNodeLabels, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, setEdgeAttributesRange, setNodeAttributesRange, 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 RandomEuclideanGenerator()
public RandomEuclideanGenerator(int dimension)
dimension
- The dimension of the space for the graph. By default it is
two.public RandomEuclideanGenerator(int dimension, boolean directed, boolean randomlyDirectedEdges)
dimension
- The dimension of the space for the graph. By default it is
two.directed
- If true the edges are directed.randomlyDirectedEdges
- If true edge, are directed and the direction is chosen at
randomly.public RandomEuclideanGenerator(int dimension, boolean directed, boolean randomlyDirectedEdges, String nodeAttribute, String edgeAttribute)
dimension
- The dimension of the space for the graph. By default it is
two.directed
- If true the edges are directed.randomlyDirectedEdges
- It true, edges are directed and the direction is chosen at
random.nodeAttribute
- put an attribute by that name on each node with a random
numeric value.edgeAttribute
- put an attribute by that name on each edge with a random
numeric value.public void begin()
begin
in interface Generator
Generator.begin()
public boolean nextEvents()
nextEvents
in interface Generator
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
public void setThreshold(double threshold)
threshold
- The defined threshold.public void edgeAttributeAdded(String sourceId, long timeId, String edgeId, String attribute, Object value)
edgeAttributeAdded
in interface org.graphstream.stream.AttributeSink
public void edgeAttributeChanged(String sourceId, long timeId, String edgeId, String attribute, Object oldValue, Object newValue)
edgeAttributeChanged
in interface org.graphstream.stream.AttributeSink
public void edgeAttributeRemoved(String sourceId, long timeId, String edgeId, String attribute)
edgeAttributeRemoved
in interface org.graphstream.stream.AttributeSink
public void graphAttributeAdded(String sourceId, long timeId, String attribute, Object value)
graphAttributeAdded
in interface org.graphstream.stream.AttributeSink
public void graphAttributeChanged(String sourceId, long timeId, String attribute, Object oldValue, Object newValue)
graphAttributeChanged
in interface org.graphstream.stream.AttributeSink
public void graphAttributeRemoved(String sourceId, long timeId, String attribute)
graphAttributeRemoved
in interface org.graphstream.stream.AttributeSink
public void nodeAttributeAdded(String sourceId, long timeId, String nodeId, String attribute, Object value)
nodeAttributeAdded
in interface org.graphstream.stream.AttributeSink
public void nodeAttributeChanged(String sourceId, long timeId, String nodeId, String attribute, Object oldValue, Object newValue)
nodeAttributeChanged
in interface org.graphstream.stream.AttributeSink
public void nodeAttributeRemoved(String sourceId, long timeId, String nodeId, String attribute)
nodeAttributeRemoved
in interface org.graphstream.stream.AttributeSink
public void edgeAdded(String sourceId, long timeId, String edgeId, String fromNodeId, String toNodeId, boolean directed)
edgeAdded
in interface org.graphstream.stream.ElementSink
public void edgeRemoved(String sourceId, long timeId, String edgeId)
edgeRemoved
in interface org.graphstream.stream.ElementSink
public void graphCleared(String sourceId, long timeId)
graphCleared
in interface org.graphstream.stream.ElementSink
public void nodeAdded(String sourceId, long timeId, String nodeId)
nodeAdded
in interface org.graphstream.stream.ElementSink
public void nodeRemoved(String sourceId, long timeId, String nodeId)
nodeRemoved
in interface org.graphstream.stream.ElementSink
public void stepBegins(String sourceId, long timeId, double step)
stepBegins
in interface org.graphstream.stream.ElementSink
Copyright © 2015. All rights reserved.