In large network cluster formation is done in grid format with availability location information of the nodes. In distributed case, each node executes the algorithm given below by applying its own position to find the grid it belongs to. In centralized case, sink node applies the algorithm and informs the grid id to each node. The grid formation is based on communication range, network width and network height.
for {set i 1} {$i < $val(nn) } { incr i } {
set grid 1
for {set gx 1} {$gx <= $g } { incr gx } {
if { $xx($i) <= [expr $gwidth * $gx] } {
set xp [expr $gwidth * $gx]
set gx [expr round($g) + 1]
for {set gy 1} {$gy <= $g } { incr gy } {
set yp [expr $gheight * $gy]
if { $yy($i) <= [expr $gheight * $gy] } {
set gridid($i) $grid
break;
} else {
set grid [expr $grid + 1]
}
}
} else {
set grid [expr [expr $gx * $g] + 1]
}
}
}
Here, total grids are 9.