public interface AgentStatistics<T extends Agent<? extends GlobalState>> extends AgentSelection<T>, SerializableSupplier<AgentStatisticsResult<T>>, JSONValue
VertexAggregator
and Graph.selectVertices(Class)
that can be customised to provide attribute level statistics via
SummaryStatistics
. This allows common
statistics for agent attributes to be collected in a declarative manner, rather than implementing
custom VertexAggregator
implementations.
AgentStatistics<MyAgent> stats =
agentSystem.stats(MyAgent.class)
.field("balance", agent -> agent.balance)
.field("spending", agent -> agent.spending);
AgentStatistics also implements the JSONValue
interface, so it may be returned from
Variable
annotated methods directly.Modifier and Type | Method and Description |
---|---|
AgentStatistics<T> |
field(java.lang.String propertyName,
SerializableFunction<T,java.lang.Number> function)
Define a field to collect statistics for.
|
AgentStatistics<T> |
filter(SerializablePredicate<T> predicate)
Applies a filter to this selection.
|
stats
aggregate, count
AgentStatistics<T> filter(SerializablePredicate<T> predicate)
VertexSelection
SerializablePredicate
predicate will
be run on each agent, and its return value will determine if the agent remains in the selection
or not.filter
in interface AgentSelection<T extends Agent<? extends GlobalState>>
filter
in interface VertexSelection<T extends Agent<? extends GlobalState>>
predicate
- Predicate on agents of type AgentStatistics<T> field(java.lang.String propertyName, SerializableFunction<T,java.lang.Number> function)
propertyName
- Name for the field in the statistics results.function
- Function for extracting the field value from the agent.