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
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.addSink(graph); 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 Class Summary
-
Constructor Summary
Constructors Constructor 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. -
Method Summary
Modifier and Type Method 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)
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
-
Constructor Details
-
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, String nodeAttribute, 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 Details
-
begin
public void begin()Start the generator. A single node is added.- Specified by:
begin
in interfaceGenerator
- See Also:
Generator.begin()
-
nextEvents
public boolean nextEvents()Step of the generator. Add a new node and connect it with some others.- Specified by:
nextEvents
in interfaceGenerator
- Returns:
- true while there are elements to add to the graph.
- See Also:
Generator.nextEvents()
-
end
public void end()Description copied from class:BaseGenerator
End the graph generation by finalizing it. Once theGenerator.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 interfaceGenerator
- Overrides:
end
in classBaseGenerator
-
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.
-
edgeAttributeAdded
public void edgeAttributeAdded(String sourceId, long timeId, String edgeId, String attribute, Object value)- Specified by:
edgeAttributeAdded
in interfaceorg.graphstream.stream.AttributeSink
-
edgeAttributeChanged
public void edgeAttributeChanged(String sourceId, long timeId, String edgeId, String attribute, Object oldValue, Object newValue)- Specified by:
edgeAttributeChanged
in interfaceorg.graphstream.stream.AttributeSink
-
edgeAttributeRemoved
- Specified by:
edgeAttributeRemoved
in interfaceorg.graphstream.stream.AttributeSink
-
graphAttributeAdded
- Specified by:
graphAttributeAdded
in interfaceorg.graphstream.stream.AttributeSink
-
graphAttributeChanged
public void graphAttributeChanged(String sourceId, long timeId, String attribute, Object oldValue, Object newValue)- Specified by:
graphAttributeChanged
in interfaceorg.graphstream.stream.AttributeSink
-
graphAttributeRemoved
- Specified by:
graphAttributeRemoved
in interfaceorg.graphstream.stream.AttributeSink
-
nodeAttributeAdded
public void nodeAttributeAdded(String sourceId, long timeId, String nodeId, String attribute, Object value)- Specified by:
nodeAttributeAdded
in interfaceorg.graphstream.stream.AttributeSink
-
nodeAttributeChanged
public void nodeAttributeChanged(String sourceId, long timeId, String nodeId, String attribute, Object oldValue, Object newValue)- Specified by:
nodeAttributeChanged
in interfaceorg.graphstream.stream.AttributeSink
-
nodeAttributeRemoved
- Specified by:
nodeAttributeRemoved
in interfaceorg.graphstream.stream.AttributeSink
-
edgeAdded
public void edgeAdded(String sourceId, long timeId, String edgeId, String fromNodeId, String toNodeId, boolean directed)- Specified by:
edgeAdded
in interfaceorg.graphstream.stream.ElementSink
-
edgeRemoved
- Specified by:
edgeRemoved
in interfaceorg.graphstream.stream.ElementSink
-
graphCleared
- Specified by:
graphCleared
in interfaceorg.graphstream.stream.ElementSink
-
nodeAdded
- Specified by:
nodeAdded
in interfaceorg.graphstream.stream.ElementSink
-
nodeRemoved
- Specified by:
nodeRemoved
in interfaceorg.graphstream.stream.ElementSink
-
stepBegins
- Specified by:
stepBegins
in interfaceorg.graphstream.stream.ElementSink
-