gadget-framework/gadget2

quotafleet help to interpret the code

vbartolino opened this issue · 4 comments

it is great to have the new ices quotafleet type which assumes a linear increase in the quota level between biomass breakpoints.
It may well be because of my limited understanding of C++, but in 3b3cdf0#diff-18472b59e896caad1e517b862b268d7d I do not find where (in the new as well as the old code) the quotalevel is set for biomass above the last breakpoint such as biomass > biomasslevel[biomasslevel.Size()]
Any help?

bthe commented

Yes this is sort of the last bit remaining for a full ICES integration of gadget. I hacked this function together for a recent benchmark. You can use the gadget_project_* functions in Rgadget to generate a quotafleet using the following code:

  gadget_project_time(num_years = ny, variant_dir = 'pre') %>% 
  gadget_project_stocks(imm.file = 'gssimm',mat.file = 'gssmat') %>% 
  gadget_project_fleets(pre_fleet = 'comm',
                        fleet_type = 'quotafleet',
                        quotafunction = 'ices',
                        biomasslevel = list(b0=0,b1=btrigger*1e6), 
                        quotalevel = list(q0=0,q1=1,q2=1),
                        selectstocks = 'gssmat') 

Where you change the stockfiles appropriately.

Thanks for sharing the Rgadget implementation.
Actually, I was more unsure/interested about the C++ code in src/quotapredator.cc.
I do not understand how Gadget knows when to apply the last quotalevel given that in the code there's no statement such

if (biomass > biomasslevel[biomasslevel.Size()]) {
      quota = quotalevel[quotalevel.Size()];
}
bthe commented

Note that biomasslevel vector is one element shorter that the quotalevelvector and indexing in c++ is zero based. So the case when the selected stocks biomass exceeds the maximum level is handled by the following statement:

} else if (biomass > biomasslevel[biomasslevel.Size() - 1]) { # references the last point in the vector
      quota = quotalevel[biomasslevel.Size()];  # quotalevel is one element larger.. 
}    

thanks for clarification