com.agentfactory.cldc.logic
Class Agent

java.lang.Object
  extended by com.agentfactory.cldc.logic.Agent

public class Agent
extends java.lang.Object

The Agent class includes the actuators, perceptors, commitment rules, resource constraints, and roles that represent an AFME agent. It contains the core control algorithm that governs agent behaviour. In AFME, agents follow a sense, deliberate, act cycle. The agent's perceptors are initially fired. The desires are then identified through the use of resolution-based reasoning. The intentions are then identified in the knapsack procedure. Finally, depending on the nature and degree of the commitments adopted, various actuators are fired.

Author:
Conor Muldoon

Constructor Summary
Agent(TerImplication[] commitmentRules, java.util.Hashtable actuators, Perceivable[] perceptors, java.util.Hashtable mods, RoleLibrary lib, int res)
          Constructs an agent from a combination of its actuators, perceptors, commitment rules, roles, and the amount of resources available to the agent.
 
Method Summary
 void addActBelief(FOS fos)
          This method adds a belief to the agent and is called by the affect manager when an actuator is adding a belief.
 void addFOSBelief(FOS belief)
          Adds a first order structure to the agents belief set.
 void addToMod(java.lang.String s, Commitment c)
          Associates a commitment with a label.
 void adoptChild(Commitment commit)
          Adds a child commitment to the agent's current commitment set.
 void adoptCommitment(Commitment commit)
          Adds a commitment to the agent's current commitment set.
 void belBuf(java.lang.StringBuffer bel)
          Appends the agent's current and temporal beliefs to a string buffer.
 void commitBuf(java.lang.StringBuffer commit)
          Appends a string representation of each of the agent's current commitments to a string buffer.
 void handleTrigger(FOS[] trigger, java.util.Hashtable table, RoleTemplate template)
          For each trigger of a role template, checks if the trigger matches a current belief.
 boolean processFOS(FOS fos, SubstitutionSet set)
          Adds variables to the substitution set for the specified first order structure if there are current beliefs that match with the first order structure and provided the substitution set is not null.
 void removeFromMod(java.lang.String s)
          This method removes the commitment that is associated with the specified label from the update table( See addToMod(String, Commitment)).
 void retractBelief(FOS fos)
          This method causes an agent to drop a belief.
 void solveRule(TerImplication[] rule)
          Solves a list of commitment rules and subsequently clears the solutions.
 void step()
          Performs a step in the agent's control algroithm.
 void updateBeliefs()
          This method updates the agent's current belief set.
 void updateResources(FOS fos)
          Updates the amount of resources available to the agent.
 void updateValues(FOS value, FOS cost, java.lang.String id)
          Updates the cost and value of the commitment that has the specified label.
 void writeToStream(java.io.DataOutputStream dos)
          Writes the agent's internal state to a data output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Agent

public Agent(TerImplication[] commitmentRules,
             java.util.Hashtable actuators,
             Perceivable[] perceptors,
             java.util.Hashtable mods,
             RoleLibrary lib,
             int res)
Constructs an agent from a combination of its actuators, perceptors, commitment rules, roles, and the amount of resources available to the agent.

Parameters:
commitmentRules - the set of rules that are used to identify the agent's desired states.
actuators - a hash table that maps action identifiers to concrete Actions. Actions typically take the form of Actuators.
perceptors - the set of perceptors (software sensors) that are fired on each iteration of the agent's control algorithm.
mods - a hash table of modules that belong to the agent.
lib - a library of roles that the agent adopts under various circumstances.
res - the amount or resources available to the agent.
Method Detail

updateResources

public void updateResources(FOS fos)
Updates the amount of resources available to the agent.

Parameters:
fos - a first order structure representation of the amount of resources available to the agent.

addToMod

public void addToMod(java.lang.String s,
                     Commitment c)
Associates a commitment with a label. This method is used to assoicate a label with a commitment so as that it can be referenced at a later stage to have its assoicated value or cost updated.

Parameters:
s - the label of the commitment.
c - the commitment to be labeled.

removeFromMod

public void removeFromMod(java.lang.String s)
This method removes the commitment that is associated with the specified label from the update table( See addToMod(String, Commitment)).

Parameters:
s - the label of the commitment.

updateValues

public void updateValues(FOS value,
                         FOS cost,
                         java.lang.String id)
