Class Environment

java.lang.Object
jason.environment.Environment
Direct Known Subclasses:
TimeSteppedEnvironment

public class Environment extends 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 Details

  • 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(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

      public void setEnvironmentInfraTier(EnvironmentInfraTier je)
      Sets the infrastructure tier of the environment (saci, jade, local, ...)
    • getEnvironmentInfraTier

      public EnvironmentInfraTier getEnvironmentInfraTier()
    • getLogger

      public Logger getLogger()
    • informAgsEnvironmentChanged

      @Deprecated public void informAgsEnvironmentChanged(Collection<String> agents)
      Deprecated.
      use version with String... parameter
    • informAgsEnvironmentChanged

      public void informAgsEnvironmentChanged(String... agents)
    • getPercepts

      public Collection<Literal> getPercepts(String agName)
      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

      public List<Literal> consultPercepts(String agName)
      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

      public void addPercept(Literal... perceptions)
      Adds a perception for all agents
    • removePercept

      public boolean removePercept(Literal per)
      Removes a perception from the common perception list
    • removePerceptsByUnif

      public int removePerceptsByUnif(Literal per)
      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

      public boolean containsPercept(Literal per)
      Returns true if the list of common percepts contains the perception per.
    • addPercept

      public void addPercept(String agName, Literal... per)
      Adds a perception for a specific agent
    • removePercept

      public boolean removePercept(String agName, Literal per)
      Removes a perception for an agent
    • removePerceptsByUnif

      public int removePerceptsByUnif(String agName, Literal per)
      Removes from an agent perception all percepts that unifies with per.
      Returns:
      the number of removed percepts.
    • containsPercept

      public boolean containsPercept(String agName, Literal per)
    • clearPercepts

      public void clearPercepts(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

      public void scheduleAction(String agName, Structure action, Object infraData)
      Called by the agent infrastructure to schedule an action to be executed on the environment
    • executeAction

      public boolean executeAction(String agName, Structure act)
      Executes an action on the environment. This method is probably overridden in the user environment class.