Class GridGenerator
- All Implemented Interfaces:
Generator
,org.graphstream.stream.Source
public class GridGenerator extends BaseGenerator
This generate square grid graphs of any size with each node not on the border of the graph having four neighbours for regular grids or height neighbours for cross grids. The nodes at each of the four corners of the grid consequently have only two or three (cross) neighbours. The nodes on the side of the grid have three or five (cross) neighbours.
The generated grid can be closed as a torus, meaning that there is no border nodes will exist, therefore all nodes will have the same degree four or height (cross).
Usage
At the contrary of most generators, this generator does not produce
only one node when you call nextEvents()
. It adds a row
and column to the grid, making the side of the square grow by one.
Therfore if you call the nextEvents()
methode n times you
will have n^2 nodes.
You can indicate at construction time if the graph will be a regular grid (no argument) or if it must be a cross-grid (first boolean argument to true) and a tore (second boolean argument to true).
A constructor with a third boolean parameter allows to indicate that nodes must have a ``xyz`` attribute to position them or not. This is the default behaviour.
Complexity
At each call tonextEvents()
((n+1)*2) new nodes are generated
with n the size of a side of the grid.
Example
Graph graph = new SingleGraph("grid"); Generator gen = new GridGenerator(); gen.addSink(graph); gen.begin(); for(int i=0; i<10; i++) { gen.nextEvents(); } gen.end(); // Nodes already have a position. graph.display(false);
- Since:
- 2007
-
Nested Class Summary
-
Constructor Summary
Constructors Constructor Description GridGenerator()
New grid generator.GridGenerator(boolean cross, boolean tore)
New grid generator.GridGenerator(boolean cross, boolean tore, boolean generateXY)
New grid generator.GridGenerator(boolean cross, boolean tore, boolean generateXY, boolean directed)
New grid generator. -
Method Summary
Modifier and Type Method Description void
begin()
Add an initial node.void
end()
If grid is a tore, a call to this method will close the tore.boolean
nextEvents()
Grow the graph.Methods inherited from class org.graphstream.algorithm.generator.BaseGenerator
addEdgeAttribute, addEdgeAttribute, addEdgeAttribute, addEdgeLabels, addNodeAttribute, addNodeAttribute, addNodeAttribute, addNodeLabels, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, 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, 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
-
GridGenerator
public GridGenerator()New grid generator. By default no diagonal links are made and the grid is not a tore. -
GridGenerator
public GridGenerator(boolean cross, boolean tore)New grid generator.- Parameters:
cross
- Create diagonal links?.tore
- Close the grid as a tore?.
-
GridGenerator
public GridGenerator(boolean cross, boolean tore, boolean generateXY)New grid generator.- Parameters:
cross
- Create diagonal links?tore
- Close the grid as a tore?generateXY
- Generate coordinates of nodes.
-
GridGenerator
public GridGenerator(boolean cross, boolean tore, boolean generateXY, boolean directed)New grid generator.- Parameters:
cross
- Create diagonal links ?tore
- Close the grid as a tore ?generateXY
- Generate coordinates of nodes.directed
- Are edges directed ?
-
-
Method Details
-
begin
public void begin()Add an initial node.- See Also:
Generator.begin()
-
nextEvents
public boolean nextEvents()Grow the graph. If grid dimensions are width x height, then after a call to this method dimensions will be (width+1)x(height+1).- Returns:
- true while there are elements to add to the graph.
- See Also:
Generator.nextEvents()
-
end
public void end()If grid is a tore, a call to this method will close the tore.- Specified by:
end
in interfaceGenerator
- Overrides:
end
in classBaseGenerator
- See Also:
Generator.end()
-