The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ... The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

nmlab.korea.ac.kr
from nmlab.korea.ac.kr More from this publisher
12.07.2015 Views

protected:double lastx_;double lasty_;double sum_;};From integrator.cc:Integrator::Integrator() : lastx_(0.), lasty_(0.), sum_(0.){bind("lastx_", &lastx_);bind("lasty_", &lasty_);bind("sum_", &sum_);}void Integrator::set(double x, double y){lastx_ = x;lasty_ = y;sum_ = 0.;}void Integrator::newPoint(double x, double y){sum_ += (x - lastx_) * lasty_;lastx_ = x;lasty_ = y;}int Integrator::command(int argc, const char*const* argv){if (argc == 4) {if (strcmp(argv[1], "newpoint") == 0) {double x = atof(argv[2]);double y = atof(argv[3]);newPoint(x, y);return (TCL_OK);}}return (TclObject::command(argc, argv));}This class provides a base class used by other classes such as QueueMonitor that keep running sums. Each new elementof the running sum is added by the newPoint(x, y) function. After the kth execution of newPoint, the running sum isequal to ∑ ki=1 y i−1(x i − x i−1 ) where x 0 = y 0 = 0 unless lastx_, lasty_, or sum_ are reset via OTcl. Note that a newpoint in the sum can be added either by the C++ member newPoint or the OTcl member newpoint. The use of integralsto compute certain types of averages (e.g. mean queue lengths) is given in (pp. 429–430, [15]).25.4 ns-randomns-randomis an obsolete way to generate random numbers. This information is provided only for backward compatibility.227

ns-random is implemented in ~ns/misc.{cc,h}. When called with no argument, it generates a random number with uniformdistribution between 0 and MAXINT. When an integer argument is provided, it seeds the random generater with the givennumber. A special case is when ns-random 0 is called, it randomly seeds the generator based on current time. This featureis useful to produce non-deterministic results across runs.25.5 Some mathematical-support related objectsINTEGRATOR OBJECTS Integrator Objects support the approximate computation of continuous integrals using discrete sums.The running sum(integral) is computed as: sum_ += [lasty_ * (x lastx_)] where (x, y) is the last element enteredand (lastx_, lasty_) was the element previous to that added to the sum. lastx_ and lasty_ are updated as new elements areadded. The first sample point defaults to (0,0) that can be changed by changing the values of (lastx_,lasty_). $integratornewpoint Add the point (x,y) to the sum. Note that it does not make sense for x to be less than lastx_.There are no configuration parameters specific to this object.State Variables are:lastx_ x-coordinate of the last sample point.lasty_ y-coordinate of the last sample point.sum_ Running sum (i.e. the integral) of the sample points.SAMPLES OBJECT Samples Objects support the computation of mean and variance statistics for a given sample.$samples meanReturns mean of the sample.$samples varianceReturns variance of the sample.$samples cntReturns a count of the sample points considered.$samples resetReset the Samples object to monitor a fresh set of samples.There are no configuration parameters or state variables specific to this object.25.6 Commands at a glanceFollowing is a list of mathematical support related commands commonly used in simulation scripts:set rng [new RNG]This creates a new random number generator.228

<strong>ns</strong>-r<strong>and</strong>om is implemented in ~<strong>ns</strong>/misc.{cc,h}. When called with no argument, it gener<strong>at</strong>es a r<strong>and</strong>om number with uniformdistribution between 0 <strong>and</strong> MAXINT. When an integer argument is provided, it seeds the r<strong>and</strong>om gener<strong>at</strong>er with the givennumber. A special case is when <strong>ns</strong>-r<strong>and</strong>om 0 is called, it r<strong>and</strong>omly seeds the gener<strong>at</strong>or based on current time. This fe<strong>at</strong>ureis useful to produce non-deterministic results across ru<strong>ns</strong>.25.5 Some m<strong>at</strong>hem<strong>at</strong>ical-support rel<strong>at</strong>ed objectsINTEGRATOR OBJECTS Integr<strong>at</strong>or Objects support the approxim<strong>at</strong>e comput<strong>at</strong>ion of continuous integrals using discrete sums.<strong>The</strong> running sum(integral) is computed as: sum_ += [lasty_ * (x lastx_)] where (x, y) is the last element entered<strong>and</strong> (lastx_, lasty_) was the element previous to th<strong>at</strong> added to the sum. lastx_ <strong>and</strong> lasty_ are upd<strong>at</strong>ed as new elements areadded. <strong>The</strong> first sample point defaults to (0,0) th<strong>at</strong> can be changed by changing the values of (lastx_,lasty_). $integr<strong>at</strong>ornewpoint Add the point (x,y) to the sum. Note th<strong>at</strong> it does not make se<strong>ns</strong>e for x to be less than lastx_.<strong>The</strong>re are no configur<strong>at</strong>ion parameters specific to this object.St<strong>at</strong>e Variables are:lastx_ x-coordin<strong>at</strong>e of the last sample point.lasty_ y-coordin<strong>at</strong>e of the last sample point.sum_ Running sum (i.e. the integral) of the sample points.SAMPLES OBJECT Samples Objects support the comput<strong>at</strong>ion of mean <strong>and</strong> variance st<strong>at</strong>istics for a given sample.$samples meanRetur<strong>ns</strong> mean of the sample.$samples varianceRetur<strong>ns</strong> variance of the sample.$samples cntRetur<strong>ns</strong> a count of the sample points co<strong>ns</strong>idered.$samples resetReset the Samples object to monitor a fresh set of samples.<strong>The</strong>re are no configur<strong>at</strong>ion parameters or st<strong>at</strong>e variables specific to this object.25.6 Comm<strong>and</strong>s <strong>at</strong> a glanceFollowing is a list of m<strong>at</strong>hem<strong>at</strong>ical support rel<strong>at</strong>ed comm<strong>and</strong>s commonly used in simul<strong>at</strong>ion scripts:set rng [new RNG]This cre<strong>at</strong>es a new r<strong>and</strong>om number gener<strong>at</strong>or.228

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!