Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request - Decision Tables #37

Closed
arsalans opened this issue Apr 16, 2017 · 4 comments
Closed

Feature request - Decision Tables #37

arsalans opened this issue Apr 16, 2017 · 4 comments

Comments

@arsalans
Copy link

arsalans commented Apr 16, 2017

@CacheControl I was wondering if this rule engine can support decision tables.

What do I mean by that:
So a decision table is composed of many rules that differ usually by one or more conditions. So, for example, I will create a decision table to implement this logic:

Colour - Price
Blue - 10
Red - 11
Green - 13
Yellow - 14
Pink - 8
White - 13
Black - 20

So, you will read it like this, if a color is "Blue" then the price is $10. So instead of creating 7 separate rules, I will only create one rule, a decision table rule. Let me know what do you think.

@CacheControl
Copy link
Owner

@arsalans interesting concept. My understanding of decision trees is that for each permutation of the conditions, there is a defined set of actions. Although it would be easy for the engine to take in a list of conditions and compute a rule per permutation, I'm confused as to how the engine would know the appropriate event to fire in each circumstance. Maybe I just need you to expand on the use case you provided so I can understand the problem you're trying to solve.

@arsalans
Copy link
Author

@CacheControl So, how about if I write my rule like this, and again, I am trying to be as naive as possible:

var decisionTable = 
{
	{
		"color": "Blue",
		"price": 10
	},
	{
		"color": "Red",
		"price": 11
	},
	{
		"color": "Green",
		"price": 13
	},
	{
		"color": "Yellow",
		"price": 14
	}
};
var helper =
{
	"condition": "color",
	"event": "price"
};

new DecisionTable (decisionTable, helper);

So now, the DecisionTable object knows what are the conditions and what are the events to send.

@CacheControl
Copy link
Owner

@arsalans Ah ok, I think I get it now. In json-rules-engine vernacular it's essentially wanting to vary the event based on which condition succeeded.

To me, this almost feels like an accessory package that would act as a rule generator - it would take in the decision tree data structure you posted above, and use it to generate a rule per decisionTable row. json-rules-engine would be responsible for the lower-level execution of the generated rules.

Alternatively, you may want to look at the ruleResult feature just released in 2.0.0 - you can use the ruleResult argument provided in the success/failure events to determine which condition was successful, and use the condition's factResult("yellow", "red", etc) to lookup from a prices hash you maintain outside the engine.

It terms of whether or not this belongs in json-rules-engine itself, right now it feels like something I'd like to keep separate; I want to keep json-rules-engine as the low level executor of basic boolean logic + firing events, while more complex rule orchestrations such as decisionTables are probably better suited as plugins/extensions.

@CacheControl
Copy link
Owner

Here's the ruleResult docs I mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants