Tuesday, August 25, 2009

Possible London Drools Boot Camp for October

The San Francisco Boot Camp was a great success, with a fantastic turnout. If I got enough names I could be tempted to do a London based event at the JBoss offices, probably in October. I would probably aim for this event to be just a 1 or 2 day event, dependant on the requests I receive. If you are interested, send me an email - mproctor at redhat d0t com.

The main idea would be to get 15 to 20 like minded people together for a day or two, where we can just discuss each others problems and we in the Drools team can help you deep dive into the Drools code.

Drools Community Figures

Thought I'd pass on some updates on community figures - as we have no web pages that report this information.

mailing list subscribers
921 rules users
315 rules dev

1150 subscribers (feedburner)
400 to 600 unique page views (eWebCounter, does not include syndication stats)

The download stats page is broken at the moment, so I can't give any download attempt figures :(

Sunday, August 23, 2009

Some articles from Java Beans dot Asia

Java Beans dot Asia is building up a nice set of Drools articles, so I thought I'd list them here, quoting opening paragraph from each article. I notice a few could do with updating to Drools 5.0, so I'm looking forward to the updates - keep up the good work.

Drools - writing DSL for DRL rule
"One of the blog readers, who posted a comment in my previous post Drools - tutorial on writing DSL template asked to me to help him with creating DSL for the following rule, so I decided to use his example as a small case study:"

Brainteaser Drools: Testing Objects
Which of the two rules does valid comparison of the two Customer instances?
Which of the two rules is invalid? Why?

Drools - tutorial on writing DSL template
Few months ago I wrote a post that describes an example that uses source DRL in conjunction with DSL template. In the current post, I want to describe and show with few examples how to write DSL template - whats allowed and whats not.

Drools - Stop executing current agenda group and all rules
Sometimes, depends on your business rules in your application, there is a need to stop current agenda group or all rules from continuing to execute. It wont help setting a focus to another agenda group, since previous agenda will still remain in a stack. So in this post I want to show how to prevent rules in a particular agenda group from continuing to execute by clearing the agenda and also how to stop all rules totally.

Drools - working with Stateless session
Drools (now it is also called JBoss Rules) is an amazing open source framework which allows you to create business rules management system for your application. I got introduced to Drools while working on a project at my current company.

Saturday, August 22, 2009

NExpert Review (MacTech)

A while back James Owen did a blog on "full opportunistic backward chaining". I've since found this old NExpert Object article, entitled "PROGRAMMING IN NEXPERT" that gives quite a nice overview including an explanation of NOTKNOWN and UKNOWN for opportunistic backward chaining in NEXPERT.


NEXPERT has two basic values that any datum may have: NOTKNOWN and UNKNOWN. NEXPERT uses UNKNOWN as the "reset" value. Whenever a datum's value is needed and it is currently UNKNOWN, then NEXPERT will switch to backward chaining to attempt to establish a value from the data already available. If this is unsuccessful then the user is queried, via the Question Window, for a value. NOTKNOWN on the other hand, is used to mean that the user has been questioned and does not know the answer. NOTKNOWN allows default reasoning to be done and prevents NEXPERT from continuing to ask for a value that the user does not know.
Once the system reaches a rule that has some UNKNOWN datum in it, the user will be prompted for a value (see the example in Figure 3 below). At this point the user can access the multi-level Explanation Facility (via the WHY? and HOW? Buttons ), which is automatically built from the static forward and backward chains already in the rule-base."

Thursday, August 20, 2009

Drools 5.0 and business process modeling flexibility (Kau)

Great to see people spreading the word on knowledge centric apis for declarative behavioural modelling :)

Drools 5.0 and business process modeling flexibility (Kau)
"Now it is possible to implement the business logic without being restricted to rule-centric or process-centric modeling approach. Therefore from the design point of view the users can practice the best applicable approach to design different parts of the business logic."
"Moreover the processes, events and rules (Condition, Actions) are all now part of one knowledge base. Thus it is easy to manage the state, share context of a particular process instance. Consequently the process instances can deviate from the pre-defined execution path, for example to handle an exception."

