|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jeops.AbstractKnowledgeBase
The main class of JEOPS. This class models the knowledge the agent has about the world. In it are stored the facts (objects) and (production) rules that act on the first. This class must be subclassed by a concrete knowledge base so that it is provided with the object and rule base needed for work.
Field Summary | |
private java.util.Vector |
allJoinNodes
All join nodes of the Rete network. |
private ConflictSet |
conflictSet
The conflict set associated with this knowledge base. |
private java.util.Vector |
conflictSetListeners
The set of conflict set listeners. |
private boolean |
debug
Flag indicating whether there is any listener for rule events in this knowledge base. |
protected java.util.Map |
entryPoints
The map that takes class names into the entry points of the Rete network. |
private java.util.Set |
forbiddenClasses
The set of classes whose objects can't be inserted into the Rete network (because there is no compatible entry node). |
private boolean |
isListener
Indicates whether this knowledge base is a listener of its conflict set. |
private int |
numberOfRules
The number of rules in the rule base. |
private ObjectBase |
objectBase
The fact (object) base. |
private AbstractRuleBase |
ruleBase
The (production) rule base. |
private java.util.Vector |
ruleFiringListeners
The set of rule firing listeners. |
Constructor Summary | |
AbstractKnowledgeBase(ConflictSet conflictSet)
Creates a new knowledge base. |
Method Summary | |
void |
addConflictSetListener(RuleFireListener l)
Adds the specified conflict set listener to receive events from this knowledge base. |
private ClassFilterReteNode |
addNewEntryNode(java.lang.Class classType)
Tries to find a way from which a class object may get into some entry point of the Rete network. |
void |
addRuleFireListener(RuleFireListener l)
Adds the specified rule fire listener to receive events from this knowledge base. |
void |
assert(java.lang.Object obj)
Inserts a new object in this knowledge base. |
private void |
createReteEntryPoints(int ruleIndex)
Stores in the entryPoints field all the entry
points for a given rule. |
private void |
createReteNetwork()
Creates the Rete network that will be used in this knowledge base. |
protected abstract AbstractRuleBase |
createRuleBase()
Factory method, used to instantiate the actual rule base. |
private void |
fireElementAddedEvent(ConflictSetEvent e)
Dispatch an element added event to all registered listeners. |
private void |
fireElementRemovedEvent(ConflictSetEvent e)
Dispatch an element removed event to all registered listeners. |
private void |
fireRuleFiredEvent(RuleEvent e)
Dispatch a rule fired event to all registered listeners. |
private void |
fireRuleFiringEvent(RuleEvent e)
Dispatch a rule firing event to all registered listeners. |
void |
flush()
Remove all facts (objects) of the object base. |
private ClassFilterReteNode |
getEntryPoint(java.lang.Class classType)
Returns the entry point of the rete network from where an object of a given class must enter. |
AbstractRuleBase |
getRuleBase()
Returns the (production) rule base of this knowledge base. |
void |
internalElementAdded(InternalConflictSetEvent e)
Invoked when an element is added to the conflict set. |
void |
internalElementRemoved(InternalConflictSetEvent e)
Invoked when an element is removed from the conflict set. |
protected void |
modified(java.lang.Object obj)
Informs this base that an object was modified, so that the rules can be retested against the object. |
void |
newFirableRule(int ruleIndex,
java.lang.Object[] objects)
Receives a message from the Rete network indicating that the given rule and objects should be inserted into the conflict set. |
java.util.Vector |
objects(java.lang.String className)
Returns the objects of a given class. |
void |
removeConflictSetListener(RuleFireListener l)
Removes the specified conflict set listener so that it no longer receives conflict set events from this knowledge base. |
void |
removeRuleFireListener(RuleFireListener l)
Removes the specified rule fire listener so that it no longer receives rule fire events from this knowledge base. |
boolean |
retract(java.lang.Object obj)
Removes a given object from this knowledge base. |
void |
run()
Fires the rules in the rule base with the objects present in the object base, until no rule is fireable anymore. |
private ClassFilterReteNode |
searchInterfaces(java.lang.Class classType,
ClassFilterReteNode classEntryNode)
Searches the interface implementation hierarchy of the given class to see if it can be connected to some entry point of the network. |
void |
setConflictSet(ConflictSet conflictSet)
Defines a conflict set policy for this knowledge base. |
private void |
setRuleBase(AbstractRuleBase ruleBase)
Defines the (production) rule base of this knowledge base. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private ObjectBase objectBase
private AbstractRuleBase ruleBase
private int numberOfRules
private ConflictSet conflictSet
private java.util.Vector ruleFiringListeners
private java.util.Vector conflictSetListeners
private boolean isListener
private boolean debug
protected java.util.Map entryPoints
private java.util.Vector allJoinNodes
private java.util.Set forbiddenClasses
Constructor Detail |
public AbstractKnowledgeBase(ConflictSet conflictSet)
conflictSet
- the conflict set associated with this knowledge base.Method Detail |
protected abstract AbstractRuleBase createRuleBase()
public void addConflictSetListener(RuleFireListener l)
l
- the conflict set listenerprivate ClassFilterReteNode addNewEntryNode(java.lang.Class classType)
classType
- the class object whose hierarchy is to be
analysed to see if it fits into the current Rete
network.null
otherwise.public void addRuleFireListener(RuleFireListener l)
l
- the rule base listenerpublic void assert(java.lang.Object obj)
obj
- the object being inserted.private void createReteEntryPoints(int ruleIndex)
entryPoints
field all the entry
points for a given rule.ruleIndex
- the index of the rule whose entry points will
be created.private void createReteNetwork()
entryPoints
will be filled with the main entry
points of the network.private void fireElementAddedEvent(ConflictSetEvent e)
private void fireElementRemovedEvent(ConflictSetEvent e)
private void fireRuleFiredEvent(RuleEvent e)
private void fireRuleFiringEvent(RuleEvent e)
public void flush()
private ClassFilterReteNode getEntryPoint(java.lang.Class classType)
null
will be returned.classType
- the class object whose entry point is desired.null
if
such entry point doesn't exist and can't even be
created.public AbstractRuleBase getRuleBase()
public void internalElementAdded(InternalConflictSetEvent e)
e
- the conflict set event.public void internalElementRemoved(InternalConflictSetEvent e)
e
- the conflict set event.protected void modified(java.lang.Object obj)
obj
- the object that was modified.public void newFirableRule(int ruleIndex, java.lang.Object[] objects)
ruleIndex
- the index of the firable rule.objects
- the objects that made the rule firable.public java.util.Vector objects(java.lang.String className)
className
- the name of the class.public void removeConflictSetListener(RuleFireListener l)
l
- the conflict set listenerpublic void removeRuleFireListener(RuleFireListener l)
l
- the rule fire listenerpublic boolean retract(java.lang.Object obj)
obj
- the object being removed.true
if the given object belonged to this base;
false
otherwise.public void run()
private ClassFilterReteNode searchInterfaces(java.lang.Class classType, ClassFilterReteNode classEntryNode)
classType
- the class object whose interface implementation
hierarchy is to be analysed to see if it fits into the
current rete network.classEntryNode
- the entry node corresponding to the given
class, if such exists. If it already exists and some
path is found, a new one won't have to be created.null
otherwise.public void setConflictSet(ConflictSet conflictSet)
conflictSet
- the new conflict set that implements its
associated conflict resolution policy.private void setRuleBase(AbstractRuleBase ruleBase)
ruleBase
- the rule base of this knowledge base.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |