[rules-users] Infinte Loop problem

Mark Proctor mproctor at codehaus.org
Wed Dec 5 08:50:27 EST 2007


benjimcc wrote:
> Im sure people have seen this before ive searched high and low for an answer
> but no luck, fairly new to using drools so any advice would be much
> appreciated.  Here is a sample of my rules:
>
> rule "Gender Desirability"
> 	salience 400
> 	no-loop true
> 	when
> 		$broker : Broker(brokerName=="bah")
> 		Proposer(gender == "F")
> 	then
> 		int desirability = $broker.getDesirability() + 10;
> 		$broker.setDesirability(desirability);	
> 		update($broker);
> 		System.out.println("Gender Hit");
> end
>
>
> rule "Age Desirability"
> 	salience 200
> 	no-loop true
> 	when
> 		$broker : Broker(brokerName=="bah")
> 		$proposer : Proposer($dob : dateOfBirth)
> 		$rulesrequest : RulesEngineRequest($inception : inceptionDate)
> 	
> eval(age_desirability_flex.isInRange($proposer.getAge($dob,$inception))==true)
> 	then
> 		int desirability = $broker.getDesirability() + 20;	
> 		$broker.setDesirability(desirability);
> 		update($broker);		
> 		System.out.println("Age Hit");	
> end
>
> rule "Check Desirability"
> 	salience 190
> 	when
> 		$broker : Broker($des : desirability,brokerName=="europa")
> 		eval($des < desirability_Index)
> 	then
> 		$broker.setInclude(false);
> 		retract($broker);
> end
>
>
>
> Ok basically all the 'when' bits work.  But what seems to happen is that
> when the update happens and the rules are evaled again and it ping pongs
> between the two rules as they both update the Broker object.  Resulting in
> the 'Check Desirability' never being hit and for debug spewing 'Gender Hit'
> 'Age Hit' in a infinite loop till te JVM runs out of memory and it crash and
> burns.
>   
checkout the attribute lock-on-active. You'll need to put the rules into 
an angenda-group or ruleflow-group, but what this means is  it'll fire 
just the current activated rules and while that group has the focus no 
more rules for those  groups can activate - thus stopping the ping pong 
effect. See the conways game of life example to see this  in  action.
> Any help in this would be much appreciated.  If you need any more
> information let me know as well.
>
> Thanks
> Ben
>
> "The views opinions and judgments expressed in this message are solely those
> of the author.  The message contents have not been viewed or reviewed or
> approved by CDL"
>   




More information about the rules-users mailing list