WSF
WsfRandomVariable Class Reference

#include <WsfRandomVariable.hpp>

Inherits UtScriptAccessible.

Collaboration diagram for WsfRandomVariable:

Public Types

enum  Distribution {
  cCONSTANT , cEXPONENTIAL , cLOG_NORMAL , cNORMAL ,
  cUNIFORM
}
 The distribution of the resulting values. More...
enum  Constraints { cNO_CONSTRAINT , cPOSITIVE , cNON_NEGATIVE }
 The constraints on the resulting values. More...

Public Member Functions

 WsfRandomVariable ()
 Construct a default random variable with a uniform distribution in the range (0..1).
 WsfRandomVariable (Constraints aConstraints)
 Construct a default random variable with a uniform distribution in the range (0..1).
 WsfRandomVariable (double aConstant, Constraints aConstraints)
 WsfRandomVariable (double aMinimum, double aMaximum, Constraints aConstraints)
 WsfRandomVariable (Distribution aDistribution, double aParameter1, double aParameter2, Constraints aConstraints)
 WsfRandomVariable (Distribution aDistribution, const WsfVariable< double > &aParameter1, const WsfVariable< double > &aParameter2, Constraints aConstraints)
bool Initialize (const std::string &aName, WsfComponent *aObjectPtr, WsfScriptContext *aContextPtr, WsfSimulation &aSimulation)
void ProcessInput (UtInput &aInput, UtInput::ValueType aValueType)
void DefineDistribution (Distribution aDistribution, const WsfVariable< double > &aParameter1, const WsfVariable< double > &aParameter2, Constraints aConstraints)
double Draw ()
 Draw the next random value from the distribution.
double LastDraw () const
 Return the last drawn value.

Conversion operators.

ut::Random * mRandomPtr
 A pointer to the currently used generator.
ut::Random mRandom
 A random number generator instance, for script usage.
Distribution mDistribution
 The type of distribution.
Constraints mConstraints
 Constraints on the resulting values.
double mValue
 The current (last drawn) value.
WsfVariable< double > mParameter1
WsfVariable< double > mParameter2
 operator double () const
 Returns the last drawn value.
const char * GetScriptClassName () const override
void SetGenerator (WsfSimulation &aSim)
 Set the random pointer for usage outside ProcessInput().
void SetDefaultValues ()
 Helper method to set initial values when 'Draw' is not called first.

WsfRandomVariable Accessors

double GetParameterFirst () const
double GetParameterSecond () const
Constraints GetConstraints () const
Distribution GetDistribution () const

Relational operators.

We're using the default assignment operator. WsfRandomVariable& operator=(const WsfRandomVariable& aRhs)

double operator== (double aRhs) const
 Is the last drawn value equal to the specified value?
double operator!= (double aRhs) const
 Is the last drawn value not equal to the specified value.
double operator< (double aRhs) const
 Is the last draw value less than the specified value.

Detailed Description

A class that defines a continuous random variable. This class defines a continuous random variable whose distribution can be defined from an input stream.

See also
WsfRandom

Member Enumeration Documentation

◆ Constraints

The constraints on the resulting values.

Enumerator
cNO_CONSTRAINT 

The variable values can be negative, zero or positive (subject to the distribution).

cPOSITIVE 

Value must be greater than zero.

cNON_NEGATIVE 

Value must be greater than or equal to zero.

◆ Distribution

The distribution of the resulting values.

Enumerator
cCONSTANT 

The random values will always have a constant value.

cEXPONENTIAL 

The random values will have a exponential distribution.

cLOG_NORMAL 

The random values will have a log-normal distribution.

cNORMAL 

The random values will have a normal distribution.

cUNIFORM 

The random values will have a uniform distribution.

Constructor & Destructor Documentation

◆ WsfRandomVariable() [1/6]

WsfRandomVariable::WsfRandomVariable ( )

Construct a default random variable with a uniform distribution in the range (0..1).

References cPOSITIVE, cUNIFORM, DefineDistribution(), and mRandomPtr.

◆ WsfRandomVariable() [2/6]

WsfRandomVariable::WsfRandomVariable ( Constraints aConstraints)

Construct a default random variable with a uniform distribution in the range (0..1).

References cUNIFORM, DefineDistribution(), and mRandomPtr.

◆ WsfRandomVariable() [3/6]

WsfRandomVariable::WsfRandomVariable ( double aConstant,
Constraints aConstraints )

Construct a random variable with a constant value.

