R Under development (unstable) (2025-04-18 r88159 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(magrittr) > library(unittest) > > library(gadget3) > > prey_a <- g3_stock('prey_a', seq(1, 10)) > prey_b <- g3_stock('prey_b', seq(1, 10)) > fleet_totalfleet <- g3_fleet('fleet_totalfleet') > fleet_numberfleet <- g3_fleet('fleet_numberfleet') > fleet_linearfleet <- g3_fleet('fleet_linearfleet') > fleet_effortfleet <- g3_fleet('fleet_effortfleet') > fleet_quotafleet <- g3_fleet('fleet_quotafleet') > > actions <- list( + g3a_time(2000, 2005, step_lengths = c(6,6), project_years = 0), + g3a_initialconditions(prey_a, ~1e10 * prey_a__midlen, ~100 * prey_a__midlen), + g3a_initialconditions(prey_b, ~2e10 * prey_b__midlen, ~200 * prey_b__midlen), + g3a_predate_fleet( + fleet_totalfleet, + list(prey_a, prey_b), + suitabilities = list(prey_a = 0.1, prey_b = 0.1), + catchability_f = g3a_predate_catchability_totalfleet(10)), + g3a_predate_fleet( + fleet_numberfleet, + list(prey_a, prey_b), + suitabilities = list(prey_a = 0.1, prey_b = 0.1), + catchability_f = g3a_predate_catchability_numberfleet(10)), + g3a_predate_fleet( + fleet_linearfleet, + list(prey_a, prey_b), + suitabilities = list(prey_a = 0.1, prey_b = 0.1), + catchability_f = g3a_predate_catchability_linearfleet(1e-5)), + g3a_predate_fleet( + fleet_effortfleet, + list(prey_a, prey_b), + suitabilities = list(prey_a = 0.1, prey_b = 0.1), + catchability_f = g3a_predate_catchability_effortfleet(list(prey_a = 1e-3, prey_b= 1e-4), 10)), + g3a_predate_fleet( + fleet_quotafleet, + list(prey_a, prey_b), + suitabilities = list(prey_a = 0.1, prey_b = 0.1), + catchability_f = g3a_predate_catchability_quotafleet( + data.frame( + biomass = c(100, Inf), + quota = I(list(~g3_param('quota.low', value = 1e-9), ~g3_param('quota.high', value = 1e-5)))), + E = 2, + recalc_f = ~cur_step == 1)), + list()) > actions <- c(actions, list( + g3a_report_detail(actions) )) > > # Compile model > model_fn <- g3_to_r(actions, trace = FALSE) > # model_fn <- edit(model_fn) > if (nzchar(Sys.getenv('G3_TEST_TMB'))) { + model_cpp <- g3_to_tmb(actions, trace = FALSE) + # model_cpp <- edit(model_cpp) + model_tmb <- g3_tmb_adfun(model_cpp, compile_flags = c("-O0", "-g")) + } else { + writeLines("# skip: not compiling TMB model") + } # skip: not compiling TMB model > > ok_group("Catchability", { + params <- attr(model_fn, 'parameter_template') + + result <- model_fn(params) + r <- attributes(result) + # str(as.list(r), vec.len = 10000) + + # Make sure everything is internally consistent + ok(all(r$report_a__consratio > 0.9499), "report_a__consratio: No overconsumption") + ok(all(r$report_b__consratio > 0.9499), "report_b__consratio: No overconsumption") + for (time_idx in head(seq_along(dimnames(r$dstart_prey_b__num)$time), -1)) { + time_lbl <- dimnames(r$dstart_prey_b__num)$time[[time_idx]] + ok(ut_cmp_equal( + r$dstart_prey_a__num[,time = time_idx] * r$dstart_prey_a__wgt[,time = time_idx] - + r$detail_prey_a_fleet_totalfleet__cons[,time = time_idx] - + r$detail_prey_a_fleet_numberfleet__cons[,time = time_idx] - + r$detail_prey_a_fleet_linearfleet__cons[,time = time_idx] - + r$detail_prey_a_fleet_effortfleet__cons[,time = time_idx] - + r$detail_prey_a_fleet_quotafleet__cons[,time = time_idx], + r$dstart_prey_a__num[,time = time_idx + 1] * r$dstart_prey_a__wgt[,time = time_idx + 1], + tolerance = 1e-6), paste0(time_lbl, "/prey_a: Consumption and abundance consistent")) + ok(ut_cmp_equal( + r$dstart_prey_b__num[,time = time_idx] * r$dstart_prey_b__wgt[,time = time_idx] - + r$detail_prey_b_fleet_totalfleet__cons[,time = time_idx] - + r$detail_prey_b_fleet_numberfleet__cons[,time = time_idx] - + r$detail_prey_b_fleet_linearfleet__cons[,time = time_idx] - + r$detail_prey_b_fleet_effortfleet__cons[,time = time_idx] - + r$detail_prey_b_fleet_quotafleet__cons[,time = time_idx], + r$dstart_prey_b__num[,time = time_idx + 1] * r$dstart_prey_b__wgt[,time = time_idx + 1], + tolerance = 1e-6), paste0(time_lbl, "/prey_b: Consumption and abundance consistent")) + + ok(ut_cmp_equal( + colSums(r$detail_prey_a_fleet_totalfleet__cons + r$detail_prey_b_fleet_totalfleet__cons)[[time_idx]], + 10, + tolerance = 1e6), paste0(time_lbl, "/totalfleet: Total consumption adds to 10")) + ok(ut_cmp_equal( + colSums(r$detail_prey_a_fleet_numberfleet__cons / r$dstart_prey_a__wgt + r$detail_prey_b_fleet_numberfleet__cons / r$dstart_prey_b__wgt)[[time_idx]], + 10, + tolerance = 1e6), paste0(time_lbl, "/numberfleet: Total consumption in numbers adds to 10")) + + ok(ut_cmp_equal( + r$detail_prey_a_fleet_linearfleet__cons[,time_idx], + (r$dstart_prey_a__num * r$dstart_prey_a__wgt * 0.5 * 0.1 * 1e-5)[,time_idx], + tolerance = 1e6), paste0(time_lbl, "/prey_a/linearfleet: Total consumption proportion of overall stock")) + + ok(ut_cmp_equal( + r$detail_prey_b_fleet_linearfleet__cons[,time_idx], + (r$dstart_prey_b__num * r$dstart_prey_b__wgt * 0.5 * 0.1 * 1e-5)[,time_idx], + tolerance = 1e6), paste0(time_lbl, "/prey_b/linearfleet: Total consumption proportion of overall stock")) + + ok(ut_cmp_equal( + r$detail_prey_a_fleet_effortfleet__cons[,time_idx], + (r$dstart_prey_a__num * r$dstart_prey_a__wgt * 0.5 * 0.1 * 1e-3 * 10)[,time_idx], + tolerance = 1e6), paste0(time_lbl, "/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability)")) + ok(ut_cmp_equal( + r$detail_prey_b_fleet_effortfleet__cons[,time_idx], + (r$dstart_prey_b__num * r$dstart_prey_b__wgt * 0.5 * 0.1 * 1e-4 * 10)[,time_idx], + tolerance = 1e6), paste0(time_lbl, "/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability)")) + + ok(ut_cmp_equal( + r$detail_prey_a_fleet_quotafleet__cons[,time_idx], + (r$dstart_prey_a__num * r$dstart_prey_a__wgt * 0.5 * 0.1 * 1e-5 * 2)[,time_idx], + tolerance = 1e6), paste0(time_lbl, "/prey_a/quotafleet: Total consumption proportion of overall stock (high quota)")) + ok(ut_cmp_equal( + r$detail_prey_b_fleet_quotafleet__cons[,time_idx], + (r$dstart_prey_b__num * r$dstart_prey_b__wgt * 0.5 * 0.1 * 1e-5 * 2)[,time_idx], + tolerance = 1e6), paste0(time_lbl, "/prey_b/quotafleet: Total consumption proportion of overall stock (high quota)")) + } + if (nzchar(Sys.getenv('G3_TEST_TMB'))) { + param_template <- attr(model_cpp, "parameter_template") + param_template$value <- params[param_template$switch] + gadget3:::ut_tmb_r_compare(model_fn, model_tmb, param_template) + } + }) # Catchability ok - report_a__consratio: No overconsumption ok - report_b__consratio: No overconsumption ok - 2000-01/prey_a: Consumption and abundance consistent ok - 2000-01/prey_b: Consumption and abundance consistent ok - 2000-01/totalfleet: Total consumption adds to 10 ok - 2000-01/numberfleet: Total consumption in numbers adds to 10 ok - 2000-01/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2000-01/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2000-01/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2000-01/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2000-01/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2000-01/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2000-02/prey_a: Consumption and abundance consistent ok - 2000-02/prey_b: Consumption and abundance consistent ok - 2000-02/totalfleet: Total consumption adds to 10 ok - 2000-02/numberfleet: Total consumption in numbers adds to 10 ok - 2000-02/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2000-02/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2000-02/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2000-02/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2000-02/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2000-02/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2001-01/prey_a: Consumption and abundance consistent ok - 2001-01/prey_b: Consumption and abundance consistent ok - 2001-01/totalfleet: Total consumption adds to 10 ok - 2001-01/numberfleet: Total consumption in numbers adds to 10 ok - 2001-01/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2001-01/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2001-01/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2001-01/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2001-01/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2001-01/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2001-02/prey_a: Consumption and abundance consistent ok - 2001-02/prey_b: Consumption and abundance consistent ok - 2001-02/totalfleet: Total consumption adds to 10 ok - 2001-02/numberfleet: Total consumption in numbers adds to 10 ok - 2001-02/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2001-02/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2001-02/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2001-02/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2001-02/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2001-02/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2002-01/prey_a: Consumption and abundance consistent ok - 2002-01/prey_b: Consumption and abundance consistent ok - 2002-01/totalfleet: Total consumption adds to 10 ok - 2002-01/numberfleet: Total consumption in numbers adds to 10 ok - 2002-01/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2002-01/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2002-01/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2002-01/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2002-01/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2002-01/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2002-02/prey_a: Consumption and abundance consistent ok - 2002-02/prey_b: Consumption and abundance consistent ok - 2002-02/totalfleet: Total consumption adds to 10 ok - 2002-02/numberfleet: Total consumption in numbers adds to 10 ok - 2002-02/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2002-02/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2002-02/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2002-02/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2002-02/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2002-02/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2003-01/prey_a: Consumption and abundance consistent ok - 2003-01/prey_b: Consumption and abundance consistent ok - 2003-01/totalfleet: Total consumption adds to 10 ok - 2003-01/numberfleet: Total consumption in numbers adds to 10 ok - 2003-01/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2003-01/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2003-01/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2003-01/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2003-01/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2003-01/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2003-02/prey_a: Consumption and abundance consistent ok - 2003-02/prey_b: Consumption and abundance consistent ok - 2003-02/totalfleet: Total consumption adds to 10 ok - 2003-02/numberfleet: Total consumption in numbers adds to 10 ok - 2003-02/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2003-02/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2003-02/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2003-02/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2003-02/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2003-02/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2004-01/prey_a: Consumption and abundance consistent ok - 2004-01/prey_b: Consumption and abundance consistent ok - 2004-01/totalfleet: Total consumption adds to 10 ok - 2004-01/numberfleet: Total consumption in numbers adds to 10 ok - 2004-01/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2004-01/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2004-01/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2004-01/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2004-01/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2004-01/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2004-02/prey_a: Consumption and abundance consistent ok - 2004-02/prey_b: Consumption and abundance consistent ok - 2004-02/totalfleet: Total consumption adds to 10 ok - 2004-02/numberfleet: Total consumption in numbers adds to 10 ok - 2004-02/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2004-02/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2004-02/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2004-02/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2004-02/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2004-02/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2005-01/prey_a: Consumption and abundance consistent ok - 2005-01/prey_b: Consumption and abundance consistent ok - 2005-01/totalfleet: Total consumption adds to 10 ok - 2005-01/numberfleet: Total consumption in numbers adds to 10 ok - 2005-01/prey_a/linearfleet: Total consumption proportion of overall stock ok - 2005-01/prey_b/linearfleet: Total consumption proportion of overall stock ok - 2005-01/prey_a/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2005-01/prey_b/effortfleet: Total consumption proportion of overall stock (using prey catchability) ok - 2005-01/prey_a/quotafleet: Total consumption proportion of overall stock (high quota) ok - 2005-01/prey_b/quotafleet: Total consumption proportion of overall stock (high quota) > > proc.time() user system elapsed 4.71 0.25 4.95 1..112 # Looks like you passed all 112 tests.