evolve {particles} | R Documentation |
Move the simulation forward one or more steps
Description
This is the function that move the simulation forward in time. It is possible
to either specify the number of steps that should be simulated or let the
simulation terminate as alpha_min
is reached. Note that some values of
alpha
and alpha_target
does not allow alpha to converge to alpha_min
so
letting the simulation self-terminate can result in an infinite loop. The
default settings will result in alpha_min
being reached in 300 generations.
Usage
evolve(simulation, steps = NULL, on_generation = NULL, ...)
Arguments
simulation |
A simulation object |
steps |
The number of generations to progress or a function getting the
simulation object and returns |
on_generation |
A function to be called after each generation has been progressed. The function will get the current state of the simulation as the first argument. If the function returns a simulation object it will replace the current simulation from the next generation. In the case of any other return type the return will be discarded and the function will have no effect outside its side-effects. |
... |
Additional arguments to |
Details
Each generation in the simulation progress in the following manner:
Check whether the specified number of generations has been reached
Check whether
alpha_min
has been reachedIf either 1. or 2. is true, terminate the simulation
Apply the forces on the current particle positions and velocities in the order they have been added
Reduce the velocity according to the given
velocity_decay
Update the position and velocity based on any provided constraints
Calculate the new particle positions based on the new velocity
If given, call the
on_generation
function.
Value
A simulation object with updated positions and velocities
Examples
graph <- tidygraph::create_notable('folkman')
sim <- graph |>
simulate() |>
wield(link_force) |>
wield(manybody_force)
# Take 5 steps and tell about it
sim |> evolve(5, function(sim) {
cat('Generation: ', evolutions(sim), '\n', sep = '')
})
# Run evolution until alpha_min is reached
sim |> evolve(NULL)