Class gsEnvironment

java.lang.Object
eu.su.mas.dedale.env.gs.gsEnvironment
All Implemented Interfaces:
IEnvironment

public class gsEnvironment
extends java.lang.Object
implements IEnvironment
This class is an implementation of the IEnvironment using the graphStream library It currently offers : - several environments generators and any predefined ones that respect the DGS format - 3 types of agents (tanker, explorer and collector), - 2 type of wumpus (which generates stench), - 1 type of keyboardControlled agent (Human), that must be unique on a given instance. - Well (that generate wind and kill the agents that come in them), - 2 types of treasures (gold and diamonds) with safes with 2 opening conditions (lockpicking expertise and strength)
Author:
hc
  • Constructor Details

  • Method Details

    • CreateEnvironment

      public void CreateEnvironment​(java.lang.String topologyConfigurationFilePath, java.lang.String instanceConfiguration, boolean isGrid, java.lang.Integer envSize, boolean diamond, boolean gold, boolean well)
      Deprecated.
      Description copied from interface: IEnvironment
      Create an environment.
      Specified by:
      CreateEnvironment in interface IEnvironment
      Parameters:
      topologyConfigurationFilePath - FullPath to the file describing it. If the environment is autogenerated, null .
      instanceConfiguration - FullPath to the file describing it. If the environment is autogenerated, null.
      isGrid - true id the generated environment is a grid
      envSize - size of the generated environment
      diamond - true if diamond have to be generated
      gold - true if gold have to be generated
      well - true if wells have to be generated
    • CreateEnvironment

      public void CreateEnvironment​(GeneratorType g, java.lang.String topologyConfigurationFilePath, java.lang.String instanceConfiguration, boolean diamond, boolean gold, boolean well, java.lang.Integer... topologyParameters)
      Description copied from interface: IEnvironment
      Create an environment.
      Specified by:
      CreateEnvironment in interface IEnvironment
      Parameters:
      topologyConfigurationFilePath - fullPath towards the topology file
      instanceConfiguration - fullPath towards the file indicating the elements on the map
      g - type of generator to use
      diamond - true is we should generate diamonds
      gold - true is we should generate golds
      well - true is we should generate wells
      topologyParameters - at least, indicate the size of the environment to generate, if necessary add the generatorType specific parameters
    • deployEntity

      public void deployEntity​(java.lang.String entityName, EntityCharacteristics e, Location locationId)
      Description copied from interface: IEnvironment
      Add an entity to the graph
      Specified by:
      deployEntity in interface IEnvironment
      Parameters:
      entityName - Should be unique
      e - Type of the agent
      locationId - position where to deploy the agent, null if free Add the agent entityName of type e on the position locationId
    • removeEntity

      public void removeEntity​(java.lang.String entityName, EntityCharacteristics e)
      Specified by:
      removeEntity in interface IEnvironment
    • getCurrentPosition

      public Location getCurrentPosition​(java.lang.String entityName)
      Specified by:
      getCurrentPosition in interface IEnvironment
      Parameters:
      entityName - Name of the agent to locate
      Returns:
      The entity current position, null if the entity is not in the environment
    • observe

      public java.util.List<dataStructures.tuple.Couple<Location,​java.util.List<dataStructures.tuple.Couple<Observation,​java.lang.Integer>>>> observe​(Location currentPosition, java.lang.String agentName)
      Specified by:
      observe in interface IEnvironment
      Parameters:
      currentPosition - the position from which the agent observe
      agentName - the name of the agent
      Returns:
      The list of observed positions, and for each one the list of observations
    • moveTo

      public java.lang.Integer moveTo​(java.lang.String entityName, EntityCharacteristics e, Location targetedPosition)
      Specified by:
      moveTo in interface IEnvironment
      Parameters:
      entityName - the name of the entity
      e - characteristics of the entity
      targetedPosition - its expected destination
      Returns:
      1 if true, 0 if refused, -1 if the consequence of the move is the agent dying
    • openLock

      public boolean openLock​(java.lang.String entityName, Location location, ElementType e)
      Specified by:
      openLock in interface IEnvironment
      Parameters:
      entityName - the name of the entity
      location - the position to pick the resource
      e - Type of resource to unlock in the environment (Currently only gold or diamond )
      Returns:
      True is the lock is opened, false otherwise
    • closeLock

      public boolean closeLock​(Location location)
      Close the lock of the safe (if any) on the current location Do not work if there are several
      Specified by:
      closeLock in interface IEnvironment
      Parameters:
      location - the position to close the safe(s)
      Returns:
      True if there was at least one safe on the current position (they are now closed), false otherwise
    • pick

      public int pick​(java.lang.String agentName, Location currentPosition, ElementType e, java.lang.Integer maxQuantity)
      Specified by:
      pick in interface IEnvironment
      Parameters:
      agentName - the name of the entity
      currentPosition - the position to pick the resource
      e - ElementType to pick
      maxQuantity - maximum number of e that the agent is able to pick
      Returns:
      the amount of resources that the agent was able to collect
    • dropOff

      public boolean dropOff​(Location location, ElementType e, java.lang.Integer quantity)
      There can be only one safe of one unique type on a given location.
      Specified by:
      dropOff in interface IEnvironment
      Parameters:
      location - id of the node where to drop the element
      e - the element the entity intends to drop
      quantity - the amount of value to drop on the current position
      Returns:
      true if the drop off was realised
    • throwGrenade

      public boolean throwGrenade​(java.lang.String agentName, Location targetName)
      Specified by:
      throwGrenade in interface IEnvironment
      Parameters:
      agentName - The name of the agent that is shooting
      targetName - the id of the room it aims at
      Returns:
      true if done, false otherwise
    • isReachable

      public boolean isReachable​(java.lang.String senderName, java.lang.String receiverName, int communicationReach)
      This method must be synchronized due tothe way graphStream computes the shortestPath
      Specified by:
      isReachable in interface IEnvironment
      Parameters:
      senderName - name of the entity willing to send the message
      receiverName - name of the receiver
      communicationReach - number of hops autorised to reach the targer
      Returns:
      true if the receiver is within reach
    • getName

      public java.lang.String getName()
      Specified by:
      getName in interface IEnvironment
      Returns:
      The name of the environment
    • updateNodeInterfaceComRendering

      public void updateNodeInterfaceComRendering​(java.lang.Integer val)
    • updateCommunicationStats

      public void updateCommunicationStats​(int nbSent, int nbReceived)
      Update the nb of messages sent and effectively transmitted
      Parameters:
      nbSent - number of messages sent
      nbReceived - number of messages received (as the messages can be losts if agents are out of reach)
    • updateAgentsStatsWithinGui

      public void updateAgentsStatsWithinGui()
    • getAgentToKill

      public java.lang.String getAgentToKill()
      Returns:
      the (local)name of the agent the user wants to terminate
    • getOoa

      public ObserverOfAgents getOoa()
      Returns:
      Return the object used to the observer of the agent state and sent to the GUI for stat updating
    • getGuiController

      public MyController getGuiController()
      Returns:
      Method used by the user-controlled agent to connect him to the events the gui receives (to move the agent)
    • getUserChoosenPath

      public Location getUserChoosenPath​(java.lang.String agentName)
      Parameters:
      agentName - name of the agent controlled by the user
      Returns:
      the node currently proposed as next destination to the user
    • updateUserChoosenPath

      public void updateUserChoosenPath​(java.lang.String agentName)
      When the user select next, we update the proposed path in incremental order of the neighbours id (whatever the sorting algo)
      Parameters:
      agentName - name of the agent controlled by the user