mas.agentsHempelsSofa
Class StrategyBasedAgent

java.lang.Object
  extended by massim.javaagents.Agent
      extended by mas.agentsHempelsSofa.StrategyBasedAgent
Direct Known Subclasses:
StrategyBasedExplorerAgent, StrategyBasedInspectorAgent, StrategyBasedRepairerAgent, StrategyBasedSaboteurAgent, StrategyBasedSentinelAgent

public abstract class StrategyBasedAgent
extends Agent

An implemenation of a generic Goal Oriented Agent.

Author:
Hempels-Sofa

Field Summary
protected  ActionGenerator ag
          The action generator.
protected  Environment environment
          The environment of the agent.
protected  Graph graph
          The believed Looking of the graph.
 AgentToken myToken
          The token which holds percepted states of this agent.
protected  java.util.Collection<eis.iilang.Percept> percepts
          The percepts which are received in each step.
static boolean SHOW_GRAPH_WINDOW
           
protected  int tactics
          The current tactical state of the agent.
 
Fields inherited from class massim.javaagents.Agent
beliefs, goals
 
Constructor Summary
StrategyBasedAgent(java.lang.String name, java.lang.String team)
          Creates a new Subsumption Agent with a specified agent-name and team-name.
 
Method Summary
 void broadcast(apltk.interpreter.data.LogicBelief belief)
           
protected  eis.iilang.Action checkEnergy(eis.iilang.Action action)
          checks whether the energy of the agent is sufficient to execute the action.
protected  void clearlog()
          clears the agent's log.
protected  boolean enemyNearby()
           
 boolean enemySaboteurAt(Vertex v)
           
 boolean enemyUnknownAgentAt(Vertex v)
           
protected  void finalize()
           
abstract  eis.iilang.Action generateAchievementAction(java.lang.String focus)
          computes a achievement supportive action with a certain focus
abstract  eis.iilang.Action generateBuyAction(java.lang.String focus)
          computes a buy action with a certain focus
abstract  eis.iilang.Action generateDefensiveAction(java.lang.String focus)
          computes an defensive action with a certain focus.
abstract  eis.iilang.Action generateOffensiveAction(java.lang.String focus)
          computes an offensive action with a certain focus.
abstract  eis.iilang.Action generateZoneAction(java.lang.String focus)
          computes a zone action with a certain focus
 Strategy getDefaultStrategy()
           
 Environment getEnvironment()
           
 Graph getGraph()
           
 Strategy getLastStrategy()
           
protected  AgentToken getMyToken()
           
 java.util.Collection<eis.iilang.Percept> getPercepts()
           
 Strategy getStrategy()
           
 ZoneManager getZoneManager()
           
abstract  void handleAgentSpecificMessages()
          handles some messages which are agent-role specific.
 void handlePercept(eis.iilang.Percept p)
          This method is called if the environment-interface sends a percept as a notification.
 void loadStrategy(Strategy strategy)
          Loads a strategy without cloning.
 void loadStrategy(Strategy strategy, boolean clone)
          Loads a strategy
protected  void log(java.lang.String s)
          appends some string to the agents log.
abstract  void preferencesRevision()
          computes the preferences for the strategies and focuses.
 void reloadStrategy()
          reloads the last strategy.
 void setEnvironment(Environment environment)
           
protected  void setGraph(Graph graph)
          b
protected  void setMyToken(AgentToken myToken)
           
 void setPercepts(java.util.Collection<eis.iilang.Percept> percepts)
           
 void setStrategy(Strategy strategy)
           
 void setZoneManager(ZoneManager zoneManager)
           
 eis.iilang.Action step()
          Executes one step of the agent.
 java.lang.String toString()
           
protected  boolean unsurveyedEdgesNearby()
           
 
Methods inherited from class massim.javaagents.Agent
addBelief, addGoal, broadcastBelief, clearBeliefs, clearGoals, containsBelief, containsGoal, createAgentFromClass, equals, getAllBeliefs, getAllPercepts, getBeliefBase, getEnvironmentInterface, getGoalBase, getMessages, getName, getTeam, hashCode, println, removeBeliefs, removeGoals, sendMessage, setEnvironmentInterface
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

environment

protected Environment environment
The environment of the agent.


graph

protected Graph graph
The believed Looking of the graph.


ag

protected ActionGenerator ag
The action generator.


percepts

protected java.util.Collection<eis.iilang.Percept> percepts
The percepts which are received in each step.


myToken

public AgentToken myToken
The token which holds percepted states of this agent.


tactics

protected int tactics
The current tactical state of the agent. This value can be specified freely by every agent.


SHOW_GRAPH_WINDOW

public static boolean SHOW_GRAPH_WINDOW
Constructor Detail

StrategyBasedAgent

public StrategyBasedAgent(java.lang.String name,
                          java.lang.String team)
Creates a new Subsumption Agent with a specified agent-name and team-name.

Parameters:
name - The name of the agent.
team - The team-name the agent belongs to.
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

handlePercept

public void handlePercept(eis.iilang.Percept p)
Description copied from class: Agent
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.

Specified by:
handlePercept in class Agent
Parameters:
p - the percept to be handled

step

public eis.iilang.Action step()
Description copied from class: Agent
Executes one step of the agent. This method is assumed to terminate in appropriate time.

Specified by:
step in class Agent

preferencesRevision

public abstract void preferencesRevision()
computes the preferences for the strategies and focuses.


handleAgentSpecificMessages

