evolve: Move the simulation forward one or more steps In particles: A Graph Based Particle Simulator Based on D3-Force

 evolve 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 `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

```graph <- tidygraph::create_notable('folkman')
sim <- graph |>
simulate() |>
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)

```

particles documentation built on Aug. 19, 2022, 5:06 p.m.