Note: Text covers an earlier version. |
MRL – MeOS Result Language
MRL (MeOS Result Language) is a programming language used to describe result calculations. To create custom result calculation rules, some basic programming skill is required. If you have write any program fragment in Java, PHP, C++, C# r a similar language, you probably possess all necessary skills.The Fundamentals
A MRL routine consists of a sequence if statements, separated by semicolon (;). We recommend formatting the code with one statement per line. It is allowed to exclude the semicolon in the last statement of the routine.Comments in the code can be given by typing // on a row. The rest of this row is ignored. Example:
if (Status != StatusOK)
return 10000; // Return a number higher than any valid time.
else
return ComputedTime;
return <value>;
as in the example above.Symbols
Each MRL routine defines a number of symbols, for example Status, Time, course Course, which for every run of the routine is setup with data for the competitor or team under consideration.A symbol can be a scalar (e.g. Time containing the running time for the team or runner), a vector (e.g. Course, which holds the course of a competitor), or a matrix (e.g. RunnerCourse, which holds the courses for each member of the team.).
Vector and matrix symbols are index from 0 using square brackets: Course[2] refers the the third control, RunnerCourse[2][0] refers to the first control for the third competitor in a team.
To get the size of a vector or matrix, use the syntax Course.size() and RunnerCourse[2].size(); (Number of controls for the third member of the team). Example: A status calculation, where a time between controls over 3 minutes means disqualification.
if (Status == StatusOK) {
for (i = 0; i < SplitTimes.size(); i++) {
if (SplitTimes[i] > 60*3)
return StatusDQ; // Disqualified if split time over 3 minutes
}
}
return Status;
Variables
Variables work in a manner similar to symbols, but you define them in the code by assigning values. A variable can hold an integer or a vector of integers. In the example above i is a variable.A vector variable can be constructed by assigning values for specific indices. The vector grows automatically, and is filled with zeros where no number has been assigned. If you type var[3] = 4 (and var was not defined earlier), var becomes a vector with contents [0,0,0,4].
You can also create a vector variable by assigning all values at once. This will happen if you write var = where name is the name of a vector symbol, for example RunnerCourse[0], the course for the first member of a team (RunnerCourse is a matrix) or a vector variable.
You can sort a vector variable by typing
var.sort()
. The following code fragment returns the code for the fastest team member:times = RunnerTimes;
times.sort();
return times[0];
Operators
MRL evaluates the most common arithmetic and logical operators. Any logic operator is evaluated to 1 of the expression is true and to 0 if the expression is false. The usual rules for operator precedence applies, use parentheses if necessary.Binary Arithmetic Operators
- +: Addition (a+b)
- -: Subtraction (a-b)
- *: Multiplication (a*b)
- /: Division (a/b)
- %: Remainder after integer division (a%b)
- max: Greatest value (max(a,b))
- min: Smallest value (min(a,b))
An expression is considered true it is not 0.
- ==: Equals (a == b)
- !=: Different from (a != b)
- <: Less than (a < b)
- >: Greater than (a > b)
- <=: Less than or equal (a <= b)
- >=: Greater than or equal (a >= b)
- &&: And, both true (a && b)
- ||: Or, at least one true (a || b)
- !: Not (!a), true if and only if a is false
- -: Minus (-a)
- ++: Increment value by 1 (++a or a++)
- --: Decrement value by 1 (--a or a--)
a = 0;
b = ++a;
c = a++;
Flow Control
If/else statements To make different calculations depending on the evaluation of a logical expression, you can use an if/else statement. The construction is:if () {
//Code to run if is true.
} else {
//Code to run if is false.
}
if () {
//Code to run if is true
} else if( {
//Code to run if false and is true
} ... {
} else {
//Code to run if no expression was true.
}
For Loops A for loop is used to repeat a calculation a certain number of times. The construction is:
for (; ; ) {
// Code to run.
}
The following example return status OK if all members of a team are OK.
for(i = 0; i < RunnerStatus.size(); i++) {
if (RunnerStatus[i] != StatusOK)
return RunnerStatus[i];
}
return StatusOK;
While Loops A while loop is an alternative to a for loop, which is simpler since there is not start and update condition, The loop code is started as long as the condition is true:
while () {
// Code to run
}
Break A break statement is used inside a loop to abort the run, regardless of the condition of the loop. Typically, it is placed inside an if statement. Example, computing a score based on the number of legs in a row (from start) that you have completed under 60 seconds:
i=0;
while (++i < CardTimes.size()) {
if (CardTimes[i] - CardTimes[i-1] > 60)
break;
}
return i-i;