ABLE 2.3.0 07/13/2005 14:21:00

com.ibm.able.rules
Class AblePredicateLib

java.lang.Object
  extended bycom.ibm.able.rules.AblePredicateLib
All Implemented Interfaces:
java.io.Serializable

public class AblePredicateLib
extends java.lang.Object
implements java.io.Serializable

This class implements an alternate math library that takes/returns AbleDoubleLiterals as arguments and defines: plus, minus, times, divideBy for use by Predicate engine.

This class provides a library of mathematical user-defined functions that can be imported into an Able ruleset with an Import() statement. Each public method in this class can then be used as a user-defined function.

See Also:
Serialized Form

Field Summary
protected  AbleWorkingMemory myWm
           
 
Constructor Summary
AblePredicateLib()
          Create a new math library of user-defined function routines.
 
Method Summary
 boolean assertFact(java.lang.Object fact)
           
 AbleDoubleLiteral divideBy(java.lang.Object theNumberA, java.lang.Object theNumberB)
          Divide A by B and return the result.
static boolean getAnswer(AbleRuleSet theRuleSet)
          Return the answer.
static java.util.Vector getGroundSolution(AbleRuleSet theRuleSet, java.lang.String theRuleBlockKey, int theIndex)
          Return the solution at the specified index in the solutionList.
static java.util.Vector getSolution(AbleRuleSet theRuleSet, java.lang.String theRuleBlockKey, int theIndex)
          Return the solution at the specified index in the solutionList.
static java.util.Vector getSolutionList(AbleRuleSet theRuleSet, java.lang.String theRuleBlockKey)
          Return the solutionList.
 AbleDoubleLiteral minus(java.lang.Object theNumberA, java.lang.Object theNumberB)
          Subtract B from A and return the result.
 AbleDoubleLiteral plus(java.lang.Object theNumberA, java.lang.Object theNumberB)
          Add two numbers and return the result.
 boolean retractFact(java.lang.Object fact)
           
 void setPredicateWorkingMemory(AbleWorkingMemory wm)
           
 AbleDoubleLiteral times(java.lang.Object theNumberA, java.lang.Object theNumberB)
          Multiply B by A and return the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myWm

protected AbleWorkingMemory myWm
Constructor Detail

AblePredicateLib

public AblePredicateLib()
Create a new math library of user-defined function routines.

Method Detail

plus

public AbleDoubleLiteral plus(java.lang.Object theNumberA,
                              java.lang.Object theNumberB)
                       throws AbleDataException
Add two numbers and return the result.

Parameters:
theNumberA - A number.

theNumberB - A number.

Returns:
the sum of the two numbers.
Throws:
AbleDataException

minus

public AbleDoubleLiteral minus(java.lang.Object theNumberA,
                               java.lang.Object theNumberB)
                        throws AbleDataException
Subtract B from A and return the result.

Parameters:
theNumberA - A number.

theNumberB - A number.

Returns:
the result of the subtraction.
Throws:
AbleDataException

times

public AbleDoubleLiteral times(java.lang.Object theNumberA,
                               java.lang.Object theNumberB)
                        throws AbleDataException
Multiply B by A and return the result.

Parameters:
theNumberA - A number.

theNumberB - A number.

Returns:
the product of the two numbers.
Throws:
AbleDataException

divideBy

public AbleDoubleLiteral divideBy(java.lang.Object theNumberA,
                                  java.lang.Object theNumberB)
                           throws AbleDataException
Divide A by B and return the result.

Parameters:
theNumberA - The dividend number.

theNumberB - The divisor number.

Returns:
the result of the division. If theNumberB is zero, return NaN.
Throws:
AbleDataException

getSolutionList

public static java.util.Vector getSolutionList(AbleRuleSet theRuleSet,
                                               java.lang.String theRuleBlockKey)
                                        throws AbleException
Return the solutionList.

Parameters:
theRuleSet -

Returns:
A Vector containing the solution(s). If no solution, zero elements will be returned.
Throws:
AbleException

getSolution

public static java.util.Vector getSolution(AbleRuleSet theRuleSet,
                                           java.lang.String theRuleBlockKey,
                                           int theIndex)
                                    throws AbleException
Return the solution at the specified index in the solutionList. This is a Vector of predicates with variables bound with the results.

Parameters:
theRuleSet -

theRuleBlockKey - The key of the ruleblock
theIndex - The index of the element in the solutionList to return
Returns:
A Vector containing the solution. If no solution, an empty Vector will be returned.
Throws:
AbleException

getGroundSolution

public static java.util.Vector getGroundSolution(AbleRuleSet theRuleSet,
                                                 java.lang.String theRuleBlockKey,
                                                 int theIndex)
                                          throws AbleException
Return the solution at the specified index in the solutionList. This is a Vector of predicates with all variables removed (i.e. ground Predicates)

Parameters:
theRuleSet -

theRuleBlockKey - The key of the ruleblock
theIndex - The index of the element in the solutionList to return
Returns:
A Vector containing the solution. If no solution, an empty Vector will be returned.
Throws:
AbleException

getAnswer

public static boolean getAnswer(AbleRuleSet theRuleSet)
                         throws AbleException
Return the answer.

Returns:
True if the solution Vector contains at least one solution.
Throws:
AbleException

setPredicateWorkingMemory

public void setPredicateWorkingMemory(AbleWorkingMemory wm)

assertFact

public boolean assertFact(java.lang.Object fact)

retractFact

public boolean retractFact(java.lang.Object fact)

ABLE 2.3.0 07/13/2005 14:21:00

(C) Copyright IBM Corporation 1999, 2005