LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How do i select a cluster header with NS2? (https://www.linuxquestions.org/questions/linux-software-2/how-do-i-select-a-cluster-header-with-ns2-4175544975/)

ali_it 06-10-2015 03:34 AM

How do i select a cluster header with NS2?
 
Hi Friends
i have a sensor field in dimension of 200 * 200 and nodes deployed randomly.
i want select nearest node to midpoint of sensor field as a Cluster Header.
How do I do this?
thanks

ali_it 06-10-2015 03:00 PM

# calculate distance between node (i) and center
for {set i 0} {$i<$val(nn)} {incr i} {
set x_posi [$n($i) set X_]
set y_posi [$n($i) set Y_]
#puts "$x_posi , $y_posi"
set x_pos [expr $x_posi - 100]
set y_pos [expr $y_posi - 100]
set v [expr ($x_pos * $x_pos) + ($y_pos * $y_pos)]
set d [expr pow($v , 0.5)]
set nd($i) $d
puts "$nd($i) \n"
#puts "distance of n($i) from center $d"
#puts "\n"
}



#calculate minimum distance to center
set mind $nd(0)
set j 0
for {set i 0} {$i < $val(nn)} {incr i} {
if {$nd($i) < $mind } {
set mind $nd($i)
set j $i ;#j is index node that nearest to center
}
}
puts "nearest node to center is $j with distance $mind"


All times are GMT -5. The time now is 12:50 AM.