[Ns-developers] Random Variables API changes

Michele Weigle mweigle at csnet.cs.odu.edu
Tue Jan 20 10:58:23 PST 2009

On Jan 20, 2009, at 1:09 PM, Gustavo Carneiro wrote:
> 2009/1/20 Tom Henderson <tomh at tomh.org>
>>> -----Original Message-----
>>> From: Gustavo Carneiro [mailto:gjcarneiro at gmail.com]
>>> Sent: Tuesday, January 20, 2009 09:19 AM
>>> To: 'Raj Bhattacharjea'
>>> Cc: 'Tom Henderson', 'NS3 Developers Mailing List'
>>> Subject: Re: [Ns-developers] Random Variables API changes
>>> 2009/1/20 Raj Bhattacharjea <raj.b at gatech.edu>
>>>> On Tue, Jan 20, 2009 at 11:40 AM, Raj Bhattacharjea <raj.b at gatech.edu 
>>>> >
>>>> wrote:
>>>>> quick ideas that need to be looked at.  The biggest of these is a
>>>>> change like the following:
>>>>> - UniformVariable::GetSingleValue (0, N)
>>>>> + UniformVariable().GetValue (0, N)
>>>>> I had to do this in one place to make things compile, but seems  
>>>>> a bit
>>>> I forgot I had to do this in several places, or things similar to
>>>> this.  The affected files are:
>>>> src/devices/csma/backoff.cc
>>>> src/mobility/random-direction-2d-mobility-model.cc
>>>> src/routing/olsr/olsr-agent-impl.cc
>>>> I'm sure the maintainers of these would have their preferred
>>>> implementation.
>>> I wonder what is the rationale for the removal of GetSingleValue?   
>>> It
>> seems
>>> to me that keeping a single static UniformVariable global variable  
>>> is just
>> a
>>> pointless API change, as it is surely equivalent to previous code,  
>>> while
>>> keeping one UniformVariable per OLSR instance sounds like a memory  
>>> waste
>> if
>>> no reason for the change is known.
>>> I think there is probably a good reason for the API change and,  
>>> not that I
>>> don't trust you, but I would like to know what that reason is.   
>>> Was the
>>> previous GetSingleValue usage pattern incorrect?
>> Here is the background on this proposed change:
>> http://mailman.isi.edu/pipermail/ns-developers/2008-September/004732.html
>> My understanding is that the recommended way would be for users to  
>> create
>> their own random variables, but if there is some reason they don't  
>> want to
>> do that, they could draw from a common stream; the first stream  
>> generated by
>> the RNG.  This stream would only provide Uniform(a,b) random  
>> variables,
>> presumably via static functions or else via some global object.
>> From the email:
> * remove the GetSingleValue function from RandomVariable classes
> The GetSingleValue function allows for potential non-independence as
> it draws values from a single RNG stream for different random
> variables.  Each random variable should have its own RNG stream.
>> From that text it sounds like either a temporary RV instance or a  
>> single
> global RV for all OLSR instances is not recommended.  But I am  
> partially
> guessing.  Under which conditions does "Each random variable should  
> have its
> own RNG stream" hold true?  Without reading the source code I can't  
> be 100%
> sure.

 From a RNG point of view, for each different random variable that you  
use, you should have a separate RandomVariable object which creates a  
separate RNG stream to ensure independence.

If you replace UniformVariable::GetSingleValue (0, OLSR_MAXJITTER)  
with UniformVariable().GetValue (0, OLSR_MAXJITTER), then GetValue()  
will automatically setup a new RNG stream if one isn't already  
associated with the UniformVariable.

I'm not familiar with the OLSR implementation (I just glanced at it to  
see how GetSingleValue was used), but could you create a single  
UniformVariable random variable that all OLSR agents were able to  
use?  I wouldn't have a problem if a set of agents used the same  
RandomVariable (and thus, the same RNG stream) to draw numbers from  
since it's only used in one place in OLSR.

BUT, if there were multiple unrelated items (for example, delay, loss,  
and bandwidth - just to make up something) that used the same  
RandomVariable object (and thus, same RNG stream), I would be  
uncomfortable with guaranteeing independence.  This is the main reason  
why I advocated getting rid of GetSingleValue().

Does that explanation help?


More information about the Ns-developers mailing list