|
| ~Expression () |
|
| Expression () |
|
| Expression (const QString &aExpression) |
|
| Expression (const QString &expression, ExpressionWrapper *wrapper) |
|
void | setExpression (const QString &aExpression) |
| set expression More...
|
|
void | setAndParse (const QString &expr) |
| set expression and parse instantly More...
|
|
void | setModelObject (ExpressionWrapper *wrapper) |
|
const QString & | expression () const |
|
void | parse (ExpressionWrapper *wrapper=nullptr) |
| force a parsing of the expression More...
|
|
void | linearize (const double low_value, const double high_value, const int steps=1000) |
| call linearize() to 'linarize' an expression, i.e. approximate the function by linear interpolation. More...
|
|
void | linearize2d (const double low_x, const double high_x, const double low_y, const double high_y, const int stepsx=50, const int stepsy=50) |
| lineraize2d works with two variables More...
|
|
double | execute (double *varlist=nullptr, ExpressionWrapper *object=nullptr) const |
| calculate formula and return result. variable values need to be set using "setVar()" More...
|
|
bool | executeBool (double *varlist=nullptr, ExpressionWrapper *object=nullptr) const |
|
double | executeLocked () |
| thread safe version More...
|
|
double | calculate (const double Val1=0., const double Val2=0., const bool forceExecution=false) const |
| calculate formula. More...
|
|
bool | calculateBool (const double Val1=0., const double Val2=0., const bool forceExecution=false) const |
|
double | calculate (ExpressionWrapper &object, const double variable_value1=0., const double variable_value2=0.) const |
| calculate formula with object More...
|
|
double | calculateBool (ExpressionWrapper &object, const double variable_value1=0., const double variable_value2=0.) const |
|
void | setVar (const QString &Var, double Value) |
| set the value of the variable named "Var". Note: using addVar to obtain a pointer may be more efficient for multiple executions. More...
|
|
double * | addVar (const QString &VarName) |
| adds variable "VarName" and returns a double pointer to the variable. Use *ptr to set the value (before calling execute()) More...
|
|
double * | getVarAdress (const QString &VarName) |
| retrieve again the value pointer of a variable. More...
|
|
bool | isConstExpression () const |
| returns true if current expression is a constant. More...
|
|
bool | isEmpty () const |
| returns true if expression is empty More...
|
|
const QString & | lastError () const |
|
bool | isStrict () |
| strict property: if true, variables must be named before execution. More...
|
|
void | setStrict (bool str) |
|
void | setCatchExceptions (bool docatch=true) |
|
void | setExternalVarSpace (const QStringList &ExternSpaceNames, double *ExternSpace) |
|
void | enableIncSum () |
|
An expression engine for mathematical expressions provided as strings.
The main purpose is fast execution speed. notes regarding the syntax: +,-,*,/ as expected, additionally "^" for power. mod(x,y): modulo division, gets remainder of x/y functions:
- sin cos tan
- exp ln sqrt
- round
- min max: variable number of arguments, e.g: min(x,y,z)
- if: if(condition, true, false): if condition=true, return true-case, else false-case. note: both (true, false) are evaluated anyway!
- incsum: ?? incremental sum - currently not supported.
- polygon: special function for polygons. polygon(value, x1,y1, x2,y2, x3,y3, ..., xn,yn): return is: y1 if value<x1, yn if value>xn, or the lineraly interpolated numeric y-value.
- sigmoid: returns a sigmoid function. sigmoid(value, type, param1, param2). see udfSigmoid() for details.
- rnd rndg: random functions; rnd(from, to): uniform random number, rndg(mean, stddev): gaussian randomnumber (mean and stddev in percent!)
- in: returns true if the value is in the list of arguments in in(x, a1, a2, a3) The Expression class also supports some logical operations: (logical) True equals to "1", "False" to zero. The precedence rules for parentheses...
- and
- or
- not
- Using Model Variables
- With the help of descendants of ExpressionWrapper values of model objects can be accessed. Example Usage:
Expression basalArea(
"dbh*dbh*3.1415/4", &wrapper);
double sum;
while (
Tree *tree = at.next()) {
sum += basalArea.execute();
}
An expression engine for mathematical expressions provided as strings.
Definition: expression.h:29
static GlobalSettings * instance()
Definition: globalsettings.h:51
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44
Definition: expressionwrapper.h:42
void setTree(const Tree *tree)
Definition: expressionwrapper.h:46
Be careful with multithreading: Now the calculate(double v1, double v2) as well as the calculate(wrapper, v1,v2) are thread safe. execute() accesses the internal variable list and is therefore not thredsafe. A threadsafe version exists (executeLocked()). Special attention is needed when using setVar() or addVar().
void Expression::linearize |
( |
const double |
low_value, |
|
|
const double |
high_value, |
|
|
const int |
steps = 1000 |
|
) |
| |
call linearize() to 'linarize' an expression, i.e. approximate the function by linear interpolation.
Linarize an expression, i.e.
approximate the function by linear interpolation. This is an option for performance critical calculations that include time consuming mathematic functions (e.g. exp()) low_value: linearization start at this value. values below produce an error high_value: upper limit steps: number of steps the function is split into