org.graphstream.algorithm.generator
Class RandomGenerator

java.lang.Object
  extended by org.graphstream.stream.SourceBase
      extended by org.graphstream.algorithm.generator.BaseGenerator
          extended by org.graphstream.algorithm.generator.RandomGenerator
All Implemented Interfaces:
Generator, org.graphstream.stream.Source

public class RandomGenerator
extends BaseGenerator

Random graph generator.

Generate a random graph of any size.

Usage

This generator creates random graphs of any size. 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 randomly to others.

The generator tries to generate nodes with random connections, with each node having in average a given degree. The law in a Poisson law, however, the way this generator works, adding node after node, perturbs this process. We should first allocate all the needed nodes, then create edges. However, we create nodes at the same rate as edges. The more nodes are added the more the degree distribution curve is shifted toward the right.

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.

Complexity

At each call to nextEvents() at max k operations are run with k the average degree.

Example

 Graph graph = new SingleGraph("Random");
 Generator gen = new RandomGenerator();
 gen.addSinkg(graph);
 gen.begin();
 for(int i=0; i<100; i++)
        gen.nextEvents();
 gen.end();
 graph.display();
 

Since:
2007

Nested Class Summary
 
Nested classes/interfaces inherited from class org.graphstream.stream.SourceBase
org.graphstream.stream.SourceBase.ElementType
 
Constructor Summary
RandomGenerator()
          New full graph generator with default attributes.
RandomGenerator(int averageDegree)
          New full graph generator.
RandomGenerator(int averageDegree, boolean directed, boolean randomlyDirectedEdges)
          New full graph generator.
RandomGenerator(int averageDegree, boolean directed, boolean randomlyDirectedEdges, String nodeAttribute, String edgeAttribute)
          New random graph generator.
 
Method Summary
 void begin()
          Start the generator.
 void end()
          End the graph generation by finalizing it.
 boolean nextEvents()
          Step the generator.
 
Methods inherited from class org.graphstream.algorithm.generator.BaseGenerator
addEdgeAttribute, addEdgeLabels, addNodeAttribute, addNodeLabels, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, setEdgeAttributesRange, setNodeAttributesRange, 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, sendEdgeRemoved, sendEdgeRemoved, sendGraphCleared, sendGraphCleared, sendNodeAdded, sendNodeAdded, 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

RandomGenerator

public RandomGenerator()
New full graph generator with default attributes.


RandomGenerator

public RandomGenerator(int averageDegree)
New full graph generator. By default no attributes are added to nodes and edges, and edges are not directed.

Parameters:
averageDegree - The average degree of nodes.

RandomGenerator

public RandomGenerator(int averageDegree,
                       boolean directed,
                       boolean randomlyDirectedEdges)
New full graph generator.

Parameters:
averageDegree - The average degree of nodes.
directed - Are edges directed?.
randomlyDirectedEdges - randomly direct generated edges.

RandomGenerator

public RandomGenerator(int averageDegree,
                       boolean directed,
                       boolean randomlyDirectedEdges,
                       String nodeAttribute,
                       String edgeAttribute)
New random graph generator.

Parameters:
averageDegree - The average degree of nodes.
directed - Are edges directed?.
randomlyDirectedEdges - randomly direct generated edges.
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.

See Also:
Generator.begin()

nextEvents

public boolean nextEvents()
Step the generator. A new node is added and connected with some others.

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


Copyright © 2011. All Rights Reserved.