WSF
WsfRandomVariable.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11// ****************************************************************************
12// Updated by Infoscitex, a DCS Company.
13// ****************************************************************************
14
15#ifndef WSFRANDOMVARIABLE_HPP
16#define WSFRANDOMVARIABLE_HPP
17
18#include "wsf_export.h"
19
20#include "UtInput.hpp"
21#include "UtRandom.hpp"
22#include "UtScriptAccessible.hpp"
23#include "UtScriptClassDefine.hpp"
25class WsfSimulation;
26#include "WsfVariable.hpp"
27
32class WSF_EXPORT WsfRandomVariable : public UtScriptAccessible
33{
34public:
44
52
53 // NOTE: The default (member-wise) copy constructor and assignment operator are used.
54 // Copying or assigning a 'Initialized variable is OK as long as the copy would also
55 // refer to the same script context.
56
58 WsfRandomVariable(Constraints aConstraints);
59 WsfRandomVariable(double aConstant, Constraints aConstraints);
60 WsfRandomVariable(double aMinimum, double aMaximum, Constraints aConstraints);
61 WsfRandomVariable(Distribution aDistribution, double aParameter1, double aParameter2, Constraints aConstraints);
62 WsfRandomVariable(Distribution aDistribution,
63 const WsfVariable<double>& aParameter1,
64 const WsfVariable<double>& aParameter2,
65 Constraints aConstraints);
66
67 bool Initialize(const std::string& aName, WsfComponent* aObjectPtr, WsfScriptContext* aContextPtr, WsfSimulation& aSimulation);
68
69 void ProcessInput(UtInput& aInput, UtInput::ValueType aValueType);
70
71 void DefineDistribution(Distribution aDistribution,
72 const WsfVariable<double>& aParameter1,
73 const WsfVariable<double>& aParameter2,
74 Constraints aConstraints);
75
76 double Draw();
77
79 double LastDraw() const { return mValue; }
80
82
83 double GetParameterFirst() const { return mParameter1; }
84 double GetParameterSecond() const { return mParameter2; }
88
90
91
93
94
96
97
98 double operator==(double aRhs) const { return (mValue == aRhs); }
100 double operator!=(double aRhs) const { return (mValue != aRhs); }
102 double operator<(double aRhs) const { return (mValue < aRhs); }
104
106
107
108 operator double() const { return mValue; }
110
111 const char* GetScriptClassName() const override { return "WsfRandomVariable"; }
112
114 void SetGenerator(WsfSimulation& aSim);
115
116protected:
118 void SetDefaultValues();
119
121 ut::Random* mRandomPtr;
122
124 ut::Random mRandom;
125
128
131
133 double mValue;
134
140
146};
147
148class WSF_EXPORT WsfScriptRandomVariableClass : public UtScriptClass
149{
150public:
151 WsfScriptRandomVariableClass(const std::string& aClassName, UtScriptTypes* aTypesPtr);
152
153 ~WsfScriptRandomVariableClass() override = default;
154
155 void* Create(const UtScriptContext& aInstance) override;
156 void* Clone(void* aObjectPtr) override;
157 void Destroy(void* aObjectPtr) override;
158
160
163
164 UT_DECLARE_SCRIPT_METHOD(GetFirstParameter);
165 UT_DECLARE_SCRIPT_METHOD(GetSecondParameter);
167 UT_DECLARE_SCRIPT_METHOD(GetDistribution);
168};
169
170#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfComponent.hpp:39
Definition WsfRandomVariable.hpp:33
WsfVariable< double > mParameter2
Definition WsfRandomVariable.hpp:145
double GetParameterFirst() const
Definition WsfRandomVariable.hpp:83
Distribution mDistribution
The type of distribution.
Definition WsfRandomVariable.hpp:127
double operator<(double aRhs) const
Is the last draw value less than the specified value.
Definition WsfRandomVariable.hpp:102
double operator!=(double aRhs) const
Is the last drawn value not equal to the specified value.
Definition WsfRandomVariable.hpp:100
Distribution
The distribution of the resulting values.
Definition WsfRandomVariable.hpp:37
@ cUNIFORM
The random values will have a uniform distribution.
Definition WsfRandomVariable.hpp:42
@ cLOG_NORMAL
The random values will have a log-normal distribution.
Definition WsfRandomVariable.hpp:40
@ cNORMAL
The random values will have a normal distribution.
Definition WsfRandomVariable.hpp:41
@ cEXPONENTIAL
The random values will have a exponential distribution.
Definition WsfRandomVariable.hpp:39
@ cCONSTANT
The random values will always have a constant value.
Definition WsfRandomVariable.hpp:38
WsfRandomVariable()
Construct a default random variable with a uniform distribution in the range (0..1).
Definition WsfRandomVariable.cpp:132
Constraints
The constraints on the resulting values.
Definition WsfRandomVariable.hpp:47
@ cNO_CONSTRAINT
The variable values can be negative, zero or positive (subject to the distribution).
Definition WsfRandomVariable.hpp:48
@ cPOSITIVE
Value must be greater than zero.
Definition WsfRandomVariable.hpp:49
@ cNON_NEGATIVE
Value must be greater than or equal to zero.
Definition WsfRandomVariable.hpp:50
Constraints mConstraints
Constraints on the resulting values.
Definition WsfRandomVariable.hpp:130
const char * GetScriptClassName() const override
Definition WsfRandomVariable.hpp:111
double GetParameterSecond() const
Definition WsfRandomVariable.hpp:84
Constraints GetConstraints() const
Definition WsfRandomVariable.hpp:85
Distribution GetDistribution() const
Definition WsfRandomVariable.hpp:86
double mValue
The current (last drawn) value.
Definition WsfRandomVariable.hpp:133
ut::Random mRandom
A random number generator instance, for script usage.
Definition WsfRandomVariable.hpp:124
double operator==(double aRhs) const
Is the last drawn value equal to the specified value?
Definition WsfRandomVariable.hpp:98
double LastDraw() const
Return the last drawn value.
Definition WsfRandomVariable.hpp:79
WsfVariable< double > mParameter1
Definition WsfRandomVariable.hpp:139
ut::Random * mRandomPtr
A pointer to the currently used generator.
Definition WsfRandomVariable.hpp:121
Definition WsfScriptContext.hpp:71
UT_DECLARE_SCRIPT_METHOD(GetDistribution)
void * Create(const UtScriptContext &aInstance) override
Definition WsfRandomVariable.cpp:532
UT_DECLARE_SCRIPT_METHOD(GetConstraint)
WsfScriptRandomVariableClass(const std::string &aClassName, UtScriptTypes *aTypesPtr)
Definition WsfRandomVariable.cpp:512
UT_DECLARE_SCRIPT_METHOD(GetFirstParameter)
UT_DECLARE_SCRIPT_METHOD(GetSecondParameter)
~WsfScriptRandomVariableClass() override=default
void * Clone(void *aObjectPtr) override
Definition WsfRandomVariable.cpp:538
void Destroy(void *aObjectPtr) override
Definition WsfRandomVariable.cpp:544
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Definition WsfVariable.hpp:149
Copyrights Multiple, All Rights Reserved