Friday, August 14, 2009

Drools Fusion official recognised as a CEP market player

Just saw this blog from paul vincent, which shows Drools official recognised as a CEP market player. Here is a reproduction of the image from that article:

Monday, August 10, 2009

Drools Flow videos

We've been preparing various presentations recently, and because not all of you can join us at a local event, I decided to create a few recordings and put these online. These videos range from showing how to get started by creating your first Drools BPMN 2.0 process to showing some of the more advanced features of Drools Flow, like the rule integration, the pluggable work items and the web-based management console.

Enjoy !
Kris Verlaenen

Hello World

A simple video that shows how to create and execute your first Drools Flow process using the Drools Eclipse plugin. It assumes you have the plugin installed correctly. You will learn how to create a Drools project, containing a sample BPMN2 process, and how to execute this process.

- BPMN 2.0


This example continues where the Hello World example left off and shows how to create a simple but real example for evaluating employees. The process first requires the user to perform a self-evaluation, after which the HR manager and the PM manager will be required to perform an evaluation as well. The video shows how to create the BPMN2 process, i.e. create all the nodes and fill in all the necessary properties. Next, the process will be executed in debug mode to simulate its behaviour, using the task client in Eclipse.

- BPMN 2.0
- Human tasks
- Debug
- Audit


Once the the evaluation process has been completed and uploaded to Guvnor, it can also be executed using the web management console. This video shows how to start a new evaluation process and how the various users can execute the requested tasks using custom task forms. It also shows how a user can get an overview of all currently running process instances (and their state), and how reports can be generated to monitor the overall activity of your business processes.

- Process instance management
- Process instance overview (control flow + data)
- Human tasks + custom task forms
- Reporting


This examples shows another real example of a business process that is used to handle sales orders. It shows some more advanced features, like rule integration for validation and discounts, timers for timeouts, etc. It also shows how breakpoints and the various debug views can be used to figure out what's going on at runtime.

- Rule integration
- Debug
- Audit

Order CEP

This extension to the Order example shows how events generated by the process during execution could be fed back into the engine itself to monitor your processes. It shows how a very simple CEP rule can then for example show a warning message if more than 5 instances of this process have been started in the last hour, but much more advanced CEP rules could really intervene and dynamically alter the business logic when problems occur.

- CEP rule integration


This example shows how pluggable work items can be used to easily integrate with external services. In this case, the process manages the registration of events in a calendar system (using Google Calendar in this case), and how feedback can be provided to the end user (using email) when problems occur. It shows some more advanced features, like rule integration for validation, for each, etc.

- Pluggable work items (email, google calendar)
- Rule integration
- Timers
- For each

Friday, August 07, 2009

Do you love to play Magic The Gathering? (Renton, WA) (Job Posting)

This came up in my google alerts today, and applying Drools to computer games is something I've always wanted to see happen :) If anyone gets the contract, you can be sure the Drools team will be available to you for direct free mentoring - actually I insist on it :)

Do you love to play Magic The Gathering? (Renton, WA)


Date: 2009-08-06, 4:44PM PDT
Reply to: job-vtfwu-1309824161@craigslist.org [Errors when replying to ads?]

Do you love to play Magic The Gathering and have experience with technology?

We are looking for a consultant to provide an initial assessment of the applicability of rules and constraint based programming to the on-line version of the game Magic: The Gathering.

The initial engagement is for one to two weeks and the bulk of the work can be done remotely with flexible hours.

Mandatory qualifications are as follows:

1. At least 3 years of Magic: The Gathering play experience.

2. Active user of Magic: The Gathering Online

3. A Pro Tour Level Player or certified Magic Judge

4. At least 3 years of rule based programming experience in at least two of the following tools:
a)Eclipse Rules/ Oracle Policy Automation
d)Corticon Rules
e)BizTalk Rules
f)JBoss Rules
g)Art Enterprise
h)OPS 83
i)ILog/IBM Rules

5. A theoretical understanding of the Rete algorithm and other rule processing optimizations

6. Experience with all of the following:
a)Natural or domain language rule expression
b)Programming language rule expression
c)Visual rule editing and diagramming

Most of the work can be done remotely, however some on-site meetings will be required. Estimate of 20-80 hours of total work over two weeks, could be an on-going need if you like the work

If you are interested in applying, please send me your current word.doc resume and let me know a good time to give you a call.

* Location: Renton, WA
* Compensation: Competitive
* Telecommuting is ok.
* This is a part-time job.
* This is a contract job.
* Principals only. Recruiters, please don't contact this job poster.
* Please, no phone calls about this job!
* Please do not contact job poster about other services, products or commercial interests.

PostingID: 1309824161

Real time chat...

And now for something completely different...

A recent feature request was for a discussion/comment feature for files in Guvnor:

The comments are below the "documentation" section (and of course optional) (and there is an Atom feed to them).

An interesting addition was using a "backchannel" type connection that is kept open from the browser to allow messages to push back - this means (when enabled) that messages show up in real time (and other handy things like if something is added to a list - the list is updated).

There are a few ways of doing this in a browser - but it all boils down to the same idea: opening a connection which "waits" on the server - the server can then "push" response messages back down this pipe (whence the client reconnects, waiting more). This type of thing is becoming more and more popular in "real time" features of websites, interestingly (but it is quite an old idea).

Here is a video which shows at the end 2 browsers, and the second one being updated in "real time" ** by the first one.

Enjoy !

** Yes this is not really "real time" but the term seems to have caught on due to things like Facebook, Google Wave etc...

Loop detection ideas...

A common problem with writing systems in rules, is when you are mutating data (modifying working memory in any way) it is possible to have rules activate themselves over and over, and cause a non terminating loop (also known as an Infinite Loop ;).

Now we all know we can't know for sure (yet) that ANY program will terminate - but still, its troubling to have run away processes etc...

So to stop the simple case of a rule directly activating itself, we of course have the "no-loop" attribute: this instructs the engine to not let that same rule be activated as a result of its consequence. Of course this only works for simple cases: its possible for ruleA to triggle ruleB, and then back to ruleA and so on (or even more complex patterns).

In unit tests - its usually easy to spot non terminating cases, and its not that troubling as they are obvious. Buried in an app this is more troubling however.

In many cases the results of this looping is mostly harmless - you would rather it just get over itself and return something right ?!

There are a few ways to help with this issue:

1. Set a max fires value when executing - this pretty much ensures it will finish (this also assumes that you know what a reasonable upper limit is for the number of rule firings - not always the case).

2. Avoid modifying an existing fact (well - not always helpful to say this - its a bit like a doctor saying "don't go and get the flu !").

3. Cycle detection:
Well if you were to note down all the names of the rules firing, you would notice that a cycle forms (a repeating pattern) which may or may not be obvious to the eye. You could perhaps decide after a certain amount of time that you will just stop and say "enough is enough ! I think you are going in circles").

There are a few algorithms for detecting these cycles, such as the Tortoise and Hare:
(which I like because it has a cute diagram):

The basic idea is that the main phase of the algorithm is where the hare moves twice as fast as the tortoise, once they both sit on the same value, they have the potential start of a cycle/loop (and if they move in sync after, they can find out the length of a potential cycle - you can read more on the Wikipedia link above).

Now all this isn't really necessary for what we want. If we were to look the names of the rules executing in sequence, at a given point in time we can take a look at that list, and see if it ends in in a cycle/loop. Unlike the above, we aren't concerned with finding any cycle - but only one that starts at the end. If the cycle is repeated enough, then we could say it *might* be stuck in a loop (the cycle might be 1 rule firing over and over, or a sequence of rules that fire over and over...).

So a rough algorithm might be to flip the list of firings around, and anchor the "tortoise" to the start, and then look for a potential repetition, check if it is a repetition, if it is, check its length. We can then decide if the repetition carries on for long enough, to terminate (this can be done by Listener implementations).

To try this out, I wrote the following (Scala) code, and applied it as a Listener. Every 1000 or so firings I would check the log, and see if a cycle had formed. If it was, and it was a certain number of iterations (but could be variable in size) I would return:

* Take a list, return a list of the pattern that is repeated, and the total number of items that are
* detected to be in a repeated pattern. Loosely based on the tortoise and hare algorithm, only in this case
* I break the tortoise legs as I don't want him to leave the start line.
def locateLoop(list: java.util.List[String]) : (Array[String], Int) = {
var i = 1;

val endVal = inv(list,0)
var pattern = Array(endVal)
var cycleSuspected = false
var confirmed = false
var cycleY = 0
var cycleX = 0
while (i < list.size - 1 && !confirmed) {
val v = inv(list, i)
if (v == endVal) {
cycleSuspected = true
cycleX = 0
cycleY = i
var repeatingItems = Array(endVal)
while (cycleSuspected) {
cycleX = cycleX + 1
cycleY = cycleY + 1
if (cycleY < list.size) {
if (inv(list,cycleX) != inv(list,cycleY)) {
if (cycleX >= i) {
pattern = repeatingItems
// println("Terminated With Loop Found")
cycleSuspected = false
} else {
// println(list(cycleX - 1))
if (cycleX == i) {
confirmed = true
// println("Found !")
if (!confirmed) {
repeatingItems = repeatingItems ++ Array(inv(list,cycleX))
} else {
pattern = repeatingItems
cycleSuspected = false
i = i + 1

(pattern.reverse, cycleY) //this is the return value - the pattern plus size !


def inv(a: java.util.List[String], i: Int) = {
a.get(a.size - i - 1)

Certainly seemed to work well. There are many cases where a deep recursion does occur, where this might detect false positives - so its not a general solution, BUT, for many business rules scenarios (for example executing on a web server as the result of a request) it can work as a safeguard quite nicely (in other words, another optional tool).

Some other suggestions I have had were to look at the cached hashcodes of the tuples causing the activations - the idea being that if there is looping AND no data mutation - then the looping is clearly useless and should be stopped. I also tried this, but it can't really work with the hashcodes as hashcodes do NOT have to change as a result of data mutation. (Sadly, this means that deep-ish copies would need to be made of the data to watch for mutation - a cumbersome and expensive option and still not fool proof).

Good times....

Thursday, August 06, 2009

My Drools 5.0 Notes (hairy bumblebee)

My Drools 5.0 Notes - http://howto-notes.blogspot.com/2009/08/my-drools-50-notes.html

My Drools 5.0 Notes (hairy bumblebee)

My Drools 5.0 Notes - http://howto-notes.blogspot.com/2009/08/my-drools-50-notes.html

Tuesday, August 04, 2009

Assigning hospital beds to patients with drools-solver

I've implemented a new example in drools-solver: patient admission scheduling. In this problem, we have to assign each patient (that will come to the hospital) a bed for each night that the patient will stay in the hospital. The problem is defined on this webpage by the Kaho Sint-Lieven IT research group and the test data comes from real world hospitals.

Each bed belongs to a room and each room belongs to a department. The arrival and departure dates of the patients is fixed: only a bed needs to be assigned for each night.

There are a couple of hard constraints:
  • 2 patients shouldn't be assigned to the same bed in the same night (not even if they are married :).
  • A room can have a gender limitation: only females, only males, the same gender in the same night or no gender limitation at all.
  • A departement can have a minimum or maximum age.
  • A patient can require a room with specific equipment(s).
And of course, there are also some soft constraints:
  • A patient can prefer a maximum room size, for example if he/she want a single room.
  • A patient is best assigned to a department that specializes in his/her problem.
  • A patient is best assigned to a room that specializes in his/her problem.
  • A patient can prefer a room with specific equipment(s).

Drools-solver solves this planning problem. Here's a screenshot of a result:

Sunday, August 02, 2009

Drools Performance: Waltz (Illation.com.au)

Steven, over at Illation, has run some drools 4 vs 5 on the waltz benchmark. As always take these things with a large pinch of salt :)