public abstract void handleAgentSpecificMessages()
handles some messages which are agent-role specific.


broadcast

public void broadcast(apltk.interpreter.data.LogicBelief belief)
Parameters:
belief - the belief to send to all other agents.

generateOffensiveAction

public abstract eis.iilang.Action generateOffensiveAction(java.lang.String focus)
computes an offensive action with a certain focus.

Parameters:
focus -
  • offensiveDestroyZones,
  • offensiveDestroyAgents,
  • offensiveDrawback
Returns:
a specific action.

generateDefensiveAction

public abstract eis.iilang.Action generateDefensiveAction(java.lang.String focus)
computes an defensive action with a certain focus.

Parameters:
focus -
  • defensiveParry,
  • defensiveRunAway,
  • defensiveRepair,
Returns:
a specific action.

generateZoneAction

public abstract eis.iilang.Action generateZoneAction(java.lang.String focus)
computes a zone action with a certain focus

Parameters:
focus -
  • zoneExpand,
  • zoneStability,
  • zoneMainZone,
  • zoneDrawback
Returns:
a specific action.

generateBuyAction

public abstract eis.iilang.Action generateBuyAction(java.lang.String focus)
computes a buy action with a certain focus

Parameters:
focus -
  • buyBattery,
  • buySabotageDevice,
  • buySensor,
  • buyShield
Returns:
a specific action.

generateAchievementAction

public abstract eis.iilang.Action generateAchievementAction(java.lang.String focus)
computes a achievement supportive action with a certain focus

Parameters:
focus -
  • achievementsProbedVertices,
  • achievementsSurveyedEdges,
  • achievementsInspectedAgents,
  • achievementsSuccessfulAttacks,
  • achievementsSuccessfulParries,
  • achievementsAreaValue
Returns:
a specific action.

checkEnergy

protected eis.iilang.Action checkEnergy(eis.iilang.Action action)
checks whether the energy of the agent is sufficient to execute the action.

Parameters:
action - the action which shall be executed.
Returns:
the same action

enemyNearby

protected boolean enemyNearby()
Returns:
True, if there is an enemy agent or an unknown agent on my postion

enemySaboteurAt

public boolean enemySaboteurAt(Vertex v)
Parameters:
v - the vertex to test
Returns:
true, if there is an enemy saboteur, else false

enemyUnknownAgentAt

public boolean enemyUnknownAgentAt(Vertex v)
Parameters:
v - vertex to test
Returns:
true if there is an enenmy unknown agent, else false

log

protected void log(java.lang.String s)
appends some string to the agents log.

Parameters:
s - the string to append

clearlog

protected void clearlog()
clears the agent's log.


finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

setGraph

protected void setGraph(Graph graph)
b

Parameters:
graph - the graph to set

getGraph

public Graph getGraph()
Returns:
the graph

setEnvironment

public void setEnvironment(Environment environment)
Parameters:
environment - the environment to set

getEnvironment

public Environment getEnvironment()
Returns:
the environment

setPercepts

public void setPercepts(java.util.Collection<eis.iilang.Percept> percepts)
Parameters:
percepts - the percepts to set

getPercepts

public java.util.Collection<eis.iilang.Percept> getPercepts()
Returns:
the percepts

setMyToken

protected void setMyToken(AgentToken myToken)
Parameters:
myToken - the myToken to set

getMyToken

protected AgentToken getMyToken()
Returns:
the myToken

setStrategy

public void setStrategy(Strategy strategy)
Parameters:
strategy - the strategy to set

getStrategy

public Strategy getStrategy()
Returns:
the current strategy which will be used for the determination of one of the next action-generated methods: Rules for the strategy and focuses preferences p:
  1. For all strategies 0 <= p < 1: a strategy is randomly chosen.
  2. A strategy has p=1: the first occurring strategy with p = 1 is chosen.
  3. Multiple strategies have 1 < p < 2: only these strategies can be chosen with p' = p - 1.
  4. A strategy is chosen, for all ps of focuses p < 1: a focus is randomly chosen.
  5. A strategy is chosen, a focus has p = 1: the first occuring focus with p = 1 is chosen.
  6. A strategy is chosen, multiple focuses have 1 < p < 2: only these focuses are considered with p' = p - 1

getLastStrategy

public Strategy getLastStrategy()
Returns:
the generic strategy from the last executed step.

getDefaultStrategy

public Strategy getDefaultStrategy()
Returns:
the default generic strategy of this agent. It is parsed from the fitting strategyconfig_agentX file. Everytimes step is executed, strategy is reset to this default strategy. You can recall the previously used strategy via getLastStrategy().

reloadStrategy

public void reloadStrategy()
reloads the last strategy.


loadStrategy

public void loadStrategy(Strategy strategy)
Loads a strategy without cloning.

Parameters:
strategy - the strategy to load

loadStrategy

public void loadStrategy(Strategy strategy,
                         boolean clone)
Loads a strategy

Parameters:
strategy - the strategy to load
clone -
  • true, if the strategy shall be cloned
  • false, otherwise (more performant)

unsurveyedEdgesNearby

protected boolean unsurveyedEdgesNearby()
Returns:
True, if there is an unsurveyed edge around the vertex I am on

setZoneManager

public void setZoneManager(ZoneManager zoneManager)
Parameters:
zoneManager - the zoneManager to set

getZoneManager

public ZoneManager getZoneManager()
Returns:
the zoneManager


Copyright © 2012. All Rights Reserved.