edu.uci.ics.jung.algorithms.generators
Class Lattice2DGenerator<V,E>

java.lang.Object
  extended by edu.uci.ics.jung.algorithms.generators.Lattice2DGenerator<V,E>
All Implemented Interfaces:
GraphGenerator<V,E>, org.apache.commons.collections15.Factory<Graph<V,E>>
Direct Known Subclasses:
KleinbergSmallWorldGenerator

public class Lattice2DGenerator<V,E>
extends Object
implements GraphGenerator<V,E>

Simple generator of an m x n lattice where each vertex is incident with each of its neighbors (to the left, right, up, and down). May be toroidal, in which case the vertices on the edges are connected to their counterparts on the opposite edges as well.

If the graph factory supplied has a default edge type of EdgeType.DIRECTED, then edges will be created in both directions between adjacent vertices.

Author:
Joshua O'Madadhain

Field Summary
protected  int col_count
           
protected  org.apache.commons.collections15.Factory<E> edge_factory
           
protected  org.apache.commons.collections15.Factory<Graph<V,E>> graph_factory
           
protected  boolean is_toroidal
           
protected  int row_count
           
protected  org.apache.commons.collections15.Factory<V> vertex_factory
           
 
Constructor Summary
Lattice2DGenerator(org.apache.commons.collections15.Factory<Graph<V,E>> graph_factory, org.apache.commons.collections15.Factory<V> vertex_factory, org.apache.commons.collections15.Factory<E> edge_factory, int latticeSize, boolean isToroidal)
          Constructs a generator of square lattices of size latticeSize with the specified parameters.
Lattice2DGenerator(org.apache.commons.collections15.Factory<Graph<V,E>> graph_factory, org.apache.commons.collections15.Factory<V> vertex_factory, org.apache.commons.collections15.Factory<E> edge_factory, int row_count, int col_count, boolean isToroidal)
          Creates a generator of row_count x col_count lattices with the specified parameters.
 
Method Summary
 Graph<V,E> create()
           
protected  int getCol(int i)
          Returns the column in which vertex i is found.
protected  int getIndex(int i, int j)
           
protected  int getRow(int i)
          Returns the row in which vertex i is found.
protected  V getVertex(int i)
          Returns the ith vertex (counting row-wise).
protected  V getVertex(int i, int j)
          Returns the vertex at position (i mod row_count, j mod col_count).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

row_count

protected int row_count

col_count

protected int col_count

is_toroidal

protected boolean is_toroidal

graph_factory

protected org.apache.commons.collections15.Factory<Graph<V,E>> graph_factory

vertex_factory

protected org.apache.commons.collections15.Factory<V> vertex_factory

edge_factory

protected org.apache.commons.collections15.Factory<E> edge_factory
Constructor Detail

Lattice2DGenerator

public Lattice2DGenerator(org.apache.commons.collections15.Factory<Graph<V,E>> graph_factory,
                          org.apache.commons.collections15.Factory<V> vertex_factory,
                          org.apache.commons.collections15.Factory<E> edge_factory,
                          int latticeSize,
                          boolean isToroidal)
Constructs a generator of square lattices of size latticeSize with the specified parameters.

Parameters:
graph_factory - used to create the Graph for the lattice
vertex_factory - used to create the lattice vertices
edge_factory - used to create the lattice edges
latticeSize - the number of rows and columns of the lattice
isToroidal - if true, the created lattice wraps from top to bottom and left to right

Lattice2DGenerator

public Lattice2DGenerator(org.apache.commons.collections15.Factory<Graph<V,E>> graph_factory,
                          org.apache.commons.collections15.Factory<V> vertex_factory,
                          org.apache.commons.collections15.Factory<E> edge_factory,
                          int row_count,
                          int col_count,
                          boolean isToroidal)
Creates a generator of row_count x col_count lattices with the specified parameters.

Parameters:
graph_factory - used to create the Graph for the lattice
vertex_factory - used to create the lattice vertices
edge_factory - used to create the lattice edges
row_count - the number of rows in the lattice
col_count - the number of columns in the lattice
isToroidal - if true, the created lattice wraps from top to bottom and left to right
Method Detail

create

public Graph<V,E> create()
Specified by:
create in interface org.apache.commons.collections15.Factory<Graph<V,E>>
See Also:
Factory.create()

getIndex

protected int getIndex(int i,
                       int j)

getVertex

protected V getVertex(int i,
                      int j)
Returns the vertex at position (i mod row_count, j mod col_count).


getVertex

protected V getVertex(int i)
Returns the ith vertex (counting row-wise).


getRow

protected int getRow(int i)
Returns the row in which vertex i is found.


getCol

protected int getCol(int i)
Returns the column in which vertex i is found.



Copyright © 2009. All Rights Reserved.