public abstract class BaseGenerator extends 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).
SourceBase.ElementType
Modifier and Type | Field and Description |
---|---|
protected boolean |
addEdgeLabels
Set the edge label attribute using the identifier?.
|
protected boolean |
addNodeLabels
Set the node label attribute using the identifier?.
|
protected boolean |
directed
Are edges directed ?
|
protected double[] |
edgeAttributeRange
If edge attributes are added, in which range are the numbers chosen ?.
|
protected ArrayList<String> |
edgeAttributes
List of attributes to put on edges with a randomly chosen numerical
value.
|
private static int |
generatorId
Used to created unique generatorId.
|
protected Graph |
internalGraph
When
useInternalGraph is on, nodes and edges are stored in this
graph. |
protected double[] |
nodeAttributeRange
If node attributes are added, in which range are the numbers chosen ?.
|
protected ArrayList<String> |
nodeAttributes
List of attributes to put on nodes with a randomly chosen numerical
value.
|
protected Random |
random
The random number generator.
|
protected boolean |
randomlyDirected
If directed, choose the direction randomly?.
|
private boolean |
useInternalGraph
Flag to know if generator has to use an internal graph.
|
attrSinks, eltsSinks, eventProcessing, eventQueue, sourceId, sourceTime
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addEdge(String id,
String from,
String to)
Add an edge, choosing randomly its orientation if needed and putting
attribute on it if needed.
|
void |
addEdgeAttribute(String name)
Add this attribute on all edges generated.
|
void |
addEdgeLabels(boolean on)
Allow to add label attributes on edges.
|
protected void |
addNode(String id)
Add a node and put attributes on it if needed.
|
protected void |
addNode(String id,
double x,
double y)
Same as
addNode(String) but specify attributes to position the
node on a plane. |
void |
addNodeAttribute(String name)
Add this attribute on all nodes generated.
|
void |
addNodeLabels(boolean on)
Allow to add label attributes on nodes.
|
protected void |
clearKeptData()
Clear the internal graph if
useInternalGraph is enable. |
protected void |
delEdge(String edgeId)
Remove an edge.
|
protected void |
delNode(String id)
Remove a node.
|
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 |
setEdgeAttributesRange(double low,
double hi)
If edge attributes are added automatically, choose in which range the
values are choosed.
|
void |
setNodeAttributesRange(double low,
double hi)
If node attributes are added automatically, choose in which range the
values are choosed.
|
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.
|
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
begin, nextEvents
addAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSink
protected boolean directed
protected boolean randomlyDirected
protected ArrayList<String> nodeAttributes
protected ArrayList<String> edgeAttributes
protected double[] nodeAttributeRange
protected double[] edgeAttributeRange
protected boolean addNodeLabels
protected boolean addEdgeLabels
private boolean useInternalGraph
setUseInternalGraph(boolean)
method to set this flag.protected Graph internalGraph
useInternalGraph
is on, nodes and edges are stored in this
graph.private static volatile int generatorId
public BaseGenerator()
public BaseGenerator(boolean directed, boolean randomlyDirectedEdges)
directed
- If true the edges are directed.randomlyDirectedEdges
- If true edge, are directed and the direction is chosen
randomly.public BaseGenerator(boolean directed, boolean randomlyDirectedEdges, String nodeAttribute, String edgeAttribute)
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.public void end()
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.public void setRandomSeed(long seed)
seed
- The seed.public void addNodeLabels(boolean on)
on
- If true labels are added.public void addEdgeLabels(boolean on)
on
- If true labels are added.public void setDirectedEdges(boolean directed, boolean randomly)
directed
- It true, edge will be directed.randomly
- If true, not only edges are directed, but the direction is
chosen randomly.public void addNodeAttribute(String name)
name
- The attribute name.setNodeAttributesRange(double, double)
,
removeNodeAttribute(String)
public void removeNodeAttribute(String name)
name
- The attribute name.addNodeAttribute(String)
public void addEdgeAttribute(String name)
name
- The attribute name.setEdgeAttributesRange(double, double)
,
removeEdgeAttribute(String)
public void removeEdgeAttribute(String name)
name
- The attribute name.addEdgeAttribute(String)
public void setNodeAttributesRange(double low, double hi)
addNodeAttribute(String)
public void setEdgeAttributesRange(double low, double hi)
addEdgeAttribute(String)
public void setUseInternalGraph(boolean on)
on
- true if the internal graph has to be enable.public boolean isUsingInternalGraph()
protected void addNode(String id, double x, double y)
addNode(String)
but specify attributes to position the
node on a plane.id
- The node identifier.x
- The node abscissa.y
- The node ordinate.protected void addNode(String id)
id
- The new node identifier.protected void addEdge(String id, String from, String to)
id
- The edge identifier, if null, the identifier is created from
the nodes identifiers.from
- The source node (can be inverted randomly with the target
node).protected void delEdge(String edgeId)
edgeId
- id of the edge to removeprotected void clearKeptData()
useInternalGraph
is enable.
This method is called in end()
to ensure the next generation
will start freshly anew.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses