[Ns-developers] Random Variables API changes

Raj Bhattacharjea raj.b at gatech.edu
Tue Jan 20 10:08:52 PST 2009


On Tue, Jan 20, 2009 at 12:55 PM, Tom Henderson <tomh at tomh.org> wrote:
>
>>-----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.
>
> So, in the OLSR example, OLSR agent would have the choice of a per-agent UniformVariable generator, or could access the (global) first stream.  But, I didn't think that we were talking about using anonymous temporary variables for this purpose.
>
At present, there is no way to access a common "first" stream; this
functionality has been removed by Hadi's patch.

>From the old email from Michelle, it seems that the issue was that all
the static GetSingleValue methods were drawing from the same
underlying generator, which could cause the independence assumption
between variables to break down.

If EACH random variable class had a designated private static
generator, with a public interface i.e. GetSingleValue, then I believe
we could solve Michelle's issue, while breaking less API.

-- 
Raj Bhattacharjea
Georgia Institute of Technology
School of Electrical and Computer Engineering
Ph.D. Candidate
Systems Analyst
404.894.2955



More information about the Ns-developers mailing list