org.graphstream.algorithm.generator

## Class RandomEuclideanGenerator

• All Implemented Interfaces:
Generator, org.graphstream.stream.AttributeSink, org.graphstream.stream.ElementSink, org.graphstream.stream.Pipe, org.graphstream.stream.Sink, org.graphstream.stream.Source

public class RandomEuclideanGenerator
extends BaseGenerator
implements org.graphstream.stream.Pipe
Random Euclidean graph generator.

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.

## Usage

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|) .

## Complexity

For the construction of a n nodes graph, the complexity is about O(n^2).

## Example

 Graph graph = new SingleGraph("random euclidean");
Generator gen = new RandomEuclideanGenerator();
gen.begin();
for(int i=0; i<1000; i++) {
gen.nextEvents();
}
gen.end();
graph.display(false);

Since:
June 25 2007
Computational Complexity:
For the construction of a n nodes graph, the complexity is about O(n^2).

• ### Nested classes/interfaces inherited from class org.graphstream.stream.SourceBase

org.graphstream.stream.SourceBase.ElementType
• ### Constructor Summary

Constructors
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, java.lang.String nodeAttribute, java.lang.String edgeAttribute)
New random Euclidean graph generator.
• ### Method Summary

All Methods
Modifier and Type Method and Description
void begin()
Start the generator.
void edgeAdded(java.lang.String sourceId, long timeId, java.lang.String edgeId, java.lang.String fromNodeId, java.lang.String toNodeId, boolean directed)
void edgeAttributeAdded(java.lang.String sourceId, long timeId, java.lang.String edgeId, java.lang.String attribute, java.lang.Object value)
void edgeAttributeChanged(java.lang.String sourceId, long timeId, java.lang.String edgeId, java.lang.String attribute, java.lang.Object oldValue, java.lang.Object newValue)
void edgeAttributeRemoved(java.lang.String sourceId, long timeId, java.lang.String edgeId, java.lang.String attribute)
void edgeRemoved(java.lang.String sourceId, long timeId, java.lang.String edgeId)
void end()
End the graph generation by finalizing it.
void graphAttributeAdded(java.lang.String sourceId, long timeId, java.lang.String attribute, java.lang.Object value)
void graphAttributeChanged(java.lang.String sourceId, long timeId, java.lang.String attribute, java.lang.Object oldValue, java.lang.Object newValue)
void graphAttributeRemoved(java.lang.String sourceId, long timeId, java.lang.String attribute)
void graphCleared(java.lang.String sourceId, long timeId)
boolean nextEvents()
Step of the generator.
void nodeAdded(java.lang.String sourceId, long timeId, java.lang.String nodeId)
void nodeAttributeAdded(java.lang.String sourceId, long timeId, java.lang.String nodeId, java.lang.String attribute, java.lang.Object value)
void nodeAttributeChanged(java.lang.String sourceId, long timeId, java.lang.String nodeId, java.lang.String attribute, java.lang.Object oldValue, java.lang.Object newValue)
void nodeAttributeRemoved(java.lang.String sourceId, long timeId, java.lang.String nodeId, java.lang.String attribute)
void nodeRemoved(java.lang.String sourceId, long timeId, java.lang.String nodeId)
void setThreshold(double threshold)
Set the threshold that defines whether or not a link is created between to notes.
void stepBegins(java.lang.String sourceId, long timeId, double step)
• ### Methods inherited from class org.graphstream.algorithm.generator.BaseGenerator

addEdgeAttribute, addEdgeAttribute, addEdgeAttribute, addEdgeLabels, addNodeAttribute, addNodeAttribute, addNodeAttribute, addNodeLabels, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, setRandomSeed, setUseInternalGraph
• ### Methods inherited from class org.graphstream.stream.SourceBase

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
• ### Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Methods inherited from interface org.graphstream.stream.Source

addAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSink
• ### Constructor Detail

• #### RandomEuclideanGenerator

public RandomEuclideanGenerator()
New random Euclidean graph generator. By default no attributes are added to nodes and edges. Dimension of the space is two.
• #### RandomEuclideanGenerator

