Class BaseGenerator

java.lang.Object
org.graphstream.stream.SourceBase
org.graphstream.algorithm.generator.BaseGenerator
All Implemented Interfaces:
Generator, org.graphstream.stream.Source
Direct Known Subclasses:
BananaTreeGenerator, BarabasiAlbertGenerator, ChainGenerator, ChvatalGenerator, DorogovtsevMendesGenerator, FlowerSnarkGenerator, FullGenerator, GridGenerator, HypercubeGenerator, IncompleteGridGenerator, LCFGenerator, LifeGenerator, LobsterGenerator, PetersenGraphGenerator, PointsOfInterestGenerator, PreferentialAttachmentGenerator, RandomEuclideanGenerator, RandomFixedDegreeDynamicGraphGenerator, RandomGenerator, URLGenerator, WattsStrogatzGenerator

public abstract class BaseGenerator
extends org.graphstream.stream.SourceBase
implements Generator
Base graph generator.

This class is a base to implement generators. It it has facilities to generate edges or nodes, and provides services to add attributes on them and to choose if the edge is directed or not.

Indeed, 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, and in addition to ask that the direction be chosen randomly (by default, if edges must be oriented, the order given for the two nodes to connect is used).

Since:
2007
  • Nested Class Summary

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

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

    Constructors 
    Constructor Description
    BaseGenerator()
    New base graph generator.
    BaseGenerator​(boolean directed, boolean randomlyDirectedEdges)
    New base graph generator.
    BaseGenerator​(boolean directed, boolean randomlyDirectedEdges, String nodeAttribute, String edgeAttribute)
    New base graph generator.
  • Method Summary

    Modifier and Type Method Description
    void addEdgeAttribute​(String name)
    Same as addEdgeAttribute(String, Function) with default factory function.
    void addEdgeAttribute​(String name, double min, double max)
    Same as addEdgeAttribute(String, Function) with default factory function.
    void addEdgeAttribute​(String name, Function<Random,​?> factory)
    Add this attribute on all edges generated.
    void addEdgeLabels​(boolean on)
    Allow to add label attributes on edges.
    void addNodeAttribute​(String name)
    Same as addNodeAttribute(String, Function) with default factory function.
    void addNodeAttribute​(String name, double min, double max)
    Same as addNodeAttribute(String, Function) with default factory function.
    void addNodeAttribute​(String name, Function<Random,​?> factory)
    Add this attribute on all nodes generated.
    void addNodeLabels​(boolean on)
    Allow to add label attributes on nodes.
    void end()
    End the graph generation by finalizing it.
    boolean isUsingInternalGraph()
    Flag to know if an internal graph is in use.
    void removeEdgeAttribute​(String name)
    Remove an automatic attribute for edges.
    void removeNodeAttribute​(String name)
    Remove an automatic attribute for nodes.
    void setDirectedEdges​(boolean directed, boolean randomly)
    Make each generated edge directed or not.
    void setRandomSeed​(long seed)
    Set the random seed used for random number generation.
    void setUseInternalGraph​(boolean on)
    Enable or disable the use of an internal graph.

    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.algorithm.generator.Generator

    begin, nextEvents

    Methods inherited from interface org.graphstream.stream.Source

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

    • BaseGenerator

      public BaseGenerator()
      New base graph generator. By default no attributes are added to nodes and edges, and edges are not directed.
    • BaseGenerator

      public BaseGenerator​(boolean directed, boolean randomlyDirectedEdges)
      New base graph generator. By default no attributes are added to nodes and edges. It is possible to make edge randomly directed.
      Parameters:
      directed - If true the edges are directed.
      randomlyDirectedEdges - If true edge, are directed and the direction is chosen randomly.
    • BaseGenerator

      public BaseGenerator​(boolean directed, boolean randomlyDirectedEdges, String nodeAttribute, String edgeAttribute)
      New base graph generator.
      Parameters:
      directed - If true the edges are directed.
      randomlyDirectedEdges - It true, edges are directed and the direction is choosed randomly.
      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

    • end

      public void end()
      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
    • setRandomSeed

      public void setRandomSeed​(long seed)
      Set the random seed used for random number generation.
      Parameters:
      seed - The seed.
    • addNodeLabels

      public void addNodeLabels​(boolean on)
      Allow to add label attributes on nodes. The label is the identifier of the node.
      Parameters:
      on - If true labels are added.
    • addEdgeLabels

      public void addEdgeLabels​(boolean on)
      Allow to add label attributes on edges. The label is the identifier of the edge.
      Parameters:
      on - If true labels are added.
    • setDirectedEdges

      public void setDirectedEdges​(boolean directed, boolean randomly)
      Make each generated edge directed or not. If the new edge created are directed, the direction is chosen randomly.
      Parameters:
      directed - It true, edge will be directed.
      randomly - If true, not only edges are directed, but the direction is chosen randomly.
    • addNodeAttribute

      public void addNodeAttribute​(String name, Function<Random,​?> factory)
      Add this attribute on all nodes generated. The second parameter is a function whose parameter is a Random object and which will return a random attribute value.
      Parameters:
      name - The attribute name.
      factory - A factory that will create the attribute value from the random object
      See Also:
      removeNodeAttribute(String)
    • addNodeAttribute

      public void addNodeAttribute​(String name, double min, double max)
      Same as addNodeAttribute(String, Function) with default factory function. This attribute will have a numerical value chosen in a range that is by default [min-max].
      Parameters:
      name - The attribute name.
      min - The minimum value for this attribute.
      max - The maximum value for this attribute.
      See Also:
      addNodeAttribute(String, Function), removeNodeAttribute(String)
    • addNodeAttribute

      public void addNodeAttribute​(String name)
      Same as addNodeAttribute(String, Function) with default factory function. This attribute will have a numerical value chosen in a range that is by default [0-1].
      Parameters:
      name - The attribute name.
      See Also:
      addNodeAttribute(String, Function), addNodeAttribute(String, double, double), removeNodeAttribute(String)
    • removeNodeAttribute

      public void removeNodeAttribute​(String name)
      Remove an automatic attribute for nodes.
      Parameters:
      name - The attribute name.
      See Also:
      addNodeAttribute(String)
    • addEdgeAttribute

      public void addEdgeAttribute​(String name, Function<Random,​?> factory)
      Add this attribute on all edges generated. The second parameter is a function whose parameter is a Random object and which will return a random attribute value.
      Parameters:
      name - The attribute name.
      factory - A factory that will create the attribute value from the random object
      See Also:
      removeEdgeAttribute(String)
    • addEdgeAttribute

      public void addEdgeAttribute​(String name, double min, double max)
      Same as addEdgeAttribute(String, Function) with default factory function. This attribute will have a numerical value chosen in a range that is by default [min-max].
      Parameters:
      name - The attribute name.
      min - The minimum value for this attribute.
      max - The maximum value for this attribute.
      See Also:
      addEdgeAttribute(String, Function), removeEdgeAttribute(String)
    • addEdgeAttribute

      public void addEdgeAttribute​(String name)
      Same as addEdgeAttribute(String, Function) with default factory function. This attribute will have a numerical value chosen in a range that is by default [0-1].
      Parameters:
      name - The attribute name.
      See Also:
      addEdgeAttribute(String, Function), addEdgeAttribute(String, double, double), removeEdgeAttribute(String)
    • removeEdgeAttribute

      public void removeEdgeAttribute​(String name)
      Remove an automatic attribute for edges.
      Parameters:
      name - The attribute name.
      See Also:
      addEdgeAttribute(String)
    • setUseInternalGraph

      public void setUseInternalGraph​(boolean on)
      Enable or disable the use of an internal graph. If enable, nodes, edges and their attributes are stored in an internal graph. This is useful if the generator needs to remember informations like node id.
      Parameters:
      on - true if the internal graph has to be enable.
    • isUsingInternalGraph

      public boolean isUsingInternalGraph()
      Flag to know if an internal graph is in use.
      Returns:
      true if nodes and edges are stored in an internal graph.