AjRools (1) Rule Engine in C#

Since last year, I was conducting a bit of research about rule engines, specially in Java:


I reviewed JBoss Drools Expert (see http://delicious.com/ajlopez/drools). Past December, I assisted to Buenos Aires JBoss Meetup (see Spanish post)

In the old eighties, I met Rete Algorithm (see The Rete Matching Algorithm, Dr.Dobb’s). After all that, I decide to implement my own rule engine, in C#. You can check my progress at:


This is the current solution:

As usual, it was coded using TDD.

I have facts, that are asserted, like Temperature = 38. And rules, that based on the asserted facts, produce other asserted facts (I plan to add actions, too, beyond fact assertions). A rule example:

# Rules example
# Rule for Child Fever
		Temperature > 38
		Age <= 12
		HasFever is true
# Rule for Adult Fever
		Temperature > 37
		Age > 12
		HasFever is true

I have ideas to extend the rule engine to support objects with properties, not only variables:

	p is_a Patient
	p.Temperature is 39
	p.HasFever is true

but this feature is still in progress. I didn’t adopt the Rete algorithm, yet, or something similar. I want to have a running implementation, with tests. Then, changing internal algorithm is like an exercise on refactoring.

Pending work: more object+properties support, session (client use of the internal implementation), etc.

Keep tuned!

Angel “Java” Lopez



3 thoughts on “AjRools (1) Rule Engine in C#

  1. Will Smith

    Nice! Maybe this can eventually lead to a C# equivalent of drools, but with LINQ an other C# isms.
    Thanks for starting this. Notice that there is a Drools Planner as well. This is equivalent to
    Microsofts Solver Foundation CSP ( http://archive.msdn.microsoft.com/solverfoundation ). I keep hoping
    that Microsoft would try to blend the rules engine that came with WF (but make it RETE) and the Solver.
    Seems like the rules engine has gone no where for years.

  2. Pingback: New Month’s Resolutions: March 2012 « Angel “Java” Lopez on Blog

  3. Pingback: Resoluciones del Nuevo Mes: Marzo 2012 - Angel "Java" Lopez

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s