Svenska Not logged in: Log in | Register

2015-03-28:

Note: Text covers an earlier version.

MRL – MeOS Result Language

Updated: 2015-03-28

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;

Each MRL routine calculates and returns an integer (which may be interpreted as a time in seconds, a score or number of points, or a runner status) based on input data, accessed through a fixed set of defined symbols. The return value is the last evaluated expression in the routine, but to return a specific number you can use the construction

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 Binary Logical Operators

An expression is considered true it is not 0. Unary Operators The operators ++ and -- have two variants, one before and one after the variable. The difference is in how the expression itself is evaluated. If the operator comes first, the result is the expression after the increment/decrement, otherwise the result is the original value.

a = 0;
b = ++a;
c = a++;

The result is that b is 1, c is also 1, and a is 2. Avoid expressions like b = ++a + 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.
}

The else part can be left out, if this case is not needed. You can also select between several case, through the construction:

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.
}

First the statement is executed. Then the loop code is started over and over again as long as is true. After the loop code has been run, the statement is run, just before the next evaluation of .

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;


To post a comment, you need to log in.