Updates the cost and value of the commitment that has the specified label.

Parameters:
value - the new value of the commitment.
cost - the new cost of the commitment.
id - the label of the commitment.

writeToStream

public void writeToStream(java.io.DataOutputStream dos)
                   throws java.io.IOException
Writes the agent's internal state to a data output stream. This method is typically used in the migration service, but it could be conceivable used for other purposes. For instance, it could be used to write the state to a data store for persistent execution over multiple runs.

Parameters:
dos - the data output stream that the state is written to.
Throws:
java.io.IOException - if there is an I/O error.

addActBelief

public void addActBelief(FOS fos)
This method adds a belief to the agent and is called by the affect manager when an actuator is adding a belief. This method differs from addFOSBelief(FOS), which is called by the perception manager. The belief is not added to the belief set during the current cycle. The reason for this is that commitment execution is nondeterministic. That is, the order in which commitments are fired in the current cycle is irrelevant at a logical level and will not have a consequence on the resolution based resaoning process for determining the desired states in the current cycle. Beliefs added using this method will only be added to the agents current belief set after all of the commitments in the current cycle have been executed.

Parameters:
fos - the belief to be added.

addFOSBelief

public void addFOSBelief(FOS belief)
Adds a first order structure to the agents belief set.

Parameters:
belief - fos the first order structure to be added to the agent's beliefs.

retractBelief

public void retractBelief(FOS fos)
This method causes an agent to drop a belief. It operates in a similar manner to addActBelief(FOS). The belief is not retracted until the current control process has finished determining the desired states. If the agent does not contain the specified belief, no error is thrown.

Parameters:
fos - the belief that is to be retracted.

updateBeliefs

public void updateBeliefs()
This method updates the agent's current belief set. Initially all of the agents perceptors are fired. The beliefs to be retracted are then removed from the set. Subsequently, the agents temporal beliefs are added (Provided it is the correct cycle for next beliefs).


step

public void step()
Performs a step in the agent's control algroithm. It should be noted that this method does not update the agent's beliefs. The updateBeliefs method must be called prior to this method for a complete cycle.


belBuf

public void belBuf(java.lang.StringBuffer bel)
Appends the agent's current and temporal beliefs to a string buffer.

Parameters:
bel - the string buffer that the beliefs are appended to.

commitBuf

public void commitBuf(java.lang.StringBuffer commit)
Appends a string representation of each of the agent's current commitments to a string buffer.

Parameters:
commit - the string buffer that the string representation of the commitments are appended to.

solveRule

public void solveRule(TerImplication[] rule)
               throws MalformedLogicException
Solves a list of commitment rules and subsequently clears the solutions. If a commitment rule is evaluated to true for at least one binding, a commitment will be added to the desired states or commitment set.

Parameters:
rule - the list of rules to be evaluated.
Throws:
MalformedLogicException - if there is a logic error.

adoptCommitment

public void adoptCommitment(Commitment commit)
Adds a commitment to the agent's current commitment set.

Parameters:
commit - the commitment that is to be added.

adoptChild

public void adoptChild(Commitment commit)
Adds a child commitment to the agent's current commitment set.

Parameters:
commit - the child commitment to be added.

handleTrigger

public void handleTrigger(FOS[] trigger,
                          java.util.Hashtable table,
                          RoleTemplate template)
                   throws MalformedLogicException
For each trigger of a role template, checks if the trigger matches a current belief. If the trigger does match, a substitution set is created for the variables of the trigger. The substituion set is subsequently applied to the role template to create a role instance.

Parameters:
trigger - an array of triggers for the role template.
table - the hash table that the role instance is to be added to.
template - the specified role template.
Throws:
MalformedLogicException - if there is a logic error.

processFOS

public boolean processFOS(FOS fos,
                          SubstitutionSet set)
                   throws MalformedLogicException
Adds variables to the substitution set for the specified first order structure if there are current beliefs that match with the first order structure and provided the substitution set is not null. If the substitution set is null, returns true if the first order structure matches a current belief, false otherwise.

Parameters:
fos - the specified first order structure.
set - the substitution set to add variable mappings to.
Returns:
true if the first order structure matches a current belief and the substitution set is null, false otherwise.
Throws:
MalformedLogicException - if there is a logic error.