Package jason.environment
Class Environment
java.lang.Object
jason.environment.Environment
- Direct Known Subclasses:
TimeSteppedEnvironment
public class Environment
extends java.lang.Object
It is a base class for Environment, it is overridden by the user
application to define the environment "behaviour".
Execution sequence:
- setEnvironmentInfraTier,
- init,
- (getPercept|executeAction)*,
- stop.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.List<Literal>>
agPercepts
private EnvironmentInfraTier
environmentInfraTier
the infrastructure tier for environment (Local, Jade, ...)protected java.util.concurrent.ExecutorService
executor
private boolean
isRunning
private static java.util.logging.Logger
logger
private java.util.List<Literal>
percepts
private java.util.Set<java.lang.String>
uptodateAgs
-
Constructor Summary
Constructors Constructor Description Environment()
creates an environment class with the default number of threads in the poolEnvironment(int n)
creates an environment class with n threads to execute actions required by the agents -
Method Summary
Modifier and Type Method Description void
addPercept(Literal... perceptions)
Adds a perception for all agentsvoid
addPercept(java.lang.String agName, Literal... per)
Adds a perception for a specific agentvoid
clearAllPercepts()
Clears all perception (from common list and individual perceptions)void
clearPercepts()
Clears the list of global perceptsvoid
clearPercepts(java.lang.String agName)
Clears the list of percepts of a specific agentjava.util.List<Literal>
consultPercepts(java.lang.String agName)
Returns a copy of the perception for an agent.boolean
containsPercept(Literal per)
Returns true if the list of common percepts contains the perception per.boolean
containsPercept(java.lang.String agName, Literal per)
boolean
executeAction(java.lang.String agName, Structure act)
Executes an action on the environment.EnvironmentInfraTier
getEnvironmentInfraTier()
java.util.logging.Logger
getLogger()
java.util.Collection<Literal>
getPercepts(java.lang.String agName)
Returns percepts for an agent.void
informAgsEnvironmentChanged(java.lang.String... agents)
void
informAgsEnvironmentChanged(java.util.Collection<java.lang.String> agents)
Deprecated.use version with String...void
init(java.lang.String[] args)
Called before the MAS execution with the args informed in .mas2j project, the user environment could override it.boolean
isRunning()
boolean
removePercept(Literal per)
Removes a perception from the common perception listboolean
removePercept(java.lang.String agName, Literal per)
Removes a perception for an agentint
removePerceptsByUnif(Literal per)
Removes all percepts from the common perception list that unifies with per.int
removePerceptsByUnif(java.lang.String agName, Literal per)
Removes from an agent perception all percepts that unifies with per.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
setEnvironmentInfraTier(EnvironmentInfraTier je)
Sets the infrastructure tier of the environment (saci, jade, local, ...)void
stop()
Called just before the end of MAS execution, the user environment could override it.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
logger
private static java.util.logging.Logger logger -
percepts
-
agPercepts
-
isRunning
private boolean isRunning -
environmentInfraTier
the infrastructure tier for environment (Local, Jade, ...) -
uptodateAgs
private java.util.Set<java.lang.String> uptodateAgs -
executor
protected java.util.concurrent.ExecutorService executor
-
-
Constructor Details
-
Environment
public Environment(int n)creates an environment class with n threads to execute actions required by the agents -
Environment
public Environment()creates an environment class with the default number of threads in the pool
-
-
Method Details
-
init
public void init(java.lang.String[] args)Called before the MAS execution with the args informed in .mas2j project, the user environment could override it. -
stop
public void stop()Called just before the end of MAS execution, the user environment could override it. -
isRunning
public boolean isRunning() -
setEnvironmentInfraTier
Sets the infrastructure tier of the environment (saci, jade, local, ...) -
getEnvironmentInfraTier
-
getLogger
public java.util.logging.Logger getLogger() -
informAgsEnvironmentChanged
@Deprecated public void informAgsEnvironmentChanged(java.util.Collection<java.lang.String> agents)Deprecated.use version with String... parameter -
informAgsEnvironmentChanged
public void informAgsEnvironmentChanged(java.lang.String... agents) -
getPercepts
Returns percepts for an agent. A full copy of both common and agent's percepts lists is returned. It returns null if the agent's perception doesn't changed since last call. This method is to be called by TS and should not be called by other objects. -
consultPercepts
Returns a copy of the perception for an agent. It is the same list returned by getPercepts, but doesn't consider the last call of the method. -
addPercept
Adds a perception for all agents -
removePercept
Removes a perception from the common perception list -
removePerceptsByUnif
Removes all percepts from the common perception list that unifies with per. Example: removePerceptsByUnif(Literal.parseLiteral("position(_)")) will remove all percepts that unifies "position(_)".- Returns:
- the number of removed percepts.
-
clearPercepts
public void clearPercepts()Clears the list of global percepts -
containsPercept
Returns true if the list of common percepts contains the perception per. -
addPercept
Adds a perception for a specific agent -
removePercept
Removes a perception for an agent -
removePerceptsByUnif
Removes from an agent perception all percepts that unifies with per.- Returns:
- the number of removed percepts.
-
containsPercept
-
clearPercepts
public void clearPercepts(java.lang.String agName)Clears the list of percepts of a specific agent -
clearAllPercepts
public void clearAllPercepts()Clears all perception (from common list and individual perceptions) -
scheduleAction
Called by the agent infrastructure to schedule an action to be executed on the environment -
executeAction
Executes an action on the environment. This method is probably overridden in the user environment class.
-