Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tcl 如何在ns2中查找邻居列表_Tcl_Ns2 - Fatal编程技术网

Tcl 如何在ns2中查找邻居列表

Tcl 如何在ns2中查找邻居列表,tcl,ns2,Tcl,Ns2,我想找到传感器网络中的邻居节点列表。如果有人能为我提供一个tcl脚本示例,那将是非常有帮助的。谢谢#邻居节点计算 # neighbor node calculation set nbr [open Neighbor w] puts $nbr "\t\t\t\t\tNeighbor Detail" puts $nbr "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" puts $nbr "\tNode\t\tNb node\t\tNode-Xpos\tNode-Ypos

我想找到传感器网络中的邻居节点列表。如果有人能为我提供一个tcl脚本示例,那将是非常有帮助的。谢谢

#邻居节点计算
# neighbor node calculation

set nbr [open Neighbor w]

puts $nbr "\t\t\t\t\tNeighbor Detail"

puts $nbr "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

puts $nbr "\tNode\t\tNb node\t\tNode-Xpos\tNode-Ypos\tNb-Xpos\t\tNb-Ypos\t\tDistance(d)"

puts $nbr "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

close $nbr

proc distance { n1 n2 nd1 nd2} {

  global c n bnd src dst j0 j1 

  set a 0

  set nbr [open Neighbor a]

  set x1 [expr int([$n1 set X_])]

  set y1 [expr int([$n1 set Y_])]

 set x2 [expr int([$n2 set X_])]

  set y2 [expr int([$n2 set Y_])]

  set d [expr int(sqrt(pow(($x2-$x1),2)+pow(($y2-$y1),2)))]

  if {$d<300} {

    if {$nd2!=$nd1} {

      puts $nbr "\t$nd1\t\t$nd2\t\t$x1\t\t$y1\t\t$x2\t\t$y2\t\t$d"

    }
    }



  close $nbr
}



U can use above function to print neighbor node's of all nodes in ns2.
设置nbr[开放邻居w] 放入$nbr“\t\t\t\t\t详细信息” 将$nbr“\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~” 放置$nbr“\tNode\t\tNb node\t\tNode Xpos\tNode Ypos\tNb Xpos\t\tNb Ypos\t\t立场(d)” 将$nbr“\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~” 收盘价$nbr 过程距离{n1 n2 nd1 nd2}{ 全局c n bnd src dst j0 j1 设置一个0 设置nbr[开放邻居a] 集合x1[expr int([$n1集合X_uz])] 集合y1[expr int([$n1集合Y])] 集合x2[expr int([$n2集合X_U4;]])] 集合y2[expr int([$n2集合Y])] 集合d[expr int(sqrt(pow($x2-$x1),2)+pow($y2-$y1),2))]
如果{$d到目前为止您尝试过做什么?(Stack Overflow鼓励人们在寻求帮助之前自己尝试。)
for {set i 0} {$i <$val(nn)} {incr i} {
      for {set j 0} {$j <$val(nn)} {incr j} {

        $ns at 10.002 "distance $n($i) $n($j) $i $j" 
      }
    }

here val(nn) denotes number of nodes.