Class RandomEuclideanGenerator

java.lang.Object
org.graphstream.stream.SourceBase
org.graphstream.algorithm.generator.BaseGenerator
org.graphstream.algorithm.generator.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.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).
  • 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 interface Generator
      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 interface Generator
      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 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.
    • edgeAttributeAdded

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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