core
Class ConnectivityGrid

java.lang.Object
  extended by core.ConnectivityGrid

public class ConnectivityGrid
extends java.lang.Object

Overlay grid of the world where each node is put on a cell depending of its location. This is used in cell-based optimization of connecting the nodes.

The idea in short:
Instead of checking for every node if some of the other nodes are close enough (this approach obviously doesn't scale) we check only nodes that are "close enough" to be possibly connected. Being close enough is determined by keeping track of the approximate location of the nodes by storing them in overlay grid's cells and updating the cell information every time the nodes move. If two nodes are in the same cell or in neighboring cells, they have a chance of being close enough for connection. Then only that subset of nodes is checked for possible connectivity.

Note: this class does NOT support negative coordinates. Also, it makes sense to normalize the coordinates to start from zero to conserve memory.


Nested Class Summary
 class ConnectivityGrid.GridCell
          A single cell in the cell grid.
 
Constructor Summary
ConnectivityGrid(int worldSizeX, int worldSizeY, int cellSize)
          Creates a new overlay connectivity grid
 
Method Summary
 void addNodes(java.util.Collection<DTNHost> nodes)
          Adds nodes to overlay grid
 void connectAllNearNodes()
          Connects all nodes, that are in adjacent cells, to each other.
 void connectToNearNodes(DTNHost node)
          Connects a node to all nodes that are in the same cell or in adjacent cells.
 java.lang.String toString()
          Returns a string representation of the ConnectivityCells object
 void updateLocation(DTNHost node)
          Checks and updates (if necessary) node's position in the grid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectivityGrid

public ConnectivityGrid(int worldSizeX,
                        int worldSizeY,
                        int cellSize)
Creates a new overlay connectivity grid

Parameters:
worldSizeX - Width of the world (biggest possible x coordinate)
worldSizeY - Height of the world (biggest possible y coordinate)
cellSize - Cell's edge's length (must be larger than the largest radio coverage's diameter)
Method Detail

addNodes

public void addNodes(java.util.Collection<DTNHost> nodes)
Adds nodes to overlay grid

Parameters:
nodes - Collection of nodes to add

updateLocation

public void updateLocation(DTNHost node)
Checks and updates (if necessary) node's position in the grid

Parameters:
node - The node to update

connectToNearNodes

public void connectToNearNodes(DTNHost node)
Connects a node to all nodes that are in the same cell or in adjacent cells. Good algorithm for small (less than 2k) amounts of nodes or highly clustered nodes. For larger amounts of nodes connectAllNearNodes() could be a better choice.

Parameters:
node - Node to connect
See Also:
connectAllNearNodes()

connectAllNearNodes

public void connectAllNearNodes()
Connects all nodes, that are in adjacent cells, to each other. Good algorithm for large amount of nodes (more than 2k) that are relatively evenly distributed, lousy for small amounts or highly clustered nodes. For smaller amounts, use connectToNearNodes()

See Also:
connectToNearNodes(DTNHost)

toString

public java.lang.String toString()
Returns a string representation of the ConnectivityCells object

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the ConnectivityCells object