Evaluate Class
(Automation::Evaluate)A mathematical expression evaluation operator. More...
Header: | #include <Evaluate.h> |
Inherits: | CDPOperator<T> |
Public Functions
Reimplemented Public Functions
virtual bool | AddChild(const std::string &name, const std::string &typeName, const std::string &configuration) override |
virtual void | Configure(XMLPrimitive *operatorXML) override |
virtual void | Create(const char *shortName, CDPBaseObject *pParent) override |
virtual void | FillNodeChildren(CDP::StudioAPI::NodeStream &stream) const override |
virtual unsigned int | Process() override |
virtual bool | RemoveChild(const std::string &name) override |
- 18 public functions inherited from CDPOperator
- 17 public functions inherited from CDPOperatorBase
- 46 public functions inherited from CDPBaseObject
- 26 public functions inherited from CDP::StudioAPI::CDPNode
- 22 public functions inherited from CDP::StudioAPI::ICDPNode
Additional Inherited Members
- 1 public variable inherited from CDPOperatorBase
- 1 static public member inherited from CDPBaseObject
- 1 protected function inherited from CDP::StudioAPI::CDPNode
- 8 protected variables inherited from CDPOperator
- 5 protected variables inherited from CDPOperatorBase
- 11 protected variables inherited from CDPBaseObject
Detailed Description
A mathematical expression evaluation operator.
This CDP operator can be used to modify input value based on complex mathematical expressions with unlimited number of arguments.
Properties
Property | Description |
---|---|
Expression | Mathematical expression to evaluate. 13 mathematical operators, ternary operator and 25 different functions are supported. |
Arguments
Argument | Description |
---|---|
Input | The default input value. |
Out | The default output value. |
Unlimited number of arguments with any name except "Input" | Arguments to use in calculation. Argument with name "Input" is reserved and can be used to include in expression with default input value before evaluation. |
Evaluate operator arguments can be routed from another signal, parameter or property.
The power of the Evaluate operator
The Evaluate operator is a very powerful and flexible operator that can be used to do complex signal arithmetic without any C++ programming. Just add the named arguments to the Evaluate operator (values to the arguments can be routed from signals, properties or parameters) and specify the mathematical expression to calculate the output value. In every processing cycle this evaluation expression (that can refer to any of the named arguments in any combination) is used, and output value is calculated based on that.
Just to illustrate the power of Evaluate operator, below are examples how it can be used instead of many other, specialized CDP operators:
CDP operator | Evaluate operator Expression that can be used instead |
---|---|
AddOperator | Input + Argument1 + Argument2 + Argument3 |
SubOperator | Input - Argument1 - Argument2 - Argument3 |
MulOperator | Input * Argument1 * Argument2 * Argument3 |
DivOperator | Input / Argument1 / Argument2 / Argument3 |
ForceOperator | ForceActive ? ForceValue : Input |
InvertOperator<bool> | Input == 0 ? 1 : 0 |
MinMaxLimiter | max(min(Input, Max), Min) or Input > Max ? Max : ( Input < Min ? Min : Input ) |
NormalPositionOperator<bool> | NormalPosition==0 ? Input : (Input==0 ? 1 : 0) |
Note: The power and flexibility of the Evaluate operator does not come without cost. The Evaluate operator requires much more computing power than other specialized operators. Consider using specialized operators instead of the Evaluate operator if your system CPU power is very limited. Or alternatively, you can create your own custom operator (via Library->Add New Operator wizard) and program needed functionality in C++.
Example
Below is an example plot with Sine signal (cyan) and the same signal with Evaluate operator with property parameters:
Argument | Value |
---|---|
A | -0.1 |
B | 2 |
Evaluate Expression | Input >A ? Input + 0.2 : (Input - 0.1) ^ B |
Mathematical operators supported by Evaluate
Operator | Description | Priority |
---|---|---|
&& | logical and | 1 |
|| | logical or | 2 |
<= | less or equal | 4 |
>= | greater or equal | 4 |
!= | not equal | 4 |
== | equal | 4 |
< | less than | 4 |
> | greater than | 4 |
+ | addition | 5 |
- | subtraction | 5 |
* | multiplication | 6 |
/ | division | 6 |
^ | raise x to the power of y | 7 |
Ternary Operator
Evaluate supports the "if then else" operator. It uses lazy evaluation in order to make sure only the necessary branch of the expression is evaluated.
Operator | Description | Remarks |
---|---|---|
?: | if then else operator | C++ style syntax |
Mathematical functions supported by Evaluate
Function | # of arguments | Explanation |
---|---|---|
sin | 1 | sine function |
cos | 1 | cosine function |
tan | 1 | tangens function |
asin | 1 | arcus sine function |
acos | 1 | arcus cosine function |
atan | 1 | arcus tangens function |
sinh | 1 | hyperbolic sine function |
cosh | 1 | hyperbolic cosine |
tanh | 1 | hyperbolic tangens function |
asinh | 1 | hyperbolic arcus sine function |
acosh | 1 | hyperbolic arcus tangens function |
atanh | 1 | hyperbolic arcus tangens function |
log2 | 1 | logarithm to the base 2 |
log10 | 1 | logarithm to the base 10 |
log | 1 | logarithm to base e (2.71828...) |
ln | 1 | logarithm to base e (2.71828...) |
exp | 1 | e raised to the power of x |
sqrt | 1 | square root of a value |
sign | 1 | sign function -1 if < 0; 1 if > 0 |
rint | 1 | round to nearest integer |
abs | 1 | absolute value |
min | unlimited | min of all arguments |
max | unlimited | max of all arguments |
sum | unlimited | sum of all arguments |
avg | unlimited | mean value of all arguments |
_pi | 0 | the value of PI (3.141592653589793238462643) |
_e | 0 | Euler's number (2.718281828459045235360287) |
When operator is used inside a signal its default input is automatically tied to signal's InternalValue or previous operator's output. Its default output is automatically tied to next operator's input or to signal's Value. See also CDP Operator Usage In CDP Signals.
Actual Processing Code of the Evaluate
unsigned int Evaluate<T>::Process() { if (m->parserOk) { try { m->inputVal = static_cast<double>(m_input); for (size_t i=0; i < m_arguments.size(); i++) m->argVals[i] = static_cast<double>(*m_arguments[i]); m_output = m->mp.Eval(); } catch (Parser::exception_type &e) { GetParent()->ReportConfigurationFault(this, "Can not evaluate expression '" + e.GetExpr() + "': " + e.GetMsg()); m->faultReported = true; return STATUS_SIGNAL_FAULT; } if (m->faultReported) { GetParent()->ClearConfigurationFault(this); m->faultReported = false; } return STATUS_OK; } return STATUS_SIGNAL_FAULT; }
See also Argument.
Member Function Documentation
Evaluate::Evaluate(const CDPPropertyBase &in)
Constructs a Evaluate with input in.
[virtual]
Evaluate::~Evaluate()
Destructs the Evaluate operator
[override virtual]
bool Evaluate::AddChild(const std::string &name, const std::string &typeName, const std::string &configuration)
[override virtual]
void Evaluate::Configure(XMLPrimitive *operatorXML)
Reimplemented from CDPBaseObject::Configure().
Configure arguments and then create muParser variable array based on them and also "Input" variable Do this once in Configure() instead of Process() for speed (as argument count and names can not change at runtime).
[override virtual]
void Evaluate::Create(const char *shortName, CDPBaseObject *pParent)
Reimplemented from CDPBaseObject::Create().
[override virtual]
void Evaluate::FillNodeChildren(CDP::StudioAPI::NodeStream &stream) const
Reimplemented from CDPNode::FillNodeChildren().
[override virtual]
unsigned int Evaluate::Process()
Reimplemented from CDPOperatorBase::Process().
Value "Input" variable and all arguments, expression string and then let muParser calculate the output value. Also catch muParser evaluation errors and report them to parent component.
[override virtual]
bool Evaluate::RemoveChild(const std::string &name)
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.