Package jason.environment
Class TimeSteppedEnvironment
java.lang.Object
jason.environment.Environment
jason.environment.TimeSteppedEnvironment
- Direct Known Subclasses:
SteppedEnvironment
public class TimeSteppedEnvironment extends Environment
General environment class that "synchronise" all agents actions.
It waits one action for each agent and, when all actions is received,
executes them.
- Author:
- Jomi
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
TimeSteppedEnvironment.ActRequest
static class
TimeSteppedEnvironment.OverActionsPolicy
Policy used when a second action is requested and the agent still has another action pending execution(package private) class
TimeSteppedEnvironment.TimeOutThread
-
Field Summary
Fields Modifier and Type Field Description private java.util.logging.Logger
logger
private int
nbAgs
private TimeSteppedEnvironment.OverActionsPolicy
overActPol
private java.util.Queue<TimeSteppedEnvironment.ActRequest>
overRequests
private java.util.Map<java.lang.String,TimeSteppedEnvironment.ActRequest>
requests
private int
sleep
private int
step
private long
stepTimeout
private TimeSteppedEnvironment.TimeOutThread
timeoutThread
Fields inherited from class jason.environment.Environment
executor
-
Constructor Summary
Constructors Constructor Description TimeSteppedEnvironment()
-
Method Summary
Modifier and Type Method Description Structure
getActionInSchedule(java.lang.String agName)
int
getNbAgs()
Returns the number of agents in the MAS (used to test the end of a cycle)java.util.Collection<Literal>
getPercepts(java.lang.String agName)
stops perception while executing the step's actionsint
getStep()
returns the current step countervoid
init(java.lang.String[] args)
Resets step counter and scheduled action requests to neutral state, optionally sets a timeout for waiting on agent actions in a step.protected int
requiredStepsForAction(java.lang.String agName, Structure action)
void
scheduleAction(java.lang.String agName, Structure action, java.lang.Object infraData)
Called by the agent infrastructure to schedule an action to be executed on the environmentvoid
setNbAgs(int n)
Set the number of agentsvoid
setOverActionsPolicy(TimeSteppedEnvironment.OverActionsPolicy p)
Sets the policy used for the second ask for an action while another action is not finished yet.void
setSleep(int s)
defines the time for a pause between cyclesvoid
setTimeout(int to)
private void
startNewStep()
protected void
stepFinished(int step, long elapsedTime, boolean byTimeout)
to be overridden by the user classprotected void
stepStarted(int step)
to be overridden by the user classvoid
stop()
Called just before the end of MAS execution, the user environment could override it.protected boolean
testEndCycle(java.util.Set<java.lang.String> finishedAgs)
Returns true when a new cycle can start, it normally holds when all agents are in the finishedAgs set.protected void
updateAgsPercept()
This method is called after the execution of the action and before to send 'continue' to the agentsprotected void
updateNumberOfAgents()
Updates the number of agents using the environment, this default implementation, considers all agents in the MAS as actors in the environment.Methods inherited from class jason.environment.Environment
addPercept, addPercept, clearAllPercepts, clearPercepts, clearPercepts, consultPercepts, containsPercept, containsPercept, executeAction, getEnvironmentInfraTier, getLogger, informAgsEnvironmentChanged, informAgsEnvironmentChanged, isRunning, removePercept, removePercept, removePerceptsByUnif, removePerceptsByUnif, setEnvironmentInfraTier
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
logger
private java.util.logging.Logger logger -
step
private int step -
nbAgs
private int nbAgs -
requests
-
overRequests
-
timeoutThread
-
stepTimeout
private long stepTimeout -
sleep
private int sleep -
overActPol
-
-
Constructor Details
-
TimeSteppedEnvironment
public TimeSteppedEnvironment()
-
-
Method Details
-
init
public void init(java.lang.String[] args)Resets step counter and scheduled action requests to neutral state, optionally sets a timeout for waiting on agent actions in a step.- Overrides:
init
in classEnvironment
- Parameters:
args
- either empty, or contains timeout in milliseconds at pos 0
-
setSleep
public void setSleep(int s)defines the time for a pause between cycles -
setTimeout
public void setTimeout(int to) -
stop
public void stop()Description copied from class:Environment
Called just before the end of MAS execution, the user environment could override it.- Overrides:
stop
in classEnvironment
-
updateNumberOfAgents
protected void updateNumberOfAgents()Updates the number of agents using the environment, this default implementation, considers all agents in the MAS as actors in the environment. -
getNbAgs
public int getNbAgs()Returns the number of agents in the MAS (used to test the end of a cycle) -
setNbAgs
public void setNbAgs(int n)Set the number of agents -
getStep
public int getStep()returns the current step counter -
setOverActionsPolicy
Sets the policy used for the second ask for an action while another action is not finished yet. If set as queue, the second action is added in a queue for future execution If set as failSecond, the second action fails. -
scheduleAction
Description copied from class:Environment
Called by the agent infrastructure to schedule an action to be executed on the environment- Overrides:
scheduleAction
in classEnvironment
-
getActionInSchedule
-
testEndCycle
protected boolean testEndCycle(java.util.Set<java.lang.String> finishedAgs)Returns true when a new cycle can start, it normally holds when all agents are in the finishedAgs set.- Parameters:
finishedAgs
- the set of agents' name that already finished the current cycle
-
updateAgsPercept
protected void updateAgsPercept()This method is called after the execution of the action and before to send 'continue' to the agents -
startNewStep
private void startNewStep() -
stepStarted
protected void stepStarted(int step)to be overridden by the user class -
stepFinished
protected void stepFinished(int step, long elapsedTime, boolean byTimeout)to be overridden by the user class -
requiredStepsForAction
-
getPercepts
stops perception while executing the step's actions- Overrides:
getPercepts
in classEnvironment
-