Package madkit.simulation.probe
Class PropertyProbe<A extends AbstractAgent,T>
java.lang.Object
madkit.kernel.Probe<A>
madkit.simulation.probe.PropertyProbe<A,T>
- Type Parameters:
A
- the most common class type expected in this group (e.g. AbstractAgent)T
- the type of the property, i.e. Integer (this works if the field is an int, i.e. a primitive type)
This probe inspects fields of type T on agents of type A and its subclasses.
- Since:
- MaDKit 5.0.0.13
- Version:
- 5.1
- Author:
- Fabien Michel
-
Constructor Summary
ConstructorDescriptionPropertyProbe
(String community, String group, String role, String fieldName) Builds a new PropertyProbe considering a CGR location and the name of the class's field. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
This method is automatically called when an agent joins the corresponding group and role.protected void
Called when a list of agents joins the corresponding group and role.void
Makes all the agents leave the corresponding role at once.double
Returns the average value for the property over all the agents.Gets the community to which this activator/probe is binded to.Returns a snapshot at moment t of the agents handling the group/role couplegetGroup()
Gets the group to which this activator/probe is binded to.Returns the maximum for the property over all the agents.Returns the minimum for the property over all the agents.getPropertyValue
(A agent) Returns the current value of the agent's fieldgetRole()
Gets the role to which this activator/probe is binded to.Returns a ListIterator over the agents which is shuffledvoid
Called by the MaDKit kernel when the Activator or Probe is first added.void
Kills all the agents which are monitored.protected void
This method is automatically called when an agent leaves the corresponding group and role.protected void
This method is automatically called when a list of agents has leaved the corresponding group and role.void
setPropertyValue
(A agent, T value) Should be used to work with primitive types or fields which are initiallynull
int
size()
Returns the number of the agents handling the group/role coupletoString()
returns a string containing the CGR location and the number of monitored agents.Methods inherited from class madkit.kernel.Probe
findFieldOn
-
Constructor Details
-
Method Details
-
getPropertyValue
Returns the current value of the agent's field- Parameters:
agent
- the agent to probe- Returns:
- the actual value of the agent's field
-
setPropertyValue
Should be used to work with primitive types or fields which are initiallynull
- Parameters:
agent
-value
-
-
getMaxValue
Returns the maximum for the property over all the agents. The property must be numerical orComparable
for this to work.- Returns:
- the maximum value for this property
-
getMinValue
Returns the minimum for the property over all the agents. The property must be numerical orComparable
for this to work.- Returns:
- the minimum value for this property
-
getAverageValue
public double getAverageValue()Returns the average value for the property over all the agents. The property must be numerical for this to work.- Returns:
- the average value for this property
-
getCommunity
Gets the community to which this activator/probe is binded to.- Returns:
- a string representing the community's name
-
getGroup
Gets the group to which this activator/probe is binded to.- Returns:
- a string representing the group's name
-
getRole
Gets the role to which this activator/probe is binded to.- Returns:
- a string representing the role's name
-
initialize
public void initialize()Called by the MaDKit kernel when the Activator or Probe is first added. Default behavior is:adding(getCurrentAgentsList());
-
adding
Called when a list of agents joins the corresponding group and role. This method is automatically called by the MaDKit kernel when agents enter a role due to the use ofAbstractAgent.launchAgentBucket(String, int, String...)
. Override this method when you want to do some initialization on the agents that enter the group/role. Default implementation is:protected void adding(final List<A> agents) { for (A agent : agents) { adding(agent); } }
- Parameters:
agents
- the list of agents which have been added to this group/role at once.
-
adding
This method is automatically called when an agent joins the corresponding group and role. This method is empty by default. Override this method when you want to do some initialization when an agent enters the group/role.- Parameters:
agent
- which has been added to this group/role
-
removing
This method is automatically called when a list of agents has leaved the corresponding group and role. This method is empty by default. Override this method when you want to do some initialization on the agents that enter the group/role. Default implementation is:protected void removing(final List<A> agents) { for (A agent : agents) { removing(agent); } }
- Parameters:
agents
- the list of agents which have been removed from this group/role
-
removing
This method is automatically called when an agent leaves the corresponding group and role. This method is empty by default. Override this method when you want to do some work when an agent leaves the group/role. Note that the role is still handled by the agent when invoked.- Parameters:
agent
- the agent which is being removed from this group/role
-
size
public int size()Returns the number of the agents handling the group/role couple- Returns:
- the number of the agents that handle the group/role couple
-
getCurrentAgentsList
Returns a snapshot at moment t of the agents handling the group/role couple- Returns:
- a list view (a snapshot at moment t) of the agents that handle the group/role couple (in proper sequence)
- Since:
- MaDKit 3.0
-
getShuffledList
Returns a ListIterator over the agents which is shuffled- Returns:
- a ListIterator which has been previously shuffled
- Since:
- MaDKit 3.0
-
toString
returns a string containing the CGR location and the number of monitored agents. -
killAgents
public void killAgents()Kills all the agents which are monitored. -
allAgentsLeaveRole
public void allAgentsLeaveRole()Makes all the agents leave the corresponding role at once.
-