org.cfpm.caves.za
Class DisposalPolicy

java.lang.Object
  extended by org.cfpm.caves.za.DisposalPolicy
Direct Known Subclasses:
EndorsementDisposalPolicy

public class DisposalPolicy
extends java.lang.Object

This class provides functionality to remove facts from the Jess fact base. It keeps track of of which type of fact can be removed after how many ticks. To be able to be removed with a disposal policy, a fact needs to possess a slot with a time stamp, denoting its assertion time. The modeller can then specify when to remove such a fact by calling the addPolicy() method with the fact header, name of the time stamped slot and the wanted time lag as parameters. If no time stamped slot is specified, the default timeStamp is assumed. The disposal policy is executed at the end of every model step after running the Jess engine, ensuring that a time lag of 0 results in immediate removal.

Author:
Scott, Ruth

Field Summary
(package private)  jess.Context context
          The context of the Jess engine
(package private)  jess.Rete engine
          The Jess engine
(package private)  java.util.HashMap<java.lang.String,java.lang.Integer> policy
          the list of policies (key = fact header, value = time lag)
(package private)  java.util.HashMap<java.lang.String,java.lang.String> timedSlots
          the list of slots containing the time stamp information (key = fact header, value = time stamp slot)
 
Constructor Summary
DisposalPolicy(java.util.HashMap<java.lang.String,java.lang.Integer> policy, jess.Rete engine)
          Creates a new disposal policy class with the given list of policies.
DisposalPolicy(jess.Rete engine)
          Creates a new empty disposal policy class.
 
Method Summary
 void addPolicy(java.lang.String factHeader, int lag)
          adds a policy for a fact with default tickStamp slot
 void addPolicy(java.lang.String factHeader, java.lang.String slotHeader, int lag)
          adds a policy for a fact with a specified timed slot
protected  void determineDisposalList(java.util.Iterator factList, java.util.ArrayList<jess.Fact> disposalList, int tick)
          The strategy applied to determine which facts fit the defined policies and should therefore be removed.
 void executePolicy(int tick)
          Executes the policies at the given time step.
 void removePolicy(java.lang.String factHeader)
          removes the policy for the specified fact type
 void setPolicy(java.util.HashMap<java.lang.String,java.lang.Integer> policy)
          replaces the current list of policies with the given list of policies.
 void setPolicy(java.util.HashMap<java.lang.String,java.lang.Integer> policy, java.util.HashMap<java.lang.String,java.lang.String> timedSlots)
          replaces the current list of policies with the given list of policies.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

engine

jess.Rete engine
The Jess engine


context

jess.Context context
The context of the Jess engine


policy

java.util.HashMap<java.lang.String,java.lang.Integer> policy
the list of policies (key = fact header, value = time lag)


timedSlots

java.util.HashMap<java.lang.String,java.lang.String> timedSlots
the list of slots containing the time stamp information (key = fact header, value = time stamp slot)

Constructor Detail

DisposalPolicy

public DisposalPolicy(jess.Rete engine)
Creates a new empty disposal policy class.

Parameters:
engine - the Jess engine

DisposalPolicy

public DisposalPolicy(java.util.HashMap<java.lang.String,java.lang.Integer> policy,
                      jess.Rete engine)
Creates a new disposal policy class with the given list of policies.

Parameters:
policy - list of policies (all facts are assumed to have the default "tickStamp" time slot)
engine - the Jess engine
Method Detail

addPolicy

public void addPolicy(java.lang.String factHeader,
                      int lag)
adds a policy for a fact with default tickStamp slot

Parameters:
factHeader - the fact header
lag - the time lag (number of ticks until the fact is to be removed)

addPolicy

public void addPolicy(java.lang.String factHeader,
                      java.lang.String slotHeader,
                      int lag)
adds a policy for a fact with a specified timed slot

Parameters:
factHeader - the fact header
slotHeader - name of the time stamp slot
lag - the time lag (number of ticks until the fact is to be removed)

removePolicy

public void removePolicy(java.lang.String factHeader)
removes the policy for the specified fact type

Parameters:
factHeader - the fact header

executePolicy

public void executePolicy(int tick)
Executes the policies at the given time step. To do so, this method retrieves the list of facts from Jess and runs through it once, determining every fact that fits a disposal policy and thus has to be removed. The determination of fitting facts is realised in the method determineDisposalList(), which may be overwritten by sub-classes (Strategy design pattern)

Parameters:
tick - - the current time step

determineDisposalList

protected void determineDisposalList(java.util.Iterator factList,
                                     java.util.ArrayList<jess.Fact> disposalList,
                                     int tick)
The strategy applied to determine which facts fit the defined policies and should therefore be removed. Collects all fitting facts in a disposal list.

Parameters:
factList - the list of all facts to be checked
disposalList - the list of facts to be removed from the fact base
tick - the current tick

setPolicy

public void setPolicy(java.util.HashMap<java.lang.String,java.lang.Integer> policy)
replaces the current list of policies with the given list of policies. All facts are assumed to have the default tickStamp slot.

Parameters:
policy - new list of policies

setPolicy

public void setPolicy(java.util.HashMap<java.lang.String,java.lang.Integer> policy,
                      java.util.HashMap<java.lang.String,java.lang.String> timedSlots)
replaces the current list of policies with the given list of policies.

Parameters:
policy - new list of policies
timedSlots - new list of time stamp slots