public interface Graph<S extends java.io.Serializable> extends JSONValue
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 |
---|---|
default <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 java.io.Serializable> |
create(S global)
Create a new AgentSystem instance.
|
DoubleAccumulator |
createDoubleAccumulator(java.lang.String name,
java.lang.String displayName)
Create a new
DoubleAccumulator on the AgentSystem. |
LongAccumulator |
createLongAccumulator(java.lang.String name,
java.lang.String displayName)
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 |
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 |
registerVertexType(java.lang.Class<? extends Vertex<S>> type)
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.
|
static <S extends java.io.Serializable> Graph<S> create(S global)
Model.getConfig()
, and others. The instance will only be fully initialised and
agents created once 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 registerVertexType(java.lang.Class<? extends Vertex<S>> type)
This is currently unused.
type
- Agent classes to register. Must implement Agent.void registerMessageTypes(java.lang.Class<? extends Message>... types)
This is currently unused.
types
- void registerLinkTypes(java.lang.Class<? extends Link>... types)
This is currently unused.
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#setup(Environment)
will not be called when this method is used. If you need
agents to have a specific messaging phase for setup, see #setup(Object)
.
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.default <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 getLongAccumulator(java.lang.String name)
LongAccumulator
name
- The accumulator nameSimudyneSDKException
- if no accumulator of this name existsDoubleAccumulator getDoubleAccumulator(java.lang.String name)
DoubleAccumulator
name
- 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()
void beginStep()