[rules-users] Best (better) practices question

Mike Dean mdean77 at comcast.net
Fri Nov 28 18:47:31 EST 2008


I am working on an application that tells how much insulin should be given to
a patient with different glucose values.  I have a decision object that
contains the current value of glucose and the rules alter the decision
object to include advice or explanations.

Since the decision object is modified, I have to have some kind of state
object so that rules do not loop;  I have created a state object that has a
series of boolean fields which are checked.  However, this feels like I am
circumventing the whole idea of an inference engine.  So I have made an
alternative helper class that contains inner classes that can be inserted as
facts.

Here is a sample rule with the first method:
[code]
rule "Detect mild hypoglycemia"	
	when
		decision : GlucoseDecision( serumGlucoseConcentration < 80, 
									serumGlucoseConcentration >= 60 )
		decisionState : GlucoseDecisionState(currentGlucoseBelowRange == true,
mildHypoglycemia == false)
	then
		decisionState.setMildHypoglycemia(true); 
		decision.explain("The patient has mild hypoglycemia (serum glucose is " + 
				decision.getSerumGlucoseConcentration() +" mg/dL).");
end
[/code]

Here is the same rule using the second approach:
[code]
rule "Detect mild hypoglycemia"	
	when
		decision : GlucoseDecision( serumGlucoseConcentration < 80, 
									serumGlucoseConcentration >= 60 )
		currentGlucoseBelowRange()
		not(mildHypoglycemia())
	then
		insert(new mildHypoglycemia());
		decision.explain("The patient has mild hypoglycemia (serum glucose is " + 
				decision.getSerumGlucoseConcentration() +" mg/dL).");
end
[/code]

My question is whether one or the other of these approaches is a better
practice?  Using facts would make my rules trace more sensible, I think, but
perhaps it is much less efficient.  Comments are appreciated.  Thank you.

- Mike
-- 
View this message in context: http://www.nabble.com/Best-%28better%29-practices-question-tp20742140p20742140.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list