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

📄 ring.tcl

📁 基于 NS2 的 AntNet 源代码
💻 TCL
字号:
# tcl script for AntNet algorithm on ring topology of 3 nodes#number of nodesset sz 3#Create event Schedularset ns [ new Simulator ]#Open the Trace fileset tf [open antnet_trace.out w]$ns trace-all $tf#Create 3 nodesfor {set i 0} {$i < $sz} {incr i} {	set n($i) [$ns node]}#Create links between the nodesfor {set i 0} {$i < $sz} {incr i} {	for {set j 0} {$j < $sz} {incr j} {		if {$i != $j} {			$ns duplex-link $n($i) $n($j) 512Mb 155ms DropTail		}	}}#Create Antnet agentsfor {set i 0} {$i < $sz} {incr i} {	set   nn($i)  [ new Agent/Antnet $i]}#Attach each node with Antnet agentfor {set i 0} {$i < $sz} {incr i} {	$ns attach-agent  $n($i)  $nn($i)}#Create connection between the nodesfor {set i 0} {$i < $sz} {incr i} {	for {set j 0} {$j < $sz} {incr j} {		if {$i != $j} {			$ns connect $nn($i) $nn($j)			$ns connect $nn($j) $nn($i)		}	}}#Add neighborsfor {set j 1} {$j < $sz} {incr j} {	$ns at now "$nn(0) add-neighbor $n(0) $n($j)"}$ns at now "$nn(0) add-neighbor $n(1) $n(2)"#Set parameters and start time for AntNet algorithmfor {set i 0} {$i < $sz} {incr i} {	$nn($i) set num_nodes_ $sz	$nn($i) set timer_ant_ 0.001	$nn($i) set r_factor_ 0.05	$ns  at  1.0  "$nn($i) start"}#Set stop time for AntNet algorithmfor {set i 0} {$i < $sz} {incr i} {	$ns  at 3.0 "$nn($i) stop"}#Print routing tables generated by AntNetfor {set i 0} {$i < $sz} {incr i} {	$ns at 4.5 "$nn($i) print_rtable"}# Final Wrap upproc Finish {} {	global ns tf	$ns   flush-trace	#Close the Trace file        close $tf}$ns  at 5.0 "Finish"# Start the simulator$ns  run

⌨️ 快捷键说明

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