public class RandomEuclideanGenerator extends BaseGenerator implements 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);
SourceBase.ElementType
Modifier and Type | Field and Description |
---|---|
protected int |
dimension
The dimension of the space.
|
protected int |
nodeNames
Used to generate node names.
|
protected double |
threshold
The threshold that defines whether or not a link is created between to
nodes.
|
addEdgeLabels, addNodeLabels, directed, edgeAttributeRange, edgeAttributes, internalGraph, nodeAttributeRange, nodeAttributes, random, randomlyDirected
attrSinks, eltsSinks, eventProcessing, eventQueue, sourceId, sourceTime
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.
|
private double |
distance(String n1,
String n2)
Distance between two nodes.
|
void |
edgeAdded(String sourceId,
long timeId,
String edgeId,
String fromNodeId,
String toNodeId,
boolean directed)
An edge was inserted in graph.
|
void |
edgeAttributeAdded(String sourceId,
long timeId,
String edgeId,
String attribute,
Object value)
A edge attribute was added.
|
void |
edgeAttributeChanged(String sourceId,
long timeId,
String edgeId,
String attribute,
Object oldValue,
Object newValue)
A edge attribute was changed.
|
void |
edgeAttributeRemoved(String sourceId,
long timeId,
String edgeId,
String attribute)
A edge attribute was removed.
|
void |
edgeRemoved(String sourceId,
long timeId,
String edgeId)
An edge of graph was removed.The nodes the edge connects may already have
been removed from the graph.
|
void |
end()
End the graph generation by finalizing it.
|
void |
graphAttributeAdded(String sourceId,
long timeId,
String attribute,
Object value)
A graph attribute was added.
|
void |
graphAttributeChanged(String sourceId,
long timeId,
String attribute,
Object oldValue,
Object newValue)
A graph attribute was changed.
|
void |
graphAttributeRemoved(String sourceId,
long timeId,
String attribute)
A graph attribute was removed.
|
void |
graphCleared(String sourceId,
long timeId)
The whole graph was cleared.
|
private void |
initDimension(int dimension) |
boolean |
nextEvents()
Step of the generator.
|
void |
nodeAdded(String sourceId,
long timeId,
String nodeId)
A node was inserted in the given graph.
|
void |
nodeAttributeAdded(String sourceId,
long timeId,
String nodeId,
String attribute,
Object value)
A node attribute was added.
|
void |
nodeAttributeChanged(String sourceId,
long timeId,
String nodeId,
String attribute,
Object oldValue,
Object newValue)
A node attribute was changed.
|
protected void |
nodeAttributeHandling(String nodeId,
String key,
Object val) |
void |
nodeAttributeRemoved(String sourceId,
long timeId,
String nodeId,
String attribute)
A node attribute was removed.
|
void |
nodeRemoved(String sourceId,
long timeId,
String nodeId)
A node was removed from the graph.
|
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)
Since dynamic graphs are based on discrete event modifications, the
notion of step is defined to simulate elapsed time between events.
|
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 nodeNames
protected int dimension
protected double threshold
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.private void initDimension(int dimension)
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
private double distance(String n1, String n2)
n1
- first noden2
- second nodepublic void setThreshold(double threshold)
threshold
- The defined threshold.protected void nodeAttributeHandling(String nodeId, String key, Object val)
public void edgeAttributeAdded(String sourceId, long timeId, String edgeId, String attribute, Object value)
AttributeSink
edgeAttributeAdded
in interface AttributeSink
sourceId
- Identifier of the graph where the change occurred.edgeId
- Identifier of the edge whose attribute changed.attribute
- The attribute name.value
- The attribute new value.public void edgeAttributeChanged(String sourceId, long timeId, String edgeId, String attribute, Object oldValue, Object newValue)
AttributeSink
edgeAttributeChanged
in interface AttributeSink
sourceId
- Identifier of the graph where the change occurred.edgeId
- Identifier of the edge whose attribute changed.attribute
- The attribute name.oldValue
- The attribute old value.newValue
- The attribute new value.public void edgeAttributeRemoved(String sourceId, long timeId, String edgeId, String attribute)
AttributeSink
edgeAttributeRemoved
in interface AttributeSink
sourceId
- Identifier of the graph where the attribute was removed.edgeId
- Identifier of the edge whose attribute was removed.attribute
- The removed attribute name.public void graphAttributeAdded(String sourceId, long timeId, String attribute, Object value)
AttributeSink
graphAttributeAdded
in interface AttributeSink
sourceId
- Identifier of the graph where the attribute changed.attribute
- The attribute name.value
- The attribute new value.public void graphAttributeChanged(String sourceId, long timeId, String attribute, Object oldValue, Object newValue)
AttributeSink
graphAttributeChanged
in interface AttributeSink
sourceId
- Identifier of the graph where the attribute changed.attribute
- The attribute name.oldValue
- The attribute old value.newValue
- The attribute new value.public void graphAttributeRemoved(String sourceId, long timeId, String attribute)
AttributeSink
graphAttributeRemoved
in interface AttributeSink
sourceId
- Identifier of the graph where the attribute was removed.attribute
- The removed attribute name.public void nodeAttributeAdded(String sourceId, long timeId, String nodeId, String attribute, Object value)
AttributeSink
nodeAttributeAdded
in interface AttributeSink
sourceId
- Identifier of the graph where the change occurred.nodeId
- Identifier of the node whose attribute changed.attribute
- The attribute name.value
- The attribute new value.public void nodeAttributeChanged(String sourceId, long timeId, String nodeId, String attribute, Object oldValue, Object newValue)
AttributeSink
nodeAttributeChanged
in interface AttributeSink
sourceId
- Identifier of the graph where the change occurred.nodeId
- Identifier of the node whose attribute changed.attribute
- The attribute name.oldValue
- The attribute old value.newValue
- The attribute new value.public void nodeAttributeRemoved(String sourceId, long timeId, String nodeId, String attribute)
AttributeSink
nodeAttributeRemoved
in interface AttributeSink
sourceId
- Identifier of the graph where the attribute was removed.nodeId
- Identifier of the node whose attribute was removed.attribute
- The removed attribute name.public void edgeAdded(String sourceId, long timeId, String edgeId, String fromNodeId, String toNodeId, boolean directed)
ElementSink
edgeAdded
in interface ElementSink
sourceId
- Identifier of the graph where the edge was added.edgeId
- Identifier of the added edge.fromNodeId
- Identifier of the first node of the edge.toNodeId
- Identifier of the second node of the edge.directed
- If true, the edge is directed.public void edgeRemoved(String sourceId, long timeId, String edgeId)
ElementSink
edgeRemoved
in interface ElementSink
sourceId
- The graph where the edge will be removed.edgeId
- The edge that will be removed.public void graphCleared(String sourceId, long timeId)
ElementSink
graphCleared
in interface ElementSink
sourceId
- The graph cleared.public void nodeAdded(String sourceId, long timeId, String nodeId)
ElementSink
nodeAdded
in interface ElementSink
sourceId
- Identifier of the graph where the node was added.nodeId
- Identifier of the added node.public void nodeRemoved(String sourceId, long timeId, String nodeId)
ElementSink
nodeRemoved
in interface ElementSink
sourceId
- Identifier of the graph where the node will be removed.nodeId
- Identifier of the removed node.public void stepBegins(String sourceId, long timeId, double step)
ElementSink
Since dynamic graphs are based on discrete event modifications, the notion of step is defined to simulate elapsed time between events. So a step is a event that occurs in the graph, it does not modify it but it gives a kind of timestamp that allow the tracking of the progress of the graph over the time.
This kind of event is useful for dynamic algorithms that listen to the dynamic graph and need to measure the time in the graph's evolution.
stepBegins
in interface ElementSink
sourceId
- Identifier of the graph where the step starts.timeId
- A numerical value that may give a timestamp to track the
evolution of the graph over the time.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses