<< Click to Display Table of Contents >> Navigation: Reference Manual > Node definitions > DSL_equation |
Header file: defequation.h
class DSL_equation : public DSL_nodeDef
DSL_equation provides implementation for nodes defined by equations (both chance and deterministic). The equation is specified as a string, validated, parsed, and stored in the DSL_generalEquation member variable. Equation nodes can be unbounded, bounded or semi-bounded. Equation nodes also define discretization intervals, which are used by hybrid inference algorithms.
virtual int GetType() const;
Overridden method from DSL_nodeDef. Returns DSL_EQUATION.
virtual const char* GetTypeName() const;
Overridden method from DSL_nodeDef. Returns "EQUATION".
const DSL_generalEquation& GetEquation() const;
Returns a reference to the DSL_generalEquation object, representing node equation in parsed form. The reference is const, and cannot be used to modify the equation.
int SetEquation(const std::string &eq,
int *errPos=NULL, std::string *errMsg=NULL);
Sets the node equation based on the text passed in eq parameter. The equation is parsed and validated. When validation fails and errPos or errMsg are not NULL, the error information is returned in these output parameters. The errMsg contains human-readable error message.
The equation should have only the node identifier on the LHS. Returns DSL_OKAY on success, or a negative error code on failure.
bool ValidateEquation(const std::string &eq,
std::vector<std::string> &vars,
std::string &errMsg, int *errPos=NULL,
bool *isConst = NULL) const;
Validates the equation and returns true if the equation is valid (i.e., using it in the SetEquation call would be successful). Checks for syntax errors and ensures that the referenced variable and function names are valid. The identifiers of the variables in the equation are returned in the vars output parameter. If validation fails, errMsg contains a human-readable error message. If validation fails and if errPos is not NULL, the index of the character in the equation string is returned.
void GetBounds(double &low, double &high) const;
Gets the domain for the variable represented by the node. If the domain of the node is unbounded or semi-bounded, the infinity is returned in one or both output parameters. Global helper function DSL_isFinite(double) returns true if its argument is finite.
void SetBounds(double low, double high);
Sets the domain for the variable represented by the node. Use plus or minus infinity to represent open bounds. Global helper function DSL_inf() returns positive infinity. Use -DSL_inf() for negative infinity.
bool HasDiscIntervals() const;
Returns true when the equation node has defined discretization intervals.
const IntervalVector& GetDiscIntervals() const;
Returns the reference to the defined intervals (which may be an empty vector if not defined yet). The IntervalVector is a typedef defined in DSL_equation class:
typedef std::vector<std::pair<std::string, double> > IntervalVector;
First element of the pair represents the interval id, is optional (can be empty), and is used only for display purposes. The second element is the upper bound of the interval. The lower bound is the upper bound of the preceding interval, or the lower bound of the first interval.
int GetDiscInterval(int intervalIndex, double &lo, double &hi) const;
Writes the edges for the discretization interval specified by intervalIndex to lo and hi. Returns DSL_OKAY on success, or a negative error code on failure.
void GetIntervalIds(DSL_idArray &ids) const;
Returns identifiers of a discretization interval.
void GetIntervalEdges(std::vector<double> &edges) const;
void GetIntervalEdges(DSL_doubleArray& edges) const;
void GetIntervalEdges(double* edges) const;
Returns the edges of a discretization interval. For N defined intervals, the output vector/array will be resized to N+1 elements. The first and the last edge are the low and the high bound, respectively. For the last overload, the caller must ensure that the buffer specified by the pointer has enough space for N+1 elements.
int SetDiscIntervals(const IntervalVector &intervals);
int SetDiscIntervals(double lo, double hi, const IntervalVector &intervals);
Set the intervals. The second overload also sets the node bounds. Returns DSL_OKAY on success, or a negative error code on failure.
int ClearDiscIntervals();
Removes discretization intervals. Does not affect node bounds. Returns DSL_OKAY on success, DSL_OUT_OF_RANGE if node has no discretization intervals, or DSL_WRONG_NODE_TYPE when node has discretization intervals and is a parent to discrete nodes (and therefore cannot be de-discretized).
int Discretize(double x) const;
Converts a continuous value to a non-negative integer interval index, based on the specified discretization intervals.