ABLE 2.0.0 07/02/2003 10:25:01

com.ibm.able.rules
Class AbleForwardChainInferenceEngine

java.lang.Object
  |
  +--com.ibm.able.rules.AbleInferenceEngine
        |
        +--com.ibm.able.rules.AbleForwardChainInferenceEngine
All Implemented Interfaces:
java.io.Serializable

public class AbleForwardChainInferenceEngine
extends AbleInferenceEngine
implements java.io.Serializable

This class provides the inferencing algorithm for processing a set of rules in a ruleblock using data-driven or forward chaining.

The AbleForwardChainInferenceEngine processes AbleAssertionRules and AbleConditionalRules and ignores all others. The control strategy ARL.ControlStrategy parameter can be used to specify several alternative control algorithms. These include:

  1. FIRE_ALL_RULES The default control strategy. Iterate over the rules firing the triggered rule with the highest priority, specficity (number of antecedent clauses), and declaration order until no rules can fire.
  2. FIRE_ONE_RULE
  3. FIRE_N_RULES

The major processing method is infer() which is called by the AbleRuleSet bean as part of the normal bean process() method.

Instances of this class are not directly constructed by the user but are dynamically created by the AbleRuleBlock init() method.

See Also:
AbleRuleSet, AbleRuleBlock, AbleAssertionRule, AbleConditionalRule, Serialized Form

Field Summary
static int FIRE_ALL_RULES
          Control strategy: cycle until no more rules can fire
static int FIRE_N_RULES
          Control strategy: find first N rules to fire, then stop
static int FIRE_ONE_RULE
          Control strategy: find first rule to fire, then stop
protected  int myControlStrategy
          The control strategy used by the engine, one of :
protected  int myNumberOfRulesToFire
          The number of rules to fire when FIRE_N_RULES is the control strategy
 
Fields inherited from class com.ibm.able.rules.AbleInferenceEngine
myDebugLevel, myRuleBlock, myRuleSet, myRulesFiredCount, myTracer, myWorkingMemory
 
Constructor Summary
AbleForwardChainInferenceEngine(AbleRuleSet theRuleSet, AbleLogger theTracer)
          Create a new inference engine.
AbleForwardChainInferenceEngine(AbleRuleSet theRuleSet, AbleLogger theTracer, AbleRuleBlock theRuleBlock)
          Create a new inference engine.
 
Method Summary
 void addRuleToConflictSet(java.util.Vector theConflictSet, AbleRule theRule)
          Inserts the Rule into the conflict set based on priority and specificity.
static java.lang.String Copyright()
          Determine the copyright of this class.
 java.lang.Object getControlParameter(java.lang.String theControlParameter)
          Returns the specified control parameter on the associated inference engine.
 void infer(AbleRuleBlock theRuleBlock)
          Fire the rules in the ruleset using conditional rules and forward chaining inferencing.
 boolean isRuleBlockValid(AbleRuleBlock theRuleBlock)
          Make sure the current ruleblock is "executable" by examining the rule types and rule object configurations.
protected  void logConflictSet(java.util.Vector conflictSet)
          Write the contents of the conflict set (triggered rules) to the Inference trace log.
protected  void reevaluateClausesWithChangedVariable(AbleClauseReferences theClauseReferences)
          Re-evaluate, if necessary, the specified clauses that contain a reference to a variable whose current value has just changed.
 void setControlParameter(java.lang.String theControlParameter, java.lang.Object theValue)
          Set the specified control parameter on the associated inference engine.
 
Methods inherited from class com.ibm.able.rules.AbleInferenceEngine
askUser, conditionalRulesValid, evalAntecedentClause, evalAntecedentExpression, evalAssertionClause, evalAssertionRule, evalConditionalRule, evalConsequentClause, evalDoUntilRule, evalDoWhileRule, evalForLoopRule, evalIfThenElseRule, evalPatternMatchRule, evaluateDoActions, evalWhileDoRule, fireEngineBreakpoint, firePropertyChange, getRuleSet, getRulesFiredCount, getWorkingMemory, init, processAssertions, processConsequent, processRuleBlock, resetRuleSet, setControlParameters, setDebugLevel, setRuleSet, setWorkingMemory, startDebugConsole, stopDebugConsole, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIRE_ALL_RULES

public static final int FIRE_ALL_RULES
Control strategy: cycle until no more rules can fire

FIRE_ONE_RULE

public static final int FIRE_ONE_RULE
Control strategy: find first rule to fire, then stop

FIRE_N_RULES

public static final int FIRE_N_RULES
Control strategy: find first N rules to fire, then stop

myControlStrategy

protected int myControlStrategy
The control strategy used by the engine, one of :

  • FIRE_ALL_RULES (default) fires all rules until none are able to be fired,
  • FIRE_ONE_RULE, fires the first triggered rule encountered
  • FIRE_N_RULES, fires the first N triggered rules encountered

  • myNumberOfRulesToFire

    protected int myNumberOfRulesToFire
    The number of rules to fire when FIRE_N_RULES is the control strategy
    Constructor Detail

    AbleForwardChainInferenceEngine

    public AbleForwardChainInferenceEngine(AbleRuleSet theRuleSet,
                                           AbleLogger theTracer)
    Create a new inference engine.
    Parameters:
    theRuleSet - A ruleset whose rules are to be used for inferencing by this inference engine.

    theTracer - A tracer object to which this inference engine can log information. This may be null, in which case no information is logged.


    AbleForwardChainInferenceEngine

    public AbleForwardChainInferenceEngine(AbleRuleSet theRuleSet,
                                           AbleLogger theTracer,
                                           AbleRuleBlock theRuleBlock)
    Create a new inference engine.
    Parameters:
    theRuleSet - A ruleset whose context is used for inferencing by this inference engine.

    theTracer - A tracer object to which this inference engine can log information. This may be null, in which case no information is logged.

    theRuleBlock - A ruleblock whose rules are to be used for inferencing by this inference engine.

    Method Detail

    isRuleBlockValid

    public boolean isRuleBlockValid(AbleRuleBlock theRuleBlock)
    Make sure the current ruleblock is "executable" by examining the rule types and rule object configurations.

    The ruleblock is invalid if any of the following are present in the ruleblock:

  • IfThenElse rules
  • Predicate rule
  • Iteration rule
  • Pattern match rule

    All reasons for validation failures are appended to the AbleRuleSet's myIsExReason variable. If validation fails, the inference engine must call myRuleSet.addIsExReason(java.lang.String) to append the reason.

    Overrides:
    isRuleBlockValid in class AbleInferenceEngine
    Returns:
    true, if the ruleset is OK; false, if the ruleset is not executable.

  • infer

    public void infer(AbleRuleBlock theRuleBlock)
               throws AbleDataException
    Fire the rules in the ruleset using conditional rules and forward chaining inferencing.

    The infer() method is called by the AbleRuleSet process() method as part of the overall ruleset bean processing sequence.

    The order of processing is as follows:

    1. Sequentially evaluate all assertion rules in declaration order.
    2. Evaluate all enabled conditional rules using forward chaining, using the algorithm specified by the control strategy parameter.
    Overrides:
    infer in class AbleInferenceEngine
    Parameters:
    theRuleBlock - The ruleblock to be processed.

    Throws:
    AbleDataException - When any error occurs.

    reevaluateClausesWithChangedVariable

    protected void reevaluateClausesWithChangedVariable(AbleClauseReferences theClauseReferences)
                                                 throws AbleDataException
    Re-evaluate, if necessary, the specified clauses that contain a reference to a variable whose current value has just changed. This engine processes only antecedent clauses.
    Parameters:
    theClauseReferences - A collection of clauses that reference some variable whose current value has just changed.


    addRuleToConflictSet

    public void addRuleToConflictSet(java.util.Vector theConflictSet,
                                     AbleRule theRule)
                              throws AbleDataException
    Inserts the Rule into the conflict set based on priority and specificity.
    Parameters:
    conflictSet - the Vector to which the rule is added
    theRule - the Rule that needs to be added

    logConflictSet

    protected void logConflictSet(java.util.Vector conflictSet)
    Write the contents of the conflict set (triggered rules) to the Inference trace log. Assumes trace is active.

    setControlParameter

    public void setControlParameter(java.lang.String theControlParameter,
                                    java.lang.Object theValue)
                             throws AbleDataException
    Set the specified control parameter on the associated inference engine.
    Overrides:
    setControlParameter in class AbleInferenceEngine

    getControlParameter

    public java.lang.Object getControlParameter(java.lang.String theControlParameter)
                                         throws AbleDataException
    Returns the specified control parameter on the associated inference engine.
    Overrides:
    getControlParameter in class AbleInferenceEngine

    Copyright

    public static java.lang.String Copyright()
    Determine the copyright of this class.
    Returns:
    A String containing this class's copyright statement.

    ABLE 2.0.0 07/02/2003 10:25:01

    (C) Copyright IBM Corporation 1999, 2003