adamecr / Common.DMN.Engine

DMN Engine is a decision engine (rule engine) allowing to execute and evaluate the decisions defined in a DMN model. Its primary target is to evaluate the decision tables that transform the inputs into the output(s) using the decision rules.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How run all decisions ?

bbrangeo opened this issue · comments

hi,

I would like run all decisions from example simulation.dmn

`using System;
using net.adamec.lib.common.dmn.engine.parser;
using net.adamec.lib.common.dmn.engine.engine.execution.context;
using net.adamec.lib.common.dmn.engine.engine.definition;

namespace ENGINE
{
class Program
{
static void Main(string[] args)
{
string fileName = "simulation.dmn";
var model=DmnParser.Parse13(fileName);
var def= DmnDefinitionFactory.CreateDmnDefinition(model);
//var def = DmnParser.Parse(fileName, DmnParser.DmnVersionEnum.V1_3);
//var ctx = DmnExecutionContextFactory.CreateExecutionContext(def);
var ctx = DmnExecutionContextFactory.CreateExecutionContext(def, configure =>
{
configure.EvaluateTableOutputsInParallel = false;
configure.EvaluateTableRulesInParallel = true;
configure.RecordSnapshots = false;
configure.ParsedExpressionCacheScope = ParsedExpressionCacheScopeEnum.Definition;
});
//var dyna = new { Name = "season", IsOk = true, Direct="Winter" };
//ctx.WithInputParameter("season", dyna);
ctx.WithInputParameter("season", "Winter");
ctx.WithInputParameter("guestCount", 1);
ctx.WithInputParameter("guestsWithChildren", true);

	//var outcome = ctx.ExecuteDecision("Dish");
	var outcome = ctx.ExecuteDecision("Beverages");


	foreach (var result in outcome.Results)
	{
	    foreach (var variable in result.Variables)
	    {
		Console.WriteLine(variable.Name + ": " + variable.Value);
	    }
	}
    Console.WriteLine("Hello World!");
}
}

}`

Thanks for help

Hello Boris @bbrangeo,
it always depends on the concrete DMN model and the goal what do you want to achieve.

I guess you use the simulation.dmn from Camunda simulator. The model contains two decisions - Dish and Beverages with a dependency between them.
So when you execute Dish decision, it will give you a dish output based on the season and number or guests.
However when you execute Beverages decision, it will execute the Dish decision (due to dependency) that will set the dish output and it will use this output together with input guests with children to decide what beverages (second output) to offer/serve. In this case, the "all decisions" are run (and both outputs are set) within the single execution because the model is defined this way, so no need to do anything but execute the Beverages decision.

You can of course iterate through the decisions in the model and execute them, but you need to always understand your model (dependencies) and the real use case and reflect it in you code accordingly - for example whether to execute them within the same context or in separate contexts, whether you need to manage the order of the decisions, how to set the cache, etc.

Hope this help
Radek

Hello Radek

Thank you so much.