[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] Running multiple simulations with a single tcl script



Brian Lee Bowers wrote:
>On Tuesday 14 August 2001 14:28, Giuseppe Tringali wrote:
>> Hi ns user,
>>
>> I'd like to run several simulations changing only a parameter (for
>> example the length of the simulation or the delay of link).
>>
>> My question is this: is it possible with a single tcl script? An if
>> so, could you give me a basic example of the script?
>>
>> I have seen in previous messages that expert user of NS use both
>> perl script and shell script. But this solution is quite difficult
>> for me.
>
>Anyone else have other suggestions?

Having just done this I can suggest the following method; add
reset functions to classes ns, scheduler and queue, which 
empty all events from the scheduler, empty all events from the
queue; and reset time to zero.  Then run multiple runs from
within a Tcl loop e.g.

proc evalresults {} {
global ns maxlocalls maxhicalls
$ns reset

..... do some stuff ....

}

for {set maxlocalls 0} {$maxlocalls<=150} {incr maxlocalls} {
  for {set maxhicalls 0} {$maxhicalls <=75} {incr maxhicalls} {
     evalresults
     }
}


NB this doesn't work without you adding the appriate reset functions
to the NS codes (changes needed to tcl/lib/ns-lib.tcl,scheduler.cc,
queue.cc (currently using connector::reset from the superclass). 
I can send you suitable patches if you email me.

In my case this works fine, although some memory is leaked, but as NS
always seems to leak memory this seems just to be life.

DO NOT try and delete the ns instance and start again as this leaks
memory like a sieve (although this should be blamed on Tcl and not ns).
It's a great pity the ns scripting language isn't a sensible garbage
collected language like LISP; a great deal of time and code is spent in
my simulations cleaning up garbage.

Alan Bain