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)

public class PropertyProbe<T> extends Probe
This probe inspects a field of type T on a group of agents.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PropertyProbe(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 Type
    Method
    Description
    void
    Makes all the agents leave the corresponding role at once.
    <A extends Agent>
    List<A>
    Returns a snapshot at moment t of the agents handling the group/role couple
    double
    Returns the average for the property over all the agents.
    Gets the community to which this activator/probe is binded to.
    Gets the group to which this activator/probe is binded to.
    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 specified Comparator.
    Returns the maximum for the property over all the agents.
    Returns the minimum for the property over all the agents.
    Gets the name.
    Returns the current value of the agent's field.
    Gets the role to which this activator/probe is binded to.
    boolean
    Checks if there is no agent in the group/role couple
    void
    Kills all the agents which are monitored.
    protected void
    onAdding(Agent agent)
    Automatically called when an agent joins the corresponding group and role.
    protected void
    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 initially null.
    int
    Returns the number of targeted agents.
    Returns a stream of the values of the property for each agent.
    returns a string containing the CGR location and the number of monitored agents.

    Methods inherited from class madkit.kernel.Probe

    findFieldOn

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PropertyProbe

      public PropertyProbe(String group, String role, String fieldName)
      Builds a new PropertyProbe considering a CGR location and the name of the class's field.
      Parameters:
      group - the group
      role - the role
      fieldName - the name of a field which is encapsulated in type T
  • Method Details

    • getPropertyValue

      public T getPropertyValue(Agent agent)
      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

      public void setPropertyValue(Agent agent, T value)
      Should be used to work with primitive types or fields which are initially null.
      Parameters:
      agent - the agent
      value - the value
    • getMax

      public T getMax()
      Returns the maximum for the property over all the agents. T must be a numerical type or Comparable for this to work, ClassCastException is thrown otherwise.
      Returns:
      the maximum value for this property
    • getMax

      public T getMax(Comparator<T> comparator) throws NoSuchElementException
      Returns the maximum for the property over all the agents using the specified Comparator. Moreover, the targeted group/role couple must not be empty, otherwise a NoSuchElementException is thrown.
      Parameters:
      comparator - the Comparator to use
      Returns:
      the maximum value for this property
      Throws:
      NoSuchElementException - if the probe is empty
    • getMin

      public T getMin()
      Returns the maximum for the property over all the agents. T must be a numerical type or Comparable for this to work, ClassCastException is thrown otherwise.
      Returns:
      the maximum value for this property
    • getMin

      public T getMin(Comparator<T> c) throws NoSuchElementException
      Returns the minimum for the property over all the agents.
      Parameters:
      c - the Comparator 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 extends Number for this to work, Moreover, the targeted groupp/role couple must not be empty, otherwise a NoSuchElementException is thrown.
      Returns:
      the maximum value for this property
    • streamValues

      public Stream<T> streamValues()
      Returns a stream of the values of the property for each agent.
      Returns:
      a stream of the values of the property for each agent
    • getCommunity

      public String getCommunity()
      Gets the community to which this activator/probe is binded to.
      Returns:
      a string representing the community's name
    • getGroup

      public String getGroup()
      Gets the group to which this activator/probe is binded to.
      Returns:
      a string representing the group's name
    • getRole

      public String getRole()
      Gets the role to which this activator/probe is binded to.
      Returns:
      a string representing the role's name
    • onAdding

      protected void onAdding(Agent agent)
      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

      protected void onRemoving(Agent agent)
      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

      public <A extends Agent> List<A> getAgents()
      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
    • toString

      public String toString()
      returns a string containing the CGR location and the number of monitored agents.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this tool.
    • getName

      public String getName()
      Gets the name.
      Returns:
      the name
    • 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.