Execute preliminary calculations in a conservation problem and store the results for later use. This function is useful when creating slightly different versions of the same conservation planning problem that involve the same pre-processing steps (e.g., calculating boundary data), because means that the same calculations will not be run multiple times.

run_calculations(x)

## Arguments

x

problem() (i.e., ConservationProblem) object.

## Value

Invisible TRUE indicating success.

## Details

This function is used for the effect of modifying the input ConservationProblem object. As such, it does not return anything. To use this function with pipe() operators, use the %T>% operator and not the %>% operator.

## Examples

# \dontrun{
# Let us imagine a scenario where we wanted to understand the effect of
# setting different targets on our solution.

# create a conservation problem with no targets
p <- problem(sim_pu_raster, sim_features) %>%

# create a copies of p and add targets

# now solve each of the different problems and record the time spent
# solving them
s1 <- system.time({solve(p1); solve(p2); solve(p3)})

# This approach is inefficient. Since these problems all share the same
# planning units it is actually performing the same calculations three times.
# To avoid this, we can use the "run_calculations" function before creating
# the copies. Normally, R runs the calculations just before solving the
# problem

# recreate a conservation problem with no targets and tell R run the
# preliminary calculations. Note how we use the %T>% operator here.
p <- problem(sim_pu_raster, sim_features) %>%
run_calculations()

# create a copies of p and add targets just like before

# solve each of the different problems and record the time spent
# solving them
s2 <- system.time({solve(p1); solve(p2); solve(p3)})

# now lets compare the times
print(s1) # time spent without running preliminary calculations
#>    user  system elapsed
#>   1.267   0.001   1.319
print(s2) # time spent after running preliminary calculations
#>    user  system elapsed
#>   1.197   0.012   1.239

# As we can see, we can save time by running the preliminary
# calculations before making copies of the problem with slightly
# different constraints. Although the time saved in this example
# is rather small, this is because the example data are very small.
# We would expect larger time savings for larger datasets.
# }