st <- g3_stock("st", c(10))
fleets <- list(
# NB: We break down our fleet names into parts, g3_quota_hockeystick() will
# use the common name part (read: trawl) when naming parameters.
nor = g3_fleet(c(type = "trawl", country = "nor")),
oth = g3_fleet(c(type = "trawl", country = "oth")) )
# Define quota for both fleets, with an assessment in spring, application in autumn
fl_quota <- g3_quota(
g3_quota_hockeystick(fleets, list(st), preyprop_fs = 1, unit="harvest-rate"),
start_step = 4L,
run_revstep = -2L )
# Invent some historical landings tables for the sake of example
landings_trawl_nor <- expand.grid(year = 1990:1995, step = 2)
landings_trawl_nor$total_weight <- 1e6
landings_trawl_oth <- expand.grid(year = 1990:1995, step = 2)
landings_trawl_oth$total_weight <- 1e8
actions <- list(
g3a_time(1990, 1995, c(3,3,3,3)),
# Define st with steadily collapsing stock
g3a_otherfood(st, num_f = g3_timeareadata('st_abund', data.frame(
year = 1990:2050,
abund = 1e6 - 1e4 * seq(0, 2050-1990)), "abund"), wgt_f = 10),
# Fleet predation, both sharing the same quota
g3a_predate(
fleets$nor,
list(st),
suitabilities = 0.8,
catchability_f = g3a_predate_catchability_project(
# Use the (shared) quota when projecting, otherwise use historical landings
quota_f = fl_quota,
landings_f = g3_timeareadata("landings_trawl_nor", landings_trawl_nor) )),
g3a_predate(
fleets$oth,
list(st),
suitabilities = 0.8,
catchability_f = g3a_predate_catchability_project(
# Use the (shared) quota when projecting, otherwise use historical landings
quota_f = fl_quota,
landings_f = g3_timeareadata("landings_trawl_oth", landings_trawl_oth) )),
NULL )
model_fn <- g3_to_r(c(actions,
g3a_report_detail(actions),
g3a_report_history(actions, "__num$|__wgt$", out_prefix="dend_"), # NB: Late reporting
g3a_report_history(actions, "quota_", out_prefix = NULL) ))
attr(model_fn, "parameter_template") |>
# Project for 30 years
g3_init_val("project_years", 30) |>
# Quota is yearly, so specify cons.step parameters to divide up into steps
# Fishing predominantly occurs in spring/summer, none in winter
g3_init_val("trawl_*.cons.step.#", c(0.0, 0.5, 0.4, 0.1)) |>
# 3/4 of the quota goes to nor, the rest to oth
g3_init_val("trawl_nor.quota.prop", 0.75) |>
g3_init_val("trawl_oth.quota.prop", 0.25) |>
# Hockefleet: harvest rate & trigger biomass (shared across trawl_nor & trawl_oth)
g3_init_val("trawl.hs.target", 0.2) |>
g3_init_val("trawl.hs.trigger", 7.2e6) |>
identity() -> params.in
r <- attributes(model_fn(params.in))
## Total biomass at assessment point
g3_array_agg(r$dend_st__num * r$dend_st__wgt, "year", step = 2)
## Quota values, inflection once total biomass falls below btrigger
par(mar = c(6, 5, 1, 0)) ; barplot(r$quota_hockeystick_trawl__var, las = 2) ; abline(v=27.7)
## Consumption by fleet, demonstrating
## (a) fixed landings before projections (landings_trawl_nor)
## (b) inflection of hitting btrigger
## (c) Uneven spread of fishing effort throughout year (fl.quota.step.#)
barplot(g3_array_agg(r$detail_st_trawl_nor__cons, "time"), las = 2)
## Timing of calculations for fishing year
fl_quota <- g3_quota(
# Our quota values are year/step at the assessment time step
quote( cur_year * 10 + cur_step ),
year_length = 1L,
start_step = 4L,
interim_value = g3_parameterized("interim_value", value = 99, optimize = FALSE),
run_revstep = -3L )
yr <- as.integer(format(Sys.Date(), "%Y"))
actions <- list(
g3a_time(yr - 6, yr - 1, project_years = 10, step_lengths = rep(3L, 4)),
fl_quota,
# At each step in the model, print the current year/step, and the quota value that will get used
# NB: before projection, g3a_predate_catchability_project() will use landings data not the quota
g3_step(g3_formula(
writeLines(paste(cur_year, cur_step, if (cur_year_projection) q else "landings")),
q = fl_quota )),
NULL)
model_fn <- g3_to_r(c(actions,
g3a_report_history(actions, "quota_", out_prefix = NULL) ))
attr(model_fn(), "quota__var")
Run the code above in your browser using DataLab