public RandomEuclideanGenerator(int dimension)
New random Euclidean graph generator. By default no attributes are added to nodes and edges. You may also specify a dimension for the space.
Parameters:
dimension - The dimension of the space for the graph. By default it is two.
• #### RandomEuclideanGenerator

public RandomEuclideanGenerator(int dimension,
boolean directed,
boolean randomlyDirectedEdges)
New random Euclidean graph generator. By default no attributes are added to nodes and edges. It is possible to make edge randomly directed. You may also specify a dimension for the space.
Parameters:
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.
• #### RandomEuclideanGenerator

public RandomEuclideanGenerator(int dimension,
boolean directed,
boolean randomlyDirectedEdges,
java.lang.String nodeAttribute,
java.lang.String edgeAttribute)
New random Euclidean graph generator.
Parameters:
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.
• ### Method Detail

• #### begin

public void begin()
Start the generator. A single node is added.
Specified by:
begin in interface Generator
Generator.begin()
• #### nextEvents

public boolean nextEvents()
Step of the generator. Add a new node and connect it with some others.
Specified by:
nextEvents in interface Generator
Returns:
true while there are elements to add to the graph.
Generator.nextEvents()
• #### end

public void end()
Description copied from class: BaseGenerator
End the graph generation by finalizing it. Once the 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.
Specified by:
end in interface Generator
Overrides:
end in class BaseGenerator
• #### setThreshold

public void setThreshold(double threshold)
Set the threshold that defines whether or not a link is created between to notes. Since the coordinate system is defined between 0 and 1, the threshold has to be set between these two bounds.
Parameters:
threshold - The defined threshold.

public void edgeAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute,
java.lang.Object value)
Specified by:
edgeAttributeAdded in interface org.graphstream.stream.AttributeSink
• #### edgeAttributeChanged

public void edgeAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
Specified by:
edgeAttributeChanged in interface org.graphstream.stream.AttributeSink
• #### edgeAttributeRemoved

public void edgeAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute)
Specified by:
edgeAttributeRemoved in interface org.graphstream.stream.AttributeSink

public void graphAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String attribute,
java.lang.Object value)
Specified by:
graphAttributeAdded in interface org.graphstream.stream.AttributeSink
• #### graphAttributeChanged

public void graphAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
Specified by:
graphAttributeChanged in interface org.graphstream.stream.AttributeSink
• #### graphAttributeRemoved

public void graphAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String attribute)
Specified by:
graphAttributeRemoved in interface org.graphstream.stream.AttributeSink

public void nodeAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute,
java.lang.Object value)
Specified by:
nodeAttributeAdded in interface org.graphstream.stream.AttributeSink
• #### nodeAttributeChanged

public void nodeAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
Specified by:
nodeAttributeChanged in interface org.graphstream.stream.AttributeSink
• #### nodeAttributeRemoved

public void nodeAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute)
Specified by:
nodeAttributeRemoved in interface org.graphstream.stream.AttributeSink

public void edgeAdded(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String fromNodeId,
java.lang.String toNodeId,
boolean directed)
Specified by:
edgeAdded in interface org.graphstream.stream.ElementSink
• #### edgeRemoved

public void edgeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String edgeId)
Specified by:
edgeRemoved in interface org.graphstream.stream.ElementSink
• #### graphCleared

public void graphCleared(java.lang.String sourceId,
long timeId)
Specified by:
graphCleared in interface org.graphstream.stream.ElementSink

public void nodeAdded(java.lang.String sourceId,
long timeId,
java.lang.String nodeId)
Specified by:
nodeAdded in interface org.graphstream.stream.ElementSink
• #### nodeRemoved

public void nodeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String nodeId)
Specified by:
nodeRemoved in interface org.graphstream.stream.ElementSink
• #### stepBegins

public void stepBegins(java.lang.String sourceId,
long timeId,
double step)
Specified by:
stepBegins in interface org.graphstream.stream.ElementSink