ns2, create circular path in tcl script -


due limitation capability of ns2 simulate open system, wold create circular path; fixed number of nodes can enter or leave area of road -we call region of interest- @ time. highway consists of number of lanes, nodes distributed evenly @ lanes. first step variables declaration:

 # variables initialization  # val(nn)  26   number of mobilenodes   # val(x)   500  x dimension of topography  # val(y)   500  y dimension of topography  # val(x), val(y), val(nn) defined above in script namespace import ::tcl::mathfunc::* ;# using sin, cos functions set namsize 30 ; # node size in nam file set cx [expr $val(x) / 2]     ;# cx, cy center of circle set cy [expr $val(y) / 2] set r [expr $cx -10]          ;# radius of circle set pi 3.14159265358979323846 set ncars $val(nn)            ;# total number of cars set lane 2                    ;# number lanes on highway set carsperlane [expr $ncars / $lane];# number of cars per lane set carsinfor [expr $ncars / $lane];# equal carsinlane. used in loop set 0                       ;# iterator used in loop 

then distribute nodes evenly @ lanes transferring code form here tcl code

# set node initial position, in loop distribute node evenly @ lanes {set counter 0} {$counter < $lane} {incr counter} {     while { $i < $carsinfor  } {             set node_($i) [$ns node]             set angle [ expr ((360.0 / $carsperlane) * $i) * ($pi / 180) ]             set pointx [ expr $cx + ($r * cos ($angle))]             set pointy [ expr $cy + ($r * sin ($angle))]             $node_($i) set x_ $pointx             $node_($i) set y_ $pointy             $node_($i) set z_ 0.0             #set tcl_precision 3             puts "lane $counter n $i x = $pointx, y = $pointy, angle = $angle" ; # logging             incr             }         set r [expr $r - $namsize]      set carsinfor [expr $carsinfor + $carsperlane] } 

and finally, set nodes movement using next segment of code:

set node movement

set theta 0;                                  ;# final angle set deltatheta 0.1;                           ;# increment value set numintegrals [expr $pi * 2 / $deltatheta] ;# total number of integrals set 0; set carsinfor $carsperlane                       ;# zeroing iterators set r [expr $cx -10] ;# reset radius  {set counter 0} {$counter < $lane} {incr counter} {     while { $i < $carsinfor  } {         set angle [ expr ((360.0 / $carsperlane) * $i) * ($pi / 180) ]         set theta $angle                      ;# assign initial angle theta         {set t 0} {$t < $numintegrals} {incr t} {             set theta [expr ($theta + $deltatheta)]             set pointx [ expr $cx + ($r * cos ($theta))]             set pointy [ expr $cy + ($r * sin ($theta))]             #set tcl_precision 3                  ; # set tcl_precision printing             #puts "l $counter n $i p $t x = $pointx, y = $pointy, angle = $theta"             $ns @ 0.0 "$node_($i) setdest $pointx $pointy 30.0" ;# correctly?         }          incr     }         set r [expr $r - $namsize]      set carsinfor [expr $carsinfor + $carsperlane] } 

when rum nam file node movements, nodes move limited time , still stationary after that. calling $ns @ 0.0 "$node_($i) setdest $pointx $pointy 30.0" ; not correctly @ loop?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -