1

I am interested in creating rules for Drools Planner. I want that a user can create his own rules in a java app before starting the Drools Planner. Maybe a Drools-rule-file could be generated after the user has added his rules. Would this be possible or do I have to create the rule-file while developing the whole java application?

Many thanks...

Dan Iel
  • 13
  • 2

1 Answers1

0

Yes it's possible. The trick is to build your own RuleBase and set it in the Planner config. See section "5.3.4.2.2. A RuleBase (possibly defined by Guvnor)" in the manual.

You can construct a RuleBase by several, depending on how you want your user to edit his/her rules:

  • From a DRL file. This presumes the user knows DRL. See Drools Expert manual.
  • From a DSL file. This allows you to use natural language.
  • From the guvnor webapp. This allows you to use the tooling Guvnor, such as a guided rule editor, a decision tables spreadsheet, ... You can even use a changeset.
  • From guvnor in eclipse or a standalone app (under development and experimental). There's some work being in this area, but it's still young.
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • PS: in the new knowledge-api, a `RuleBase` has been replaced by a `KnowledgeBase`. You can cast a `KnowledgeBase` to a `RuleBase` as required by Planner 5.4. – Geoffrey De Smet Jun 13 '12 at 16:24
  • Wouldn't it be possible to give a user some facts like "time", "size",... and he builds his rules by himself. And when he's ready a DRL is created based on the selected facts? So the user has not to know DRL only the programmer. So I would have my own "Guvnor webapp". :-) So the rule is not 100% dynamic but the user has a range for creating a rule. – Dan Iel Jun 13 '12 at 22:38
  • Sorry for my bad english. I want a user to offer a subset of components to create his own set for a rule. For example: He could select a name of a teacher, a day, a time-slot and a subject and maybe a priority to differ between soft and hard constraint. – Dan Iel Jun 13 '12 at 22:52
  • @Dan Yes, that would be possible, but you can probably make it even simpler but defining your rules with non-hardcoded variables like "time" and "size". For example: let's say you want to give the user to optionally state which days the nurse wants to have a day off. For each of those days for a certain nurse, a DayOffRequest is created and if any of such instances exist, the dayOff score rule checks if they have been fulfilled. If they don't use DayOffRequests, the score rule has little or no performance impact because ReteOO quickly determines that no facts can match that rule. – Geoffrey De Smet Jun 15 '12 at 06:27
  • very nice idea! Do you have a link to a manual or tutorial which describes this behavior? – Dan Iel Jun 15 '12 at 11:31
  • @Dan See the nurse rostering example source (in zip or github) and look for the class DayOffRequest (java files + usage in DRL) – Geoffrey De Smet Jun 16 '12 at 11:42
  • How to cast to a RuleBase: `((InternalKnowledgeBase) myKnowledgeBase).getRuleBase()` – Geoffrey De Smet Jun 20 '12 at 06:50