evolve: Move the simulation forward one or more steps

Description Usage Arguments Details Value Examples

View source: R/evolve.R

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

1
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 TRUE if the simulation should proceed and FALSE if it should stop. If NULL the simulation will run until alpha_min has been reached.

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 on_generation

Details

Each generation in the simulation progress in the following manner:

  1. Check whether the specified number of generations has been reached

  2. Check whether alpha_min has been reached

  3. If either 1. or 2. is true, terminate the simulation

  4. Apply the forces on the current particle positions and velocities in the order they have been added

  5. Reduce the velocity according to the given velocity_decay

  6. Update the position and velocity based on any provided constraints

  7. Calculate the new particle positions based on the new velocity

  8. If given, call the on_generation function.

Value

A simulation object with updated positions and velocities

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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)

thomasp85/particles documentation built on Jan. 15, 2019, 2:25 a.m.