Package eu.su.mas.dedale.env.gs
Class gsEnvironment
java.lang.Object
eu.su.mas.dedale.env.gs.gsEnvironment
- All Implemented Interfaces:
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Close the lock of the safe (if any) on the current location Do not work if there are severalvoid
CreateEnvironment
(GeneratorType g, String topologyConfigurationFilePath, String instanceConfiguration, boolean diamond, boolean gold, boolean well, Integer... topologyParameters) Create an environment.void
deployEntity
(String entityName, EntityCharacteristics e, Location locationId) Add an entity to the graphboolean
dropOff
(Location location, ElementType e, Integer quantity) There can be only one safe of one unique type on a given location.getCurrentPosition
(String entityName) getName()
getOoa()
getUserChoosenPath
(String agentName) boolean
isReachable
(String senderName, String receiverName, int communicationReach) This method must be synchronized due tothe way graphStream computes the shortestPathmoveTo
(String entityName, EntityCharacteristics e, Location targetedPosition) List
<dataStructures.tuple.Couple<Location, List<dataStructures.tuple.Couple<Observation, String>>>> boolean
openLock
(String entityName, Location location, ElementType e) int
pick
(String agentName, Location currentPosition, ElementType e, Integer maxQuantity) void
removeEntity
(String entityName, EntityCharacteristics e) boolean
throwGrenade
(String agentName, Location targetName) void
void
updateCommunicationStats
(int nbSent, int nbReceived) Update the nb of messages sent and effectively transmittedvoid
void
updateUserChoosenPath
(String agentName) When the user select next, we update the proposed path in incremental order of the neighbours id (whatever the sorting algo)
-
Constructor Details
-
gsEnvironment
public gsEnvironment()
-
-
Method Details
-
CreateEnvironment
public void CreateEnvironment(GeneratorType g, String topologyConfigurationFilePath, String instanceConfiguration, boolean diamond, boolean gold, boolean well, Integer... topologyParameters) Description copied from interface:IEnvironment
Create an environment.- Specified by:
CreateEnvironment
in interfaceIEnvironment
- Parameters:
g
- type of generator to usetopologyConfigurationFilePath
- fullPath towards the topology fileinstanceConfiguration
- fullPath towards the file indicating the elements on the mapdiamond
- true is we should generate diamondsgold
- true is we should generate goldswell
- true is we should generate wellstopologyParameters
- at least, indicate the size of the environment to generate, if necessary add the generatorType specific parameters
-
deployEntity
Description copied from interface:IEnvironment
Add an entity to the graph- Specified by:
deployEntity
in interfaceIEnvironment
- Parameters:
entityName
- Should be uniquee
- Type of the agentlocationId
- position where to deploy the agent, null if free Add the agent entityName of type e on the position locationId
-
removeEntity
- Specified by:
removeEntity
in interfaceIEnvironment
-
getCurrentPosition
- Specified by:
getCurrentPosition
in interfaceIEnvironment
- Parameters:
entityName
- Name of the agent to locate- Returns:
- The entity current position, null if the entity is not in the environment
-
observe
public List<dataStructures.tuple.Couple<Location,List<dataStructures.tuple.Couple<Observation, observeString>>>> (Location currentPosition, String agentName) - Specified by:
observe
in interfaceIEnvironment
- Parameters:
currentPosition
- the position from which the agent observeagentName
- the name of the agent- Returns:
- The list of observed positions, and for each one the list of observations
-
moveTo
- Specified by:
moveTo
in interfaceIEnvironment
- Parameters:
entityName
- the name of the entitye
- characteristics of the entitytargetedPosition
- its expected destination- Returns:
- 1 if true, 0 if refused, -1 if the consequence of the move is the agent dying
-
openLock
- Specified by:
openLock
in interfaceIEnvironment
- Parameters:
entityName
- the name of the entitylocation
- the position to pick the resourcee
- Type of resource to unlock in the environment (Currently only gold or diamond )- Returns:
- True is the lock is opened, false otherwise
-
closeLock
Close the lock of the safe (if any) on the current location Do not work if there are several- Specified by:
closeLock
in interfaceIEnvironment
- 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
- Specified by:
pick
in interfaceIEnvironment
- Parameters:
agentName
- the name of the entitycurrentPosition
- the position to pick the resourcee
- ElementType to pickmaxQuantity
- maximum number of e that the agent is able to pick- Returns:
- the amount of resources that the agent was able to collect
-
dropOff
There can be only one safe of one unique type on a given location.- Specified by:
dropOff
in interfaceIEnvironment
- Parameters:
location
- id of the node where to drop the elemente
- the element the entity intends to dropquantity
- the amount of value to drop on the current position- Returns:
- true if the drop off was realised
-
throwGrenade
- Specified by:
throwGrenade
in interfaceIEnvironment
- Parameters:
agentName
- The name of the agent that is shootingtargetName
- the id of the room it aims at- Returns:
- true if done, false otherwise
-
isReachable
This method must be synchronized due tothe way graphStream computes the shortestPath- Specified by:
isReachable
in interfaceIEnvironment
- Parameters:
senderName
- name of the entity willing to send the messagereceiverName
- name of the receivercommunicationReach
- number of hops autorised to reach the targer- Returns:
- true if the receiver is within reach
-
getName
- Specified by:
getName
in interfaceIEnvironment
- Returns:
- The name of the environment
-
updateNodeInterfaceComRendering
-
updateCommunicationStats
public void updateCommunicationStats(int nbSent, int nbReceived) Update the nb of messages sent and effectively transmitted- Parameters:
nbSent
- number of messages sentnbReceived
- number of messages received (as the messages can be losts if agents are out of reach)
-
updateAgentsStatsWithinGui
public void updateAgentsStatsWithinGui() -
getAgentToKill
- Returns:
- the (local)name of the agent the user wants to terminate
-
getOoa
- Returns:
- Return the object used to the observer of the agent state and sent to the GUI for stat updating
-
getGuiController
- Returns:
- Method used by the user-controlled agent to connect him to the events the gui receives (to move the agent)
-
getUserChoosenPath
- Parameters:
agentName
- name of the agent controlled by the user- Returns:
- the node currently proposed as next destination to the user
-
updateUserChoosenPath
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
-