Modify Globals

You can add a new or additional value to the globals struct with:

Vahana.push_global!Function
push_global!(sim::Simulation, name, value)

In the case that a field of the globals struct from the Simulation constructor is a vector (e.g. for time series data), push_global! can be used to add a value to this vector, instead of writing set_global!(sim, name, push!(get_global(sim, name), value).

In parallel simulations, push_global! must be called on all processes, and with identical value across all processes.

push_global! must not be called within a transition function.

See also create_model, mapreduce, set_global! and get_global

source
Vahana.modify_global!Function
modify_global!(sim::Simulation, name, f)

Modify the value of the name field of the globals structure for the simulation sim using the f function, which receives the current value as an argument.

This is a combination of set_global! and get_global: set_global!(sim, name, f(get_global(sim, name))).

modify_global! must not be called within a transition function.

In parallel simulations, push_global! must be called on all processes, and with identical value across all processes.

See also create_simulation, mapreduce, set_global! push_global! and get_global

source
Base.mapreduceFunction
mapreduce(sim, f, op, ::Type{T}; [kwargs ...])

Calculate an aggregated value, based on the state of all agents or edges of type T.

f is applied to all of these agents or edges and then op is used to reduce (aggregate) the values returned by f.

mapreduce is calling Base.mapreduce, f, op and kwargs are passed directly to mapreduce, while sim and T are used to determine the iterator.

source
Warning

The state of the globals struct (the globals argument of the create_simulation function can not be changed inside of a transition function, as a transition function is calculated on a per agent basis with many evaluations in parallel, and changes to the global layer must be a single, synchronized operation.