Class Lattice2DGenerator<V,E>
java.lang.Object
edu.uci.ics.jung.algorithms.generators.Lattice2DGenerator<V,E>
- All Implemented Interfaces:
com.google.common.base.Supplier<Graph<V,E>>, GraphGenerator<V, E>, Supplier<Graph<V, E>>
- Direct Known Subclasses:
KleinbergSmallWorldGenerator
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 Supplier supplied has a default edge type of EdgeType.DIRECTED,
then edges will be created in both directions between adjacent vertices.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLattice2DGenerator(com.google.common.base.Supplier<? extends Graph<V, E>> graph_factory, com.google.common.base.Supplier<V> vertex_factory, com.google.common.base.Supplier<E> edge_factory, int latticeSize, boolean isToroidal) Constructs a generator of square lattices of sizelatticeSizewith the specified parameters.Lattice2DGenerator(com.google.common.base.Supplier<? extends Graph<V, E>> graph_factory, com.google.common.base.Supplier<V> vertex_factory, com.google.common.base.Supplier<E> edge_factory, int row_count, int col_count, boolean isToroidal) Creates a generator ofrow_countxcol_countlattices with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionget()Generates a graph based on the constructor-specified settings.protected intgetCol(int i) intReturns the number of edges found in a lattice of this generator's specifications.protected intgetIndex(int i, int j) protected intgetRow(int i) protected VgetVertex(int i) protected VgetVertex(int i, int j) protected intmod(int i, int modulus)
-
Field Details
-
row_count
protected int row_count -
col_count
protected int col_count -
is_toroidal
protected boolean is_toroidal -
is_directed
protected boolean is_directed -
graph_factory
-
vertex_factory
-
edge_factory
-
v_array
-
-
Constructor Details
-
Lattice2DGenerator
public Lattice2DGenerator(com.google.common.base.Supplier<? extends Graph<V, E>> graph_factory, com.google.common.base.Supplier<V> vertex_factory, com.google.common.base.Supplier<E> edge_factory, int latticeSize, boolean isToroidal) Constructs a generator of square lattices of sizelatticeSizewith the specified parameters.- Parameters:
graph_factory- used to create theGraphfor the latticevertex_factory- used to create the lattice verticesedge_factory- used to create the lattice edgeslatticeSize- the number of rows and columns of the latticeisToroidal- if true, the created lattice wraps from top to bottom and left to right
-
Lattice2DGenerator
public Lattice2DGenerator(com.google.common.base.Supplier<? extends Graph<V, E>> graph_factory, com.google.common.base.Supplier<V> vertex_factory, com.google.common.base.Supplier<E> edge_factory, int row_count, int col_count, boolean isToroidal) Creates a generator ofrow_countxcol_countlattices with the specified parameters.- Parameters:
graph_factory- used to create theGraphfor the latticevertex_factory- used to create the lattice verticesedge_factory- used to create the lattice edgesrow_count- the number of rows in the latticecol_count- the number of columns in the latticeisToroidal- if true, the created lattice wraps from top to bottom and left to right
-
-
Method Details
-
get
-
getGridEdgeCount
public int getGridEdgeCount()Returns the number of edges found in a lattice of this generator's specifications. (This is useful for subclasses that may modify the generated graphs to add more edges.)- Returns:
- the number of edges that this generator will generate
-
getIndex
protected int getIndex(int i, int j) -
mod
protected int mod(int i, int modulus) -
getVertex
- Parameters:
i- row index into the latticej- column index into the lattice- Returns:
- the vertex at position (
i mod row_count, j mod col_count)
-
getVertex
- Parameters:
i- row index into the lattice- Returns:
- the
ith vertex (counting row-wise)
-
getRow
protected int getRow(int i) - Parameters:
i- index of the vertex whose row we want- Returns:
- the row in which the vertex with index
iis found
-
getCol
protected int getCol(int i) - Parameters:
i- index of the vertex whose column we want- Returns:
- the column in which the vertex with index
iis found
-