⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 noc.tcl

📁 基于 NS2 的 AntNet 源代码
💻 TCL
字号:
# tcl script for AntNet algorithm on a regular 3 x 4 mesh topology# number of nodes in a rowset sz_x 4# number of nodes in a columnset sz_y 3#Create event Schedularset ns [ new Simulator ]#Open the Trace fileset tf [open antnet_trace.out w]$ns trace-all $tf#Create the nxn nodesfor {set i 0} {$i < [expr $sz_x * $sz_y]} {incr i} {	set n($i) [$ns node]}#Create links between the nodes (Horizontal)for {set i 0} {$i < $sz_y} {incr i} {	for {set j 0} {$j < [expr $sz_x-1]} {incr j} {		set k [expr $sz_x * $i]		$ns duplex-link $n([expr $j+$k]) $n([expr [expr $j+1] + $k]) 512Mb 5ms DropTail	}}#Create links between the nodes (Vertical)for {set i 0} {$i < [expr $sz_y-1]} {incr i} {	for {set j 0} {$j < $sz_x} {incr j} {		set k [expr $sz_x*$i]		$ns duplex-link $n([expr $j+$k]) $n([expr $k + [expr $j+$sz_x]]) 512Mb 5ms DropTail	}}#Create Antnet agentsfor {set i 0} {$i < [expr $sz_x * $sz_y]} {incr i} {	set   nn($i)  [ new Agent/Antnet $i]}#Attach each node with Antnet agentfor {set i 0} {$i < [expr $sz_x*$sz_y]} {incr i} {	$ns attach-agent  $n($i)  $nn($i)}#Create connection between the nodes (Horizontal)for {set i 0} {$i < $sz_y} {incr i} {	for {set j 0} {$j < [expr $sz_x-1]} {incr j} {		set k [expr $sz_x*$i]		$ns connect $nn([expr $j+$k]) $nn([expr $k+[expr $j+1]])		$ns connect $nn([expr $k + [expr $j+1]]) $nn([expr $j + $k])	}}#Create connection between the nodes (Vertical)for {set i 0} {$i < [expr $sz_y-1]} {incr i} {	for {set j 0} {$j < $sz_x} {incr j} {		set k [expr $sz_x * $i]		$ns connect $nn([expr $j+$k]) $nn([expr $k + [expr $j + $sz_x]])		$ns connect $nn([expr $k + [expr $j + $sz_x]]) $nn([expr $j + $k])	}}#Add neighbors (Horizontal)for {set i 0} {$i < $sz_y} {incr i} {	for {set j 0} {$j < [expr $sz_x-1]} {incr j} {		set k [expr $sz_x*$i]		$ns at now "$nn(0) add-neighbor $n([expr $j+$k]) $n([expr $k+[expr $j+1]])"	}}#Add neighbors (Vertical)for {set i 0} {$i < [expr $sz_y-1]} {incr i} {	for {set j 0} {$j < $sz_x} {incr j} {		set k [expr $sz_x*$i]		$ns at now "$nn(0) add-neighbor $n([expr $j+$k]) $n([expr $k + [expr $j + $sz_x]])"	}}#Set parameters and start time for AntNet algorithmfor {set i 0} {$i < [expr $sz_x * $sz_y]} {incr i} {	$nn($i) set num_nodes_x_ $sz_x	$nn($i) set num_nodes_y_ $sz_y	$nn($i) set num_nodes_ [expr $sz_x * $sz_y]	$nn($i) set timer_ant_ 0.03	$nn($i) set r_factor_ 0.001	$ns  at  1.1  "$nn($i) start"}#Set stop time for AntNet algorithmfor {set i 0} {$i < [expr $sz_x * $sz_y]} {incr i} {	$ns  at 2.1 "$nn($i) stop"}#Print routing tables generated by AntNetfor {set i 0} {$i < [expr $sz_x * $sz_y]} {incr i} {	$ns at 4.2 "$nn($i) print_rtable"}# Final Wrap upproc Finish {} {	global ns tf	$ns   flush-trace	#Close the Trace file        close $tf}$ns  at 8.4  "Finish"# Start the simulator$ns  run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -