massim.javaagents
Class Agent

java.lang.Object
  extended by massim.javaagents.Agent
Direct Known Subclasses:
SimpleDebugRechargeAgent, SimpleExplorerAgent, SimpleInspectorAgent, SimpleRepairerAgent, SimpleSaboteurAgent, SimpleSentinelAgent, StrategyBasedAgent, SubsumptionAgent, TargaryenAgent

public abstract class Agent
extends java.lang.Object

This class represents a simple agent. Note that is is an abstract class, that is that you are supposed to inherit from this class in order to implement specialized agents.

An abstract agent consists of beliefs and goals and has access to a simple system for communicating with others.

Note that specialized agents can and will be instantiated by the interpreter using Java-reflection.

Author:
tristanbehrens

Field Summary
protected  java.util.Set<apltk.interpreter.data.LogicBelief> beliefs
           
protected  java.util.Set<apltk.interpreter.data.LogicGoal> goals
           
 
Constructor Summary
Agent(java.lang.String name, java.lang.String team)
          Initializes an agent with a given name.
 
Method Summary
 void addBelief(apltk.interpreter.data.LogicBelief belief)
           
 void addGoal(apltk.interpreter.data.LogicGoal goal)
           
 void broadcastBelief(apltk.interpreter.data.LogicBelief belief)
          Sends a message to all agents of the team.
protected  void clearBeliefs()
           
 void clearGoals()
           
 boolean containsBelief(apltk.interpreter.data.LogicBelief belief)
           
protected  boolean containsGoal(apltk.interpreter.data.LogicGoal goal)
           
static Agent createAgentFromClass(java.lang.String agentName, java.lang.String team, java.lang.String agentClass)
          Yields an instance of a specified agent-class with a given name.
 boolean equals(java.lang.Object obj)
           
 java.util.LinkedList<apltk.interpreter.data.LogicBelief> getAllBeliefs(java.lang.String predicate)
          Yields all beliefs from the belief base that have a specific predicate.
protected  java.util.Collection<eis.iilang.Percept> getAllPercepts()
          Yields all percepts that are currently available.
 java.util.Collection<apltk.interpreter.data.LogicBelief> getBeliefBase()
          Yields the belief-base of the agent.
static eis.EnvironmentInterfaceStandard getEnvironmentInterface()
          Yields the environment-interface that all agents access.
 java.util.Collection<apltk.interpreter.data.LogicGoal> getGoalBase()
          Yields the goal-base of the agent.
protected  java.util.Collection<apltk.interpreter.data.Message> getMessages()
          Gets all messages that were sent to the agent.
 java.lang.String getName()
          Yields the name of the agent.
 java.lang.String getTeam()
          Yields the team of the agent.
abstract  void handlePercept(eis.iilang.Percept p)
          This method is called if the environment-interface sends a percept as a notification.
 int hashCode()
           
protected  void println(java.lang.Object obj)
          Prints an arbitrary object, e.g. a String, to the standard-out.
 void removeBeliefs(java.lang.String predicate)
          Removes all beliefs from the belief-base that have a given predicate.
protected  void removeGoals(java.lang.String predicate)
          Removes all goals that have a given predicate.
 void sendMessage(apltk.interpreter.data.Belief belief, java.lang.String receiver)
          Sends a message to a specific agent in the team.
static void setEnvironmentInterface(eis.EnvironmentInterfaceStandard theEI)
          Sets the environment-interface for all agents in this process.
abstract  eis.iilang.Action step()
          Executes one step of the agent.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beliefs

protected java.util.Set<apltk.interpreter.data.LogicBelief> beliefs

goals

protected java.util.Set<apltk.interpreter.data.LogicGoal> goals
Constructor Detail

Agent

public Agent(java.lang.String name,
             java.lang.String team)
Initializes an agent with a given name. Ensures that the name is unique.

Parameters:
name - is the name of the agent
team - is the team of the agent
Method Detail

getName

public java.lang.String getName()
Yields the name of the agent.

Returns:
the name of the agent

getTeam

public java.lang.String getTeam()
Yields the team of the agent.

Returns:
the team of the agent

createAgentFromClass

public static Agent createAgentFromClass(java.lang.String agentName,
                                         java.lang.String team,
                                         java.lang.String agentClass)
Yields an instance of a specified agent-class with a given name. This uses Java-reflection and assumes that the class is already in the classpath.

Parameters:
agentName - is the name of the agent
team - is the team of the agent
agentClass - is the fully-qualified name of the agent-class to-be-loaded
Returns:
an agent-instance

setEnvironmentInterface

public static void setEnvironmentInterface(eis.EnvironmentInterfaceStandard theEI)
Sets the environment-interface for all agents in this process.

Parameters:
theEI - is the environment-interface

getEnvironmentInterface

public static eis.EnvironmentInterfaceStandard getEnvironmentInterface()
Yields the environment-interface that all agents access.

Returns:

step

public abstract eis.iilang.Action step()
Executes one step of the agent. This method is assumed to terminate in appropriate time.


println

protected final void println(java.lang.Object obj)
Prints an arbitrary object, e.g. a String, to the standard-out. Should be used for debugging purposes only.

Parameters:
obj -

getBeliefBase

public final java.util.Collection<apltk.interpreter.data.LogicBelief> getBeliefBase()
Yields the belief-base of the agent.

Returns:
the belief-base

getGoalBase

public final java.util.Collection<apltk.interpreter.data.LogicGoal> getGoalBase()
Yields the goal-base of the agent.

Returns:
the goal-base

getAllPercepts

protected java.util.Collection<eis.iilang.Percept> getAllPercepts()
Yields all percepts that are currently available.

Returns:
a list of percepts or an empty-list if perceiving failed

getMessages

protected final java.util.Collection<apltk.interpreter.data.Message> getMessages()
Gets all messages that were sent to the agent. After calling this method the messages will be removed from the message-box.

Returns:
all messages

sendMessage

public final void sendMessage(apltk.interpreter.data.Belief belief,
                              java.lang.String receiver)
Sends a message to a specific agent in the team.

Parameters:
msg - the message to be sent
receiver - the recipient of the message

broadcastBelief

public final void broadcastBelief(apltk.interpreter.data.LogicBelief belief)
Sends a message to all agents of the team.

Parameters:
msg - the message to be broadcasted

handlePercept

public abstract void handlePercept(eis.iilang.Percept p)
This method is called if the environment-interface sends a percept as a notification. Note, that sending percepts-via-notifications must be explicitely activated for the environment-interface. An alternative is to use the getAllPercepts method which yields all percepts.

Parameters:
p - the percept to be handled

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getAllBeliefs

public java.util.LinkedList<apltk.interpreter.data.LogicBelief> getAllBeliefs(java.lang.String predicate)
Yields all beliefs from the belief base that have a specific predicate.

Parameters:
predicate - the given predicate
Returns:
a list of beliefs that have the given predicate

removeBeliefs

public void removeBeliefs(java.lang.String predicate)
Removes all beliefs from the belief-base that have a given predicate.

Parameters:
predicate - the given predicate

removeGoals

protected void removeGoals(java.lang.String predicate)
Removes all goals that have a given predicate.

Parameters:
predicate - the given predicate

addBelief

public void addBelief(apltk.interpreter.data.LogicBelief belief)

addGoal

public void addGoal(apltk.interpreter.data.LogicGoal goal)

containsBelief

public boolean containsBelief(apltk.interpreter.data.LogicBelief belief)

containsGoal

protected boolean containsGoal(apltk.interpreter.data.LogicGoal goal)

clearBeliefs

protected void clearBeliefs()

clearGoals

public void clearGoals()


Copyright © 2012. All Rights Reserved.