Class 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
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
-
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 asaddEdgeAttribute(String, Function)
with default factory function.void
addEdgeAttribute(String name, double min, double max)
Same asaddEdgeAttribute(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 asaddNodeAttribute(String, Function)
with default factory function.void
addNodeAttribute(String name, double min, double max)
Same asaddNodeAttribute(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
-
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 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. -
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
Add this attribute on all nodes generated. The second parameter is a function whose parameter is aRandom
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
Same asaddNodeAttribute(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
Same asaddNodeAttribute(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
Remove an automatic attribute for nodes.- Parameters:
name
- The attribute name.- See Also:
addNodeAttribute(String)
-
addEdgeAttribute
Add this attribute on all edges generated. The second parameter is a function whose parameter is aRandom
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
Same asaddEdgeAttribute(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
Same asaddEdgeAttribute(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
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.
-