[rules-users] Drools Community Clinic Feb 4th 5PM GMT

Dan Seaver dan.seaver at ge.com
Mon Jan 26 14:28:38 EST 2009


I am familiar with both of these rule attributes. However, no-loop doesn't
work in all cases, and lock-on-active needs a fairly fine-grained setup of
activation groups or ruleflow groups in many circumstances. Also,
lock-on-active can not block selective activations, it blocks all
activations. So the activations you don't want to block have to go in a
separate rule that doesn't have lock-on-active set.

I think it would be useful for many in the group to see an example of
appropriate use of these attributes, as well as possible solutions for when
these attributes are inappropriate to use.

Here are two rules that apply:
rule "Rule 1" 
	lock-on-active true
	when
		board : Board (thickness == 1)
		stack : Stack (location == "A")
	then 
		stack.addBoard(board);
		update(stack);
		System.out.format ("Sorted: %s added to Stack %s\n", board, stack);
end

rule "Rule 2"
	salience 1
	no-loop true
	when
		stack : Stack (size > 3)
	then
		stack.setStatus("Overflowing");
		update (stack);
		System.out.format ("Stack %s\n", stack);
		for (Board stackBoard : stack.getBoards()) {
			System.out.format ("%20s\n", stackBoard);
		}
end

I've attached an Eclipse project that contains these rules for anyone that
wants to play around with it.

If no-loop is used with Rule 1 instead of lock-on-active, the rule will go
into an infinite loop. I don't understand why no-loop doesn't work. Any
guidance?

If lock-on-active is used on Rule 1 and Rule 2 (instead of no-loop), Rule 2
is never activated. It's interesting that no-loop works in Rule 2, but not
in Rule 1.

Dan


Mark Proctor wrote:
> 
> see no-loop or the more powerful lock-on-active.
> 
> Mark
> Dan Seaver wrote:
>> Sounds like a very good idea. If you go forward with this, I'd love to
>> see
>> your method for solving the following type of problem:
>>
>> I need to update a particular object without causing the rule to re-fire.
>>
>> Say I have two classes, Stack and Board. I need to choose the Stack to
>> put
>> each Board, so one of these sorting rulles would look like this:
>>
>> when
>>    board : Board (thickness == 1)
>>    stack : Stack (location == "A")
>> then
>>    board.setStack(stack);
>>    update(board);
>> end
>>
>> The problem is the update statement puts the rule back in the Agenda to
>> be
>> fired again, thus an infinite loop. My solution in general has been to
>> use a
>> Collection to track boards that have been processed, but it seems to be
>> alot
>> of overhead. I'm not pleased by my solution.
>>
>> when
>>    board : Board (thickness == 1)
>>    stack : Stack (location == "A")
>>    processed : NamedCollection(name == "BoardsSorted", collection not
>> contains board)
>> then
>>    board.setStack(stack);
>>    update(board);
>>    processed.add(board);
>>    update(processed);
>> end
>>
>> Also, the NamedCollection needs to be created, which I'm doing within the
>> ruleset, which adds a somewhat meaningless to Business Analysts rule.
>> Though
>> I could create the NamedCollection in Java and add it to WorkingMemory
>> prior
>> to firing the rules, I'd like the rulesets to take care of themselves.
>>
>> My actual problem set is laced with many solutions that need to update
>> objects. Even if the object is not directly related to the rule criteria,
>> a
>> map to the object needs to be created in the RHS so the LHS has a
>> reference
>> to the object being updated, thus posing the same problem as above.
>>
>> Your insights would be greatly appreciated.
>>
>>
>> Mark Proctor wrote:
>>   
>>> I'm going to try an informal experiment for the 4th of February at 5PM 
>>> GMT (Date/Time subject to change), we will run an online Drools Clinic 
>>> in the form of a Webinar. So the idea here isn't of a 60 minute 
>>> presentation, but really more of a 60 minute interactive Q&A where we 
>>> will use the desktop to assist in some explanations talking through code 
>>> or examples. What do people think?
>>>
>>> Ideally we would have a set of pre-determined questions, with some adhoc 
>>> ones on the day too. Feel free to start listing your Qs here. I want to 
>>> avoid "What's  WorkingMemory" type questions, but other than that, 
>>> anything is game. Also if anyone has anything cool they would like to 
>>> discuss about how they have used Drools, or just general interesting AI 
>>> ideas, then that's fine too - happy for this just to turn into a fun 
>>> geek chat too.
>>>
>>> Mark
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>>     
>>
>>   
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 
http://www.nabble.com/file/p21671931/tests.zip tests.zip 
-- 
View this message in context: http://www.nabble.com/Drools-Community-Clinic-Feb-4th-5PM-GMT-tp21623144p21671931.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list