Add migration to a g3 model

g3a_migrate_normalize(row_total = 1)

g3a_migrate(stock, migrate_f, normalize_f = g3a_migrate_normalize(),
            run_f = TRUE,
            run_at = g3_action_order$migrate)

Arguments

row_total

When calculating the proportion of individuals that will stay in place, use this total for what rows are expected to sum to.

stock

The g3_stock that will migrate in this action.

migrate_f

A formula describing the migration in terms of (source) area and dest_area.

normalize_f

Function to normalize a vector of possible destinations, to make sure fish aren't added or destroyed.

run_f

formula specifying a condition for running this action, default always runs.

run_at

Integer order that spawning actions will be run within model, see g3_action_order.

Details

To restrict movement to a particular step in a year, or a particular area, use run_f. For example:

cur_step == 1

Migration will happen on first step of every year

cur_step == 1 && cur_year >= 1990

Migration will happen on first step of every year after 1990

cur_step == 2 && area = 1

Migration will happen on second step of every year, in the first area

Multiple migration actions can be added, for a separate spring and autumn migration, for instance.

The action will define the following stock instance variables for each given stock:

stock__migratematrix

\(a \times a\) array, containing proportion of (stock) moved from one area to another. If NaN, no movement has occurred

Value

g3a_migrate_normalize

A formula transforming stock__migratematrix[,stock__area_idx] (i.e. all possible destinations from a given area) by:

  1. Squaring so values are all positive

  2. Altering the proportion of static individuals so a row sums to row_total

  3. Dividing by row_total so a row sums to 1

g3a_migrate

An action (i.e. list of formula objects) that will, for the given stock...

  1. Fill in stock__migratematrix using migrate_f and normalize_f

  2. Apply movement to stock

See also

Examples

areas <- list(a=1, b=2, c=3, d=4)

# NB: stock doesn't live in b, so won't figure in stock_acd__migratematrix
stock_acd <- (g3_stock('stock_acd', seq(10, 40, 10))
    %>% g3s_livesonareas(areas[c('a', 'c', 'd')]))

movement_action <- list(
    g3a_migrate(
        stock_acd,
        # In spring, individuals in area 'a' will migrate to 'd'.
        ~if (area == area_a && dest_area == area_d) 0.8 else 0,
        run_f = ~cur_step == 2),
    g3a_migrate(
        stock_acd,
        # In autumn, individuals in all areas will migrate to 'a'
        ~if (dest_area == area_a) 0.8 else 0,
        run_f = ~cur_step == 4),
    list())