Click here to Skip to main content
Click here to Skip to main content

Use Rules In Your Applications

By , 29 Aug 2006
 
Overview of first Use Case

Introduction

This Rules Engine was formulated from my need to provide automation based on external rules. The rules were to govern how the graphical user interface (GUI) behaved in response to Rule execution. De-coupling the rules of the application enabled me to then develop the GUI independently of the Rules and to develop the Rules independently of the application. The connection between the application and the rules is a rules engine whose responsibility is the execution of the rules and notifying the application of changes to variables.

This is the original intent of this Rules Engine, it has since evolved in scope and applicability.

Background

The original intent of this library precluded any notion of ambiguous or non-determinant rule execution. The original need required absolute determination of results since the automation of a GUI cannot resolve ambiguity. I decided to define Rules such that the Rule maker made the decision tree(s).

Rules engines that I have seen (Corticon's offering excepted) are built upon the RETE algorithm. This engine does not utilize the RETE algorithm. RETE can produce non-determinant results which can be disastrous to automation. RETE is better suited to analysis than automation.

This engine has evolved to accommodate various use cases.

Thread-safety is integral to the engine and is implemented using the ReaderWriter lock in .NET. Rule execution based on variable changes is implemented by defining "Triggers". Events for rule execution as well as variable changes are also defined.

Using the Code

The Rules Engine is utilized by instantiating a Rule Engine object from the class. The Rules Engine can then be loaded with Rules.

Instantiating a Rules Engine and adding delegates:

Variable _oVariableEngine = new VariableEngine();
RulesEngine _oRulesEngine = new RulesEngine();
_oRulesEngine.VarEngine = _oVariableEngine;

_oRulesEngine.VariableChanging += 
    new RulesEngine.VariableChangingDelegate(_oRulesEngine_VariableChanging);
_oRulesEngine.VariableChanged +=
    new RulesEngine.VariableChangedDelegate(_oRulesEngine_VariableChanged);
_oRulesEngine.VariableAdded +=
    new RulesEngine.VariableAddedDelegate(_oRulesEngine_VariableAdded);
_oRulesEngine.RuleEntered +=
    new RulesEngine.RuleEnteredDelegate(_oRulesEngine_RuleEntered);
_oRulesEngine.RuleComplete += 
    new RulesEngine.RuleCompleteDelegate(_oRulesEngine_RuleComplete);

Rules can be defined and loaded into the engine from any source. The source code contains a Reader/Writer Visual Studio Solution as well as an XML Schema (with documentation) for using an XML file to define and persist Rules.

Links of Interest

Points of Interest

  • Type-safe collections are implemented by extending CollectionBase and using a binary search algorithm to provide high performance access to any item in the collection.
  • Variables are class objects that have overloaded operators.
  • There is an Interface that allows any object to be used as a variable. Using DataSets as variables are implemented using this methodology
  • The source code contains the complete Visual Studio Solution of Jaxlab Rules Engine, complete Visual Studio Solution for Reader/Writer class, Rule XML Schema and documentation, complete documentation of Rules Engine (HTML and CHM).
  • A Rule can contain Rules to create rule trees to organize rules and rule processing.

History

  • 29th August, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jeff Bramlett
Software Developer (Senior)
United States United States
Member
Website: http://www.somedeveloper.us

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralThe License is LGPL not CPOLmemberCyborgDE11 Jun '11 - 3:38 
The License is LGPL not CPOL !
QuestionHow to match variables plz. help me [modified]memberShyamPrasadP5 Dec '10 - 20:05 
Hi Jeff,
I wrote like
<Variable id="ICU">0</Variable>
<Variable id="TypeofAdmision"></Variable>
<match>(Status = Approved) and (TypeofAdmision != ICU)</match> but this condition not evaluated.
 
how to write a match condition for type not equal to ICU please help me.
shyam.p
modified on Monday, December 6, 2010 2:21 AM

GeneralQuestionmemberchazim12 Nov '10 - 8:20 
Hi Mr. Bramlett,
 
I was searching on the net for a Rules Engine and came across your JaxLabRulesEngine. I must thank you in advance for such greate job. The engine works greate and it is very easy to use.
 
I have a question, I hope you will be able to help me with.
I want to be able to evalute an expression like
 
<Match>(a = 100 OR b > 0) AND (c <> 2)</Match>
<Assign>0.5</Assign>
 
Is this something that can be done with JaxLabRulesEngine? I have tried every thing I can think of without any success. Any help will be greatly appreciated. Thanks.
GeneralRe: QuestionmemberJeff Bramlett12 Nov '10 - 15:03 
Chazim,
 

It has been a while since I have delved into the engine but the I think you can use | for "or" and & for "and" so the expression would be: (a = 100 | b> 0) & (c<> 2)
 
I am "gearing up" to rewrite the engine since generics and vars were not in the framework when I wrote it last time. Any suggestions/comments to put into the new code?
 
I would also be interested to see how people are using the code (just curious Smile | :) ).
 
Jeff
Jeff Bramlett

GeneralRe: Questionmemberterryterryd14 Apr '11 - 2:08 
I'd like to be able to compare the values of string variables.
 
eg.
<Match>Editor != Creator</Match>
At present, my Variable called "Editor" (holding the value "Jim") and my Variable called "Creator" (holding the value "Bob") would be compared (inside the RulesEngine) as "Jim" != "Creator" (which isn't the desired behaviour)
 
If the values in the XML are surrounded by quotes then treat the value literally
eg.
<Match>Editor != "Creator"</Match>    ---   compare Editor ("Jim") to the string "Creator"
If there are no quotes treat the value as it's variable
eg.
<Match>Editor != Creator</Match>    ---   compare  Editor ("Jim") to Creator ("Bob")
 
PS. I am using your rule engine in a Silverlight app. The Rule Engine needed a bit of work to make it Silverlight compatible.
GeneralRe: QuestionmemberJeff Bramlett12 Nov '10 - 15:05 
I am also experimenting with a generic DataBus pattern and the Managed Extensibility Framework to "roll into" the newer version. Could prove interesting!
Jeff Bramlett

QuestionHow to use loopsmemberSumit Prakash Sharma20 Apr '09 - 2:17 
Hi Jeff Sir
 
Thanks for too good Rule Engine
 
I want to use for, while loop in rule base, so pleas tell me the correct systex for looping in rule base
Thanks in advance
QuestionNeed Help !memberrajalakshmiam16 Apr '09 - 23:51 
Hi Jeff,
 
I new to this rule engine , do u have any documentation- to create rules and step by step process.
 
Thanks & Regards
Rajalakshmi
GeneralBroken Linksmemberchris lambrou1 Mar '09 - 19:05 
The links to the www.jaxlab.com web site are broken Smile | :)
GeneralGUI for making new rules and editing the existing onememberBanty Nigam12 Feb '09 - 20:29 
How can I make new rules and edit the existing ones?
 
Plese help me.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 29 Aug 2006
Article Copyright 2006 by Jeff Bramlett
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid