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).
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.
nextEvents()
((n+1)*2) new nodes are generated
with n the size of a side of the grid.
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);
Constructor and 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.
|
Modifier and Type | Method and 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.
|
addEdgeAttribute, addEdgeLabels, addNodeAttribute, addNodeLabels, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, setEdgeAttributesRange, setNodeAttributesRange, setRandomSeed, setUseInternalGraph
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
public GridGenerator()
public GridGenerator(boolean cross, boolean tore)
cross
- Create diagonal links?.tore
- Close the grid as a tore?.public GridGenerator(boolean cross, boolean tore, boolean generateXY)
cross
- Create diagonal links?tore
- Close the grid as a tore?generateXY
- Generate coordinates of nodes.public GridGenerator(boolean cross, boolean tore, boolean generateXY, boolean directed)
cross
- Create diagonal links ?tore
- Close the grid as a tore ?generateXY
- Generate coordinates of nodes.directed
- Are edges directed ?public void begin()
Generator.begin()
public boolean nextEvents()
Generator.nextEvents()
public void end()
end
in interface Generator
end
in class BaseGenerator
Generator.end()
Copyright © 2015. All rights reserved.