This function initiates a simulation based on the provided graph and
parameters. Any graph structure with a tidygraph::as_tbl_graph()
method
is supported as input. This function does not start the simulation but merely
sets it up.
simulate(
graph,
alpha = 1,
alpha_min = 0.001,
alpha_decay = 1 - alpha_min^(1/300),
alpha_target = 0,
velocity_decay = 0.4,
setup = phyllotactic_genesis(),
...
)is.simulation(x)
record(simulation, ...)
clear_history(simulation)
get_history(simulation, age = -1)
history_length(simulation)
reheat(simulation, alpha)
particles(simulation)
position(simulation)
velocity(simulation)
evolutions(simulation)
A simulation object
A graph in a format supported by tidygraph
The starting alpha value. See Details.
The minimum alpha value after which the simulation is terminated. See Details.
The speed at which the alpha value decreases. See Details.
The alpha value that alpha drifts towards. See Details.
The dampening factor of the system. See Details.
A function that takes the particle graph and returns a start
position and velocity to each particle. particles
provides a range of
genesis functions to choose from.
Additional parameters for the simulation (currently ignored)
A simulation object
The version to retrieve. Positive numbers count from the
beginning, while negative numbers counts backwards from current version.
Defaults to -1
.
record()
: Save the current state in the simulation's history
clear_history()
: Clear the current history from the simulation
get_history()
: Retrieve a simulation from the history
history_length()
: Get the number of versions stored in the history of the simulation
reheat()
: set the cooling of the simulation to a new value
particles()
: Extract the particle graph from a simulation
position()
: Extract the position coordinates from a simulation
velocity()
: Extract the velocity verlets from a simulation
evolutions()
: Get the number of generations the simulation has undergone
A simulation in the context of the particles package is a series of
equidistant steps where the velocity and position of each particle is
updated. A few global rules applies to this cycle irrespectively of the
forces added to the simulation. Once a simulation is initiated an alpha
value is defined (defaults to 1
). At each step this alpha value is
decreased according to its distance to the alpha_target
(defaults to 0
)
and alpha_decay
(defaults to ~0.023
). Once the alpha value gets below
alpha_min
(defaults to 0.001
) the simulation seizes to take additional
steps. The default values is adapted from the d3-force implementation and
corresponds to 300 steps. Conceptually the alpha
progression can be seen
as a cooling off of the system as the value decreases quickly in the
beginning and then slowly reach the target value. If it is not intended to
have a system that cools off, simply set the alpha_target
value to the same
as alpha
. At each step, after the new particle velocities has been
calculated but before they have been applied to the positions, a dampening
factor (velocity_decay
) is applied in order to simulate the gradual loss
of momentum. If this is not intended for the simulation, simply set the value
to 0
.
graph <- tidygraph::create_notable('folkman')
graph |>
simulate()
Run the code above in your browser using DataLab