[Ns-developers] ns3::RandomVariable

Gustavo Carneiro gjcarneiro at gmail.com
Wed Mar 18 04:53:32 PDT 2009


2009/3/18 Mathieu Lacage <mathieu.lacage at sophia.inria.fr>

> On Tue, 2009-03-17 at 23:34 -0700, Tom Henderson wrote:
> > >>
> > >> I should point out that there is a fundamental difference between Ptr
> and
> > >> the RandomVariable classes.  With Ptr, when you copy a pointer
> variable the
> > >> original object is not copied.  With a RandomVariable variable,
> copying the
> > >> variable will trigger a under-the-hood copy of the underlying XxxImpl.
> > >> Mathieu, correct me if I'm wrong (possible :)
> > >
> > > It is a bit more subtle. An example will make this clearer:
> > >
> > > // in this example, the two random variables share the same
> > > // distribution parameters but not the same seed so, they
> > > // will generate independent streams of random values which
> > > // share the same statistical properties
> > > RandomVariable a = UniformVariable (...);
> > > RandomVariable b = a;
> > > a.GetValue ();
> > > b.GetValue ();
> >
> > I am not seeing the above subtle behavior; a and b appear to be sharing
> > the same substream, just as in the below.
>
> I assume that you ran a python test program: python variable assignments
> do not perform a deep copy: they merely copy a reference so, if you
> wrote a naive python test program which matches this example, you won't
> see what I explained. The attached test program will show the behavior I
> allude to.
>
> Alternatively, the correct python idiom to trigger a deep copy is
> 'copy': http://docs.python.org/library/copy.html


Correct.

With pybindgen bindings you can do a value copy in one of three ways (for
C++ classes that have a copy constructor):

1. b = RandomVariable(a)
2. b = a.__copy__()
3. b = copy.copy(a) # copy.deepcopy is equivalent in this case

-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert


More information about the Ns-developers mailing list