Thoughts on DMN Expressions - Gnorion/BizVR GitHub Wiki

Thoughts on DMN Expressions

In a DMN Diagram there is a distinction between a decision table box and an expression box. Decision tables in DMN can set multiple outputs whereas expressions can only set a single output

For example:

image

The decision table named "Determine Classification" uses rules to process average as an input and produces classification as an output

image

The expression box named "Calculate Average Score" uses the expression language to calculate the average of a list of numbers

image

You could also have done this

image

In this example the expression is very simple, but it could be a very complex multi line expression as long as it evaluates to a single value (which can be a single value or a complex structure

Effectively a DMN expression is an assignment for the form average = mean(list_of_scores)

image

How Does BizVR Deal With This

In BizVR there is no distinction. Both forms are modeled as decision tables.

A DMN expression box is essentially a decision table with one unconditional rule and one output variable.

So BizVR does not need to make a distinction between the two forms. Everything in BizVR is a decision table.

In BizVR you can put an expression into any cell in a decision table. Even a very long expression.

But if the expression is particularly long (or the result of the expression needs to be referenced in more than one place) then you can create a separate decision table to set the value of an attribute and just use the attribute name in the decision table.

In BizVR this decision might look like this image

The tables would look like this:

image image

But you could equally well do it with a single table like this (and so can DMN) image

General

I just realized that in BizVR we do not need to have a special type of table that corresponds to the DMN expression box. Everything just gets modeled as a standard decision table. A DMN expression box just becomes a standard BizVR DT (with one unconditional rule that has a single action that sets a single variable)

As long as our expression language for the most part matches up with DMN we should have no problems.

And of course we can put any expression in any cell (except for the output name field in the action - which has to be attribute name or a single RETURN when the DT is a function)

In fact DMN doesn't actually NEED an expression box - you could simply put the expression inside a decision table cell (like we would). But sometimes when the expression is particularly complex (or you need to save the expression results somewhere) then defining it separately make be a bit clearer.

I'm not sure how DMN would deal with the situation where you had two different expression boxes that both set the value of the same variable. Probably both would execute and the last one to execute would win.

FC using Aion would do the same thing. but BC would stop as soon as one of the decision tables had got the value of the variable. But now you may need to give the engine a bit of extra information about which decision table is more important - so it tries that first in BC (and counterintuitively, last in FC)

Performance

While putting that expression (mean(filter(list_of_scores))) as a condition in the table works just fine it will have an impact on performance.

image

Its probably going to be reevaluated for each rule (unless the Aion code gen does some clever optimization) When modeled as separate table we only compute the intermediate variables (like average) only once Both models would execute just fine - but maybe we need to have VV suggest to the user that a decision table that uses expressions in its rule condition may not be the most efficient - the more rules that reevaluate that same condition, the more it will affect performance. The recommendation should be to only use single variable names as the condition. And create a separate table to determine the value of that variable so it can be used in multiple places.