Class PropertyProbe<T>
java.lang.Object
madkit.kernel.Probe
madkit.simulation.PropertyProbe<T>
- Type Parameters:
T
- the type of the property, i.e. Integer (this works if the field is an int, i.e. a inspected primitive type should use its wrapper)
This probe inspects a field of type T on a group of agents.
-
Constructor Summary
ConstructorsConstructorDescriptionPropertyProbe
(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 TypeMethodDescriptionvoid
Makes all the agents leave the corresponding role at once.Returns a snapshot at moment t of the agents handling the group/role coupledouble
Returns the average for the property over all the agents.Gets the community to which this activator/probe is binded to.getGroup()
Gets the group to which this activator/probe is binded to.getMax()
Returns the maximum for the property over all the agents.getMax
(Comparator<T> comparator) Returns the maximum for the property over all the agents using the specifiedComparator
.getMin()
Returns the maximum for the property over all the agents.getMin
(Comparator<T> c) Returns the minimum for the property over all the agents.getName()
Gets the name.getPropertyValue
(Agent agent) Returns the current value of the agent's field.getRole()
Gets the role to which this activator/probe is binded to.boolean
isEmpty()
Checks if there is no agent in the group/role couplevoid
Kills all the agents which are monitored.protected void
Automatically called when an agent joins the corresponding group and role.protected void
onRemoving
(Agent agent) Automatically called when an agent leaves the corresponding group and role.void
setPropertyValue
(Agent agent, T value) Should be used to work with primitive types or fields which are initiallynull
.int
size()
Returns the number of targeted agents.Returns a stream of the values of the property for each agent.toString()
returns a string containing the CGR location and the number of monitored agents.Methods inherited from class madkit.kernel.Probe
findFieldOn
-
Constructor Details
-
PropertyProbe
-
-
Method Details
-
getPropertyValue
-
setPropertyValue
-
getMax
Returns the maximum for the property over all the agents. T must be a numerical type orComparable
for this to work,ClassCastException
is thrown otherwise.- Returns:
- the maximum value for this property
-
getMax
Returns the maximum for the property over all the agents using the specifiedComparator
. Moreover, the targeted group/role couple must not be empty, otherwise aNoSuchElementException
is thrown.- Parameters:
comparator
- theComparator
to use- Returns:
- the maximum value for this property
- Throws:
NoSuchElementException
- if the probe is empty
-
getMin
Returns the maximum for the property over all the agents. T must be a numerical type orComparable
for this to work,ClassCastException
is thrown otherwise.- Returns:
- the maximum value for this property
-
getMin
Returns the minimum for the property over all the agents.- Parameters:
c
- theComparator
to use- Returns:
- the maximum value for this property
- Throws:
NoSuchElementException
- if the probe is empty
-
getAverage
public double getAverage()Returns the average for the property over all the agents. T must extendsNumber
for this to work, Moreover, the targeted groupp/role couple must not be empty, otherwise aNoSuchElementException
is thrown.- Returns:
- the maximum value for this property
-
streamValues
-
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
-
onAdding
Automatically called when an agent joins the corresponding group and role. 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
-
onRemoving
Automatically called when an agent leaves the corresponding group and role. 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 targeted agents.- Returns:
- the number of targeted agents
-
isEmpty
public boolean isEmpty()Checks if there is no agent in the group/role couple- Returns:
- true, if no agent is handling the group/role couple
-
getAgents
-
toString
-
getName
-
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.
-