public interface Graph<S extends simudyne.core.graph.BaseGlobalState> extends JSONValue, Value
Vertex) and contain state (stored as normal fields
on the class instance). Agents can then interact with each other via message passing. An agent
has no direct access to any other agent within the system, everything must occur via messaging.
This choice means that systems can be transparently parallelized and distributed.
This approach to agent systems is heavily inspired by Pregel, a system developed by Google for large scale graph processing. A good introduction that may assist in understanding this approach is available here: https://blog.acolyer.org/2015/05/26/pregel-a-system-for-large-scale-graph-processing/
| Modifier and Type | Method and Description |
|---|---|
<T extends Vertex<S>> |
addVertices(java.lang.Class<T> vertexType,
long vertexCount)
Add a number of agents to the system.
|
<T extends Vertex<S>> |
addVertices(java.lang.Class<T> vertexType,
long vertexCount,
SerializableBiConsumer<InitContext,T> dataInjector)
Add a number of agents to the system.
|
void |
beginStep()
reset all the accumulator that haven't been flagged as persistent
|
static <S extends simudyne.core.graph.BaseGlobalState> |
create(S global,
ModelContext context,
Model model)
Create a new AgentSystem instance.
|
DoubleAccumulator |
createDoubleAccumulator(java.lang.String name,
java.lang.String displayName)
Create a new
DoubleAccumulator on the AgentSystem. |
DoubleAccumulator |
createDoubleAccumulator(java.lang.String name,
java.lang.String displayName,
double initialValue)
Create a new
DoubleAccumulator on the AgentSystem. |
LongAccumulator |
createLongAccumulator(java.lang.String name,
java.lang.String displayName)
Create a new
LongAccumulator on the AgentSystem. |
LongAccumulator |
createLongAccumulator(java.lang.String name,
java.lang.String displayName,
long initialValue)
Create a new
LongAccumulator on the AgentSystem. |
DoubleAccumulator |
getDoubleAccumulator(java.lang.String name)
Get a previously created
DoubleAccumulator |
java.util.Map<java.lang.String,DoubleAccumulator> |
getDoubleAccumulators()
Get all previously created
DoubleAccumulator as a read only map. |
S |
getGlobals()
Get the value of the global state that can be read globally by agents.
|
LongAccumulator |
getLongAccumulator(java.lang.String name)
Get a previously created
LongAccumulator |
java.util.Map<java.lang.String,LongAccumulator> |
getLongAccumulators()
Get all previously created
LongAccumulator as a read only map. |
long |
getNextVertexID()
Returns the next agent ID that will be assigned via
addVertices(java.lang.Class<T>, long). |
boolean |
hasProcessedMessages() |
boolean |
isSetup() |
void |
registerLinkTypes(java.lang.Class<? extends Link>... types)
Register link types with the system for serialisation.
|
void |
registerMessageTypes(java.lang.Class<? extends Message>... types)
Register message types with the system for serialisation.
|
void |
registerVertexTypes(java.lang.Class<? extends Vertex<S>>... types)
Register agent types with the system for serialisation.
|
<T extends Vertex> |
selectVertices(java.lang.Class<T> clazz)
Create a selection of agents from the system that can then be summarised.
|
void |
setup()
Initialise the agent system.
|
void |
step(Message message)
Run a messaging phase on the agents.
|
getSchema, getValues, receiveJSONemitData, registerSchemasstatic <S extends simudyne.core.graph.BaseGlobalState> Graph<S> create(S global, ModelContext context, Model model)
setup() is called.global - A global state object that can be read globally by agents. Values can be accessed
by agents by Environment.getGlobals()S getGlobals()
void registerVertexTypes(java.lang.Class<? extends Vertex<S>>... types)
types - Agent classes to register. Must implement Agent.void registerMessageTypes(java.lang.Class<? extends Message>... types)
types - void registerLinkTypes(java.lang.Class<? extends Link>... types)
types - void setup()
This will choose a suitable backend implementation given the current configuration. Any
agents defined via addVertices(Class, long) will then be created in the new instance.
Vertex.setEnvironment(Environment) will not be called when this method is used.
void step(Message message)
The given message will be broadcast to all agents, and a messaging super-step will be run
using the Vertex.step(Environment) handler.
message - Initial message to broadcast to the agents.<T extends Vertex<S>> void addVertices(java.lang.Class<T> vertexType, long vertexCount)
vertexType - vertexCount - <T extends Vertex<S>> void addVertices(java.lang.Class<T> vertexType, long vertexCount, SerializableBiConsumer<InitContext,T> dataInjector)
vertexType - vertexCount - dataInjector - long getNextVertexID()
addVertices(java.lang.Class<T>, long).<T extends Vertex> VertexSelection<T> selectVertices(java.lang.Class<T> clazz)
clazz - Class of the agents to select.LongAccumulator createLongAccumulator(java.lang.String name, java.lang.String displayName)
LongAccumulator on the AgentSystem.name - The accumulator namedisplayName - The name shown by the consoleDoubleAccumulator createDoubleAccumulator(java.lang.String name, java.lang.String displayName)
DoubleAccumulator on the AgentSystem.name - The accumulator namedisplayName - The name shown by the consoleLongAccumulator createLongAccumulator(java.lang.String name, java.lang.String displayName, long initialValue)
LongAccumulator on the AgentSystem.name - The accumulator namedisplayName - The name shown by the consoleinitialValue - For populating with a default value at initial time stepDoubleAccumulator createDoubleAccumulator(java.lang.String name, java.lang.String displayName, double initialValue)
DoubleAccumulator on the AgentSystem.name - The accumulator namedisplayName - The name shown by the consoleinitialValue - For populating with a default value at initial time stepLongAccumulator getLongAccumulator(java.lang.String name)
LongAccumulatorname - The accumulator nameSimudyneSDKException - if no accumulator of this name existsDoubleAccumulator getDoubleAccumulator(java.lang.String name)
DoubleAccumulatorname - The accumulator nameSimudyneSDKException - if no accumulator of this name existsjava.util.Map<java.lang.String,DoubleAccumulator> getDoubleAccumulators()
DoubleAccumulator as a read only map. Attempting to add
accumulators to this map will not work, and the accumulators will not be available on the
AgentSystem.JSONValue objectjava.util.Map<java.lang.String,LongAccumulator> getLongAccumulators()
LongAccumulator as a read only map. Attempting to add
accumulators to this map will not work, and the accumulators will not be available on the
AgentSystem.JSONValue objectboolean isSetup()
boolean hasProcessedMessages()
void beginStep()