Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What pattern/patterns work best for developing rule/decision engine [closed]

I am working on a decision engine / rule evaluation engine. For example:

Input: Customer and all the offences done by the customer

Output: Consequences of the offences

A sample case would be:

Input: Customer(Jhonny Chimpo, 999-00-1111), Offences ( Broke window, slapped boss, kicked team lead in his groin)

Output: Gets pink slip

So the piece of code I want to write evaluates different offences based on rules for each offence and combined offence. The current code is just a maze of if and else statements. I am sure such business problems are common. What design/enterprise pattern is usually used to solve a problem like this?

Is it the specification pattern? I want the code to be open for extension, clean and flexible.

like image 942
Perpetualcoder Avatar asked Jan 24 '10 10:01

Perpetualcoder


People also ask

What is a rules engine design pattern?

One of the popular design patterns to help developers follow OCP is the Rule Engine design pattern. It is an efficient design pattern to develop software applications with multiple and complex business rules processing the same entity. Business rules could be correlated and complex.


2 Answers

Basically business rules look like

forall rules:
  if <condition> then doAction();

What about categorizing all offences by severity using scores, perhaps extra bonus for frequent "evil-doers", some offences may become time-barred and whatever required.

Then a rough draft of an algorithm could be:

  • Sum of all scores of a customer (weighted)
  • compare to maximum

This would be straight forward using data structures instead of many (possibly deeply nested) if..then..else things.

like image 164
stacker Avatar answered Oct 10 '22 17:10

stacker


I can suggest you a tool we used to solve a similar problem.

Take a look at JBoss Drools: http://www.jboss.org/drools/

It's a BRMS: Business Rules Management System

Here it is an introductory video: http://www.jboss.com/products/platforms/brms/

like image 37
Andrea Zilio Avatar answered Oct 10 '22 18:10

Andrea Zilio