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

protected:double lastx_;double lasty_;double sum_;};From integr<strong>at</strong>or.cc:Integr<strong>at</strong>or::Integr<strong>at</strong>or() : lastx_(0.), lasty_(0.), sum_(0.){bind("lastx_", &lastx_);bind("lasty_", &lasty_);bind("sum_", &sum_);}void Integr<strong>at</strong>or::set(double x, double y){lastx_ = x;lasty_ = y;sum_ = 0.;}void Integr<strong>at</strong>or::newPoint(double x, double y){sum_ += (x - lastx_) * lasty_;lastx_ = x;lasty_ = y;}int Integr<strong>at</strong>or::comm<strong>and</strong>(int argc, co<strong>ns</strong>t char*co<strong>ns</strong>t* argv){if (argc == 4) {if (strcmp(argv[1], "newpoint") == 0) {double x = <strong>at</strong>of(argv[2]);double y = <strong>at</strong>of(argv[3]);newPoint(x, y);return (TCL_OK);}}return (TclObject::comm<strong>and</strong>(argc, argv));}This class provides a base class used by other classes such as QueueMonitor th<strong>at</strong> 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 th<strong>at</strong> a newpoint in the sum can be added either by the C++ member newPoint or the OTcl member newpoint. <strong>The</strong> use of integralsto compute certain types of averages (e.g. mean queue lengths) is given in (pp. 429–430, [15]).25.4 <strong>ns</strong>-r<strong>and</strong>om<strong>ns</strong>-r<strong>and</strong>omis an obsolete way to gener<strong>at</strong>e r<strong>and</strong>om numbers. This inform<strong>at</strong>ion is provided only for backward comp<strong>at</strong>ibility.227

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

Saved successfully!

Ooh no, something went wrong!