org.graphstream.algorithm.generator
Class GridGenerator

java.lang.Object
  extended by org.graphstream.stream.SourceBase
      extended by org.graphstream.algorithm.generator.BaseGenerator
          extended by org.graphstream.algorithm.generator.GridGenerator
All Implemented Interfaces:
Generator, org.graphstream.stream.Source

public class GridGenerator
extends BaseGenerator

Generator for square grids of any size.

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 to nextEvents() ((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
 
Nested classes/interfaces inherited from class org.graphstream.stream.SourceBase
org.graphstream.stream.SourceBase.ElementType
 
Constructor Summary
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
 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, addEdgeLabels, addNodeAttribute, addNodeLabels, isUsingInternalGraph, removeEdgeAttribute, removeNodeAttribute, setDirectedEdges, setEdgeAttributesRange, setNodeAttributesRange, 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
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.graphstream.stream.Source
addAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSink
 

Constructor Detail

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 Detail

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 interface Generator
Overrides:
end in class BaseGenerator
See Also:
Generator.end()


Copyright © 2013. All Rights Reserved.