问题
I noticed that the function t.runNextEvent() has a big impact in the time of the simulation. To be sure all events are simulated I call it a lot of times. In some cases(especially when I use flooding to disseminate information) it is not enough.
Hence if this number is too large I have to wait more to obtain the results. If instead the number of calls is too small the simulation becomes useless.
There is any way to know the right number of calls? Here we have to consider the highly randomness and the fact that flooding may be used.
回答1:
By default TOSSIM simulates low-level TinyOS components that potentially generate a lot of events. The only way to know the exact number of times you need to call t.runNextEvent()
is to know what exactly is going on in those layers. But this is a) probably impossible and b) unnecessary.
I have been using following approach:
- Estimate how long (in seconds/minutes/hours) I want my simulation to run. This can depend on the project requirements or nature of code you are simulating.
- Find out how many ticks are there per simulated second using
t.ticksPerSecond()
. Note that I said simulated second (Usefull paper on TOSSIM, see top of page 3). - Call
t.runNextEvent()
inside a loop that iteratest.ticksPerSecond() * simulation_length
times. Although there is no direct link between the amount of time your code would run on real motes and the time it will take to simulate it using TOSSIM, I have found that using real time intervals is quite good for sizing the number of iterations required for a particular simulation.
Example:
simLength = 60*5 #run code for simulated 5 minutes
while True:
t.runNextEvent()
if t.time() > simLength * t.ticksPerSecond():
break
来源:https://stackoverflow.com/questions/17817255/how-do-i-decide-the-right-number-of-events-in-tinyos-and-tossim