VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
13.8 - Conditional Expressions

Table of Contents

This section provides details about the different types of conditional expressions.

The first two subsections discuss DtSimCondExpr and DtEvaluator. These objects are created by factories in VR-Forces. You can extend the set of existing conditional expressions by creating and registering new subclasses with the appropriate factories. For details, please see the Add Condition (GUI) and Add Condition (Sim) examples.

13.8.1 Conditional Expression Objects

DtSimCondExpr (condExpr.h) objects represent conditional expressions. They are used to test the properties of entities and units.

A simple conditional expression can be represented by just a single object. More complicated expressions are formed as tree structures of simpler expressions (sub-expressions) combined by the operators: AND, OR and NOT, which are themselves conditional expressions.

For example:

AND(Entity-In-Area Entity:"1 M1A2, 1 Force" Area:"base camp", resource(fuel) < 50%)

would be represented in objects as:

conditionalexpression.png
Conditional Expression Objects

When If statements or When statements want to test the current state of a conditional expression, they call the evaluate() member function, which recursively evaluates all operators and their sub-expressions.

13.8.2 Conditional Expression Evaluators

DtSimCondExprs are evaluated by calling their evaluate() member functions. The DtSimCondExpr class does not actually perform the evaluation of the expression itself. Instead, in its evaluate() function, it uses a DtEvaluator object to actually perform the test. In the VR-Forces back-end, DtSimCondExpr’s are always configured with a corresponding DtEvaluator class (a DtEvaluator is always created and set in a DtSimCondExpr class, whenever a DtSimCondExpr is created). DtSimCondExprs that are configured with a DtEvaluator invoke the DtEvaluator’s evaluate() member function whenever its evaluate() function is called. Each DtEvaluator subclass is designed to work with a particular DtSimCondExpr, so there is a one-to-one correspondence between DtSimCondExpr subclasses and DtEvaluator subclasses.

In a remote application (an application that uses the VR-Forces Remote Control API, such as a GUI), conditional expressions are created and used without DtEvaluators. They only need the data aspect of a conditional express to be able to do things such as display and edit plans. They never need to actually evaluate the expression, so the DtSimCondExpr’s evaluate() function is never invoked. They only need to hold the parameters associated with a particular conditional expression.

13.8.3 Logical Constants

The two logical constants (True and False) are implemented by the same class: DtCeConstant (ceConstant.h). It stores its value as a bool flag. The DtCeConstant class is configured with the DtEvalConstant (evalConstant.h) evaluator.

13.8.4 Logical Operators

The three logical operators (DtCeAnd (ceAnd.h), DtCeOr (ceOr.h), and DtCeNot (ceNot.h)) are very similar. They only differ in:

Each logical operator stores its sub-expressions as pointers to other DtSimCondExpr objects, which could also be logical operators. The AND and OR operators sub-expressions are called leftCondExpr() and rightCondExpr(). The NOT operator sub-expression is called condExpr().

The following evaluators are configured with the three logical operators:

13.8.5 Resource Operators

The DtCeResourceOperator (ceResourceOp.h) class represents a relational comparison (for example, <, >) between a simulation object's resource value and a floating point constant. Each DtCeResourceOperator contains a:

When the evaluate() function is called, the resource operator looks up the named resource in the localState() of the simulation object associated with the plan context.

If the percentFlag flag is true, the resource's percentageFull() value is used, otherwise the resource's amount() value is used. The resource value is then converted into a real number and compared to the specified comparison value, using the specified relational operator.

The supported operators are the same as in C++:

The DtCeResourceOperator class is configured with the DtEvalResourceOp (evalResourceOp.h) evaluator.

13.8.6 Conditional Expressions for Testing Entity Status

VR-Forces comes with several conditional expressions for testing simulation object status, such as:

Each test is given a unique identifier (the string returned by DtVrfObject::uuid()) and an optional modifier string. (Currently only the "ANY" modifier is implemented.) The unique identifier is the unique identifier for VR-Forces simulation objects, and is the simulation object identifier for non-VR-Forces remote simulation objects. The tests take other test-specific input.

The "ANY" modifier changes the way a test operates when it is applied to a unit or the force level. When ANY is not applied, a test is true only if it is true for all members of the unit. Therefore, the test terminates the first time it sees a simulation object that does not match the criteria. With the "ANY" modifier, a test is true if any one member of the unit satisfies the condition. Therefore, the search terminates the first time it finds a simulation object that matches the criteria.

Conditional tests can be applied to:

To apply their tests to the appropriate combination of simulation objects, the conditional expression simulation object tests use matching classes derived from DtSimSubordinateSearch (subSearch.h) to do the actual evaluate() work. DtCeEntDestroyed uses the DtEntDestroyedSearch (entDstroySrch.h) class; DtCeEntInArea uses the DtEntInAreaSearch (entInAreaSrch.h) class; and DtCeEntLeftOfLine uses the DtEntLeftOfLineSearch (entLOLineSrch.h) class.

13.8.7 The Random Operator

The random logical operator makes a random draw between 0 and 1, and compares the result against a given real probability parameter (if the result is less than the parameter, return True, otherwise returns False). It is implemented by the class DtCeRandom (ceRandom.h). It stores a DtReal probability parameter.

The DtCeRandom class is configured with the DtEvalRandom (evalRandom.h) evaluator.

[<< Statements] [Home] [Top of Page] [Triggers >>]


Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)