Parameters
aConstantThe constant value.
aConstraintsAdditional constraints on the resulting values.

References cCONSTANT, DefineDistribution(), and mRandomPtr.

◆ WsfRandomVariable() [4/6]

WsfRandomVariable::WsfRandomVariable ( double aMinimum,
double aMaximum,
Constraints aConstraints )

Construct a random variable with a uniform distribution of (minimum, maximum).

Parameters
aMinimumThe minimum value of the distribution.
aMaximumThe maximum value of the distribution.
aConstraintsAdditional constraints on the resulting values.

References cUNIFORM, DefineDistribution(), and mRandomPtr.

◆ WsfRandomVariable() [5/6]

WsfRandomVariable::WsfRandomVariable ( Distribution aDistribution,
double aParameter1,
double aParameter2,
Constraints aConstraints )

Construct a random variable with a specific distribution.

Parameters
aDistributionThe type of distribution.
aParameter1The first parameter for the distribution.
  • For a constant distribution this is the constant value.
  • For a uniform distribution this is the minimum value.
  • For a normal or log-normal distribution this is the mean value.
  • For an exponential distribution this is the lambda.
aParameter2The second parameter for the distribution.
  • For a constant distribution this is unused.
  • For a uniform distribution this is the maximum value.
  • For a normal or log-normal distribution this is the standard deviation.
  • For an exponential distribution this is unused.
aConstraintsAdditional constraints on the resulting values.

References DefineDistribution(), and mRandomPtr.

◆ WsfRandomVariable() [6/6]

WsfRandomVariable::WsfRandomVariable ( Distribution aDistribution,
const WsfVariable< double > & aParameter1,
const WsfVariable< double > & aParameter2,
Constraints aConstraints )

Construct a random variable with a specific distribution.

Parameters
aDistributionThe type of distribution.
aParameter1The first parameter for the distribution.
  • For a constant distribution this is the constant value.
  • For a uniform distribution this is the minimum value.
  • For a normal or log-normal distribution this is the mean value.
  • For an exponential distribution this is the lambda.
aParameter2The second parameter for the distribution.
  • For a constant distribution this is unused.
  • For a uniform distribution this is the maximum value.
  • For a normal or log-normal distribution this is the standard deviation.
  • For an exponential distribution this is unused.
aConstraintsAdditional constraints on the resulting values.

References DefineDistribution(), and mRandomPtr.

Member Function Documentation

◆ DefineDistribution()

void WsfRandomVariable::DefineDistribution ( Distribution aDistribution,
const WsfVariable< double > & aParameter1,
const WsfVariable< double > & aParameter2,
Constraints aConstraints )

Set the defining parameters of the distribution.

Parameters
aDistributionThe type of distribution.
aParameter1The first parameter for the distribution.
  • For a constant distribution this is the constant value.
  • For a uniform distribution this is the minimum value.
  • For a normal or log-normal distribution this is the mean value.
aParameter2The second parameter for the distribution.
  • For a constant distribution this is unused.
  • For a uniform distribution this is the maximum value.
  • For a normal or log-normal distribution this is the standard deviation.
aConstraintsAdditional constraints on the resulting values.

References mConstraints, mDistribution, mParameter1, mParameter2, and SetDefaultValues().

Referenced by ProcessInput(), WsfRandomVariable(), WsfRandomVariable(), WsfRandomVariable(), WsfRandomVariable(), WsfRandomVariable(), and WsfRandomVariable().

◆ Draw()

double WsfRandomVariable::Draw ( )

◆ GetConstraints()

Constraints WsfRandomVariable::GetConstraints ( ) const
inline

References mConstraints.

◆ GetDistribution()

Distribution WsfRandomVariable::GetDistribution ( ) const
inline

References mDistribution.

◆ GetParameterFirst()

double WsfRandomVariable::GetParameterFirst ( ) const
inline

References mParameter1.

◆ GetParameterSecond()

double WsfRandomVariable::GetParameterSecond ( ) const
inline

References mParameter2.

◆ GetScriptClassName()

const char * WsfRandomVariable::GetScriptClassName ( ) const
inlineoverride

◆ Initialize()

bool WsfRandomVariable::Initialize ( const std::string & aName,
WsfComponent * aObjectPtr,
WsfScriptContext * aContextPtr,
WsfSimulation & aSimulation )

◆ LastDraw()

double WsfRandomVariable::LastDraw ( ) const
inline

Return the last drawn value.

References mValue.

Referenced by wsf::comm::medium::ModeUnguided::CalculateTransferRate().

◆ operator double()

WsfRandomVariable::operator double ( ) const
inline

Returns the last drawn value.

References mValue.

◆ operator!=()

double WsfRandomVariable::operator!= ( double aRhs) const
inline

Is the last drawn value not equal to the specified value.

References mValue.

◆ operator<()

double WsfRandomVariable::operator< ( double aRhs) const
inline

Is the last draw value less than the specified value.

References mValue.

◆ operator==()

double WsfRandomVariable::operator== ( double aRhs) const
inline

Is the last drawn value equal to the specified value?

References mValue.

◆ ProcessInput()

void WsfRandomVariable::ProcessInput ( UtInput & aInput,
UtInput::ValueType aValueType )

Define a distribution from an input stream. This method reads a distribution definition from the input stream. The input can be of the form:

  • constant <value>
  • <value> (a synonym for a constant value)
  • exponential lambda <value>
  • exponential (a synonym for exponential w\ lambda = 1.0)
  • log_normal mean <value> sigma <value>
  • normal mean <value> sigma <value>
  • uniform minimum <value> maximum <value>
    Parameters
    aInputThe input stream.
    aValueTypeThe units of the values.

References cCONSTANT, cEXPONENTIAL, cLOG_NORMAL, cNON_NEGATIVE, cNORMAL, cPOSITIVE, cUNIFORM, DefineDistribution(), mConstraints, WsfVariable< T >::ReadValueOfType(), WsfVariable< T >::ValueGreater(), and WsfVariable< T >::ValueGreaterOrEqual().

Referenced by wsf::comm::NetworkAdHoc::ProcessAddressRate(), wsf::cyber::Attack::ProcessFrequencyInput(), wsf::comm::PhysicalLayer::ProcessInput(), wsf::comm::ProtocolIGMP::ProcessInput(), wsf::comm::router::ProtocolOSPF::ProcessInput(), WsfLaserWeapon::ProcessInput(), WsfRF_Jammer::ProcessInput(), WsfTrackStateController::ProcessInput(), and wsf::comm::NetworkAdHoc::ProcessNamedRate().

◆ SetDefaultValues()

void WsfRandomVariable::SetDefaultValues ( )
protected

Helper method to set initial values when 'Draw' is not called first.

References cCONSTANT, cEXPONENTIAL, cLOG_NORMAL, cNORMAL, cUNIFORM, mDistribution, mParameter1, mParameter2, and mValue.

Referenced by DefineDistribution(), and Initialize().

◆ SetGenerator()

void WsfRandomVariable::SetGenerator ( WsfSimulation & aSim)

Set the random pointer for usage outside ProcessInput().

References WsfSimulation::GetRandom(), mRandom, and mRandomPtr.

Referenced by wsf::comm::NetworkAdHoc::ChangeRate(), and UT_DEFINE_SCRIPT_METHOD().

Member Data Documentation

◆ mConstraints

Constraints WsfRandomVariable::mConstraints
protected

Constraints on the resulting values.

Referenced by DefineDistribution(), Draw(), GetConstraints(), and ProcessInput().

◆ mDistribution

Distribution WsfRandomVariable::mDistribution
protected

The type of distribution.

Referenced by DefineDistribution(), Draw(), GetDistribution(), Initialize(), and SetDefaultValues().

◆ mParameter1

WsfVariable<double> WsfRandomVariable::mParameter1
protected

The first parameter of the distribution.

  • For a constant distribution it is the constant value.
  • For a uniform distribution this is the minimum value.
  • For normal or log normal it is the mean value.

Referenced by DefineDistribution(), Draw(), GetParameterFirst(), Initialize(), and SetDefaultValues().

◆ mParameter2

WsfVariable<double> WsfRandomVariable::mParameter2
protected

The second parameter of the distribution.

  • For a constant distribution it is unused.
  • For a uniform distribution this is the maximum value.
  • For a normal or log normal it is the standard deviation.

Referenced by DefineDistribution(), Draw(), GetParameterSecond(), Initialize(), and SetDefaultValues().

◆ mRandom

ut::Random WsfRandomVariable::mRandom
protected

A random number generator instance, for script usage.

Referenced by SetGenerator().

◆ mRandomPtr

ut::Random* WsfRandomVariable::mRandomPtr
protected

◆ mValue

double WsfRandomVariable::mValue
protected

The current (last drawn) value.

Referenced by Draw(), LastDraw(), operator double(), operator!=(), operator<(), operator==(), and SetDefaultValues().


The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved