9#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_FLEET_HPP
10#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_FLEET_HPP
13#include "../../../population_dynamics/fleet/fleet.hpp"
34 static std::map<uint32_t, std::shared_ptr<FleetInterfaceBase>>
live_objects;
72 SharedInt interface_observed_agecomp_data_id_m = -999;
76 SharedInt interface_observed_lengthcomp_data_id_m = -999;
80 SharedInt interface_observed_index_data_id_m = -999;
84 SharedInt interface_observed_landings_data_id_m = -999;
88 SharedInt interface_selectivity_id_m = -999;
218 std::shared_ptr<FleetInterface>
fleet =
219 std::make_shared<FleetInterface>(*
this);
233 interface_observed_agecomp_data_id_m(
234 other.interface_observed_agecomp_data_id_m),
235 interface_observed_lengthcomp_data_id_m(
236 other.interface_observed_lengthcomp_data_id_m),
237 interface_observed_index_data_id_m(
238 other.interface_observed_index_data_id_m),
239 interface_observed_landings_data_id_m(
240 other.interface_observed_landings_data_id_m),
241 interface_selectivity_id_m(
other.interface_selectivity_id_m),
343 return interface_observed_agecomp_data_id_m.
get();
351 return interface_observed_lengthcomp_data_id_m.
get();
358 return interface_observed_index_data_id_m.
get();
365 return interface_observed_landings_data_id_m.
get();
375 " has been finalized already.");
380 std::shared_ptr<fims_info::Information<double>>
info =
385 it =
info->fleets.find(this->
id);
389 " not found in Information.");
392 std::shared_ptr<fims_popdy::Fleet<double>>
fleet =
393 std::dynamic_pointer_cast<fims_popdy::Fleet<double>>(
it->second);
395 for (
size_t i = 0;
i < this->log_Fmort.
size();
i++) {
396 if (this->log_Fmort[
i].estimation_type_m.
get() ==
"constant") {
397 this->log_Fmort[
i].final_value_m = this->log_Fmort[
i].initial_value_m;
399 this->log_Fmort[
i].final_value_m =
fleet->log_Fmort[
i];
403 for (
size_t i = 0;
i < this->log_q.
size();
i++) {
404 if (this->log_q[
i].estimation_type_m.
get() ==
"constant") {
405 this->log_q[
i].final_value_m = this->log_q[
i].initial_value_m;
407 this->log_q[
i].final_value_m =
fleet->log_q[
i];
411 for (
size_t i = 0;
i <
fleet->age_to_length_conversion.size();
i++) {
412 if (this->age_to_length_conversion[
i].estimation_type_m.
get() ==
414 this->age_to_length_conversion[
i].final_value_m =
415 this->age_to_length_conversion[
i].initial_value_m;
417 this->age_to_length_conversion[
i].final_value_m =
418 fleet->age_to_length_conversion[
i];
426 template <
typename Type>
428 std::shared_ptr<fims_info::Information<Type>>
info =
431 std::shared_ptr<fims_popdy::Fleet<Type>>
fleet =
432 std::make_shared<fims_popdy::Fleet<Type>>();
434 std::stringstream
ss;
438 fleet->n_ages = this->n_ages.
get();
439 fleet->n_lengths = this->n_lengths.
get();
440 fleet->n_years = this->n_years.
get();
444 fleet->fleet_observed_agecomp_data_id_m =
445 interface_observed_agecomp_data_id_m.
get();
447 fleet->fleet_observed_lengthcomp_data_id_m =
448 interface_observed_lengthcomp_data_id_m.
get();
450 fleet->fleet_observed_index_data_id_m =
451 interface_observed_index_data_id_m.
get();
452 fleet->fleet_observed_landings_data_id_m =
453 interface_observed_landings_data_id_m.
get();
455 fleet->fleet_selectivity_id_m = interface_selectivity_id_m.
get();
458 for (
size_t i = 0;
i < this->log_q.
size();
i++) {
459 fleet->log_q[
i] = this->log_q[
i].initial_value_m;
461 if (this->log_q[
i].estimation_type_m.
get() ==
"fixed_effects") {
463 ss <<
"Fleet." << this->
id <<
".log_q." << this->log_q[
i].
id_m;
464 info->RegisterParameterName(
ss.str());
467 if (this->log_q[
i].estimation_type_m.
get() ==
"random_effects") {
469 ss <<
"Fleet." << this->
id <<
".log_q." << this->log_q[
i].
id_m;
470 info->RegisterRandomEffectName(
ss.str());
475 if (this->log_Fmort.
size() !=
static_cast<size_t>(this->n_years.
get())) {
476 FIMS_ERROR_LOG(
"The size of `log_Fmort` does not match `n_years`: " +
477 fims::to_string(this->log_Fmort.
size()) +
478 " != " + fims::to_string(
this->n_years.get()));
479 throw std::invalid_argument(
480 "Fleet log_Fmort size mismatch."
481 "Fleet log_Fmort is of size " +
482 fims::to_string(this->log_Fmort.
size()) +
483 " and the number of years is " +
484 fims::to_string(
this->n_years.get()));
486 fleet->log_Fmort.resize(
static_cast<size_t>(this->log_Fmort.
size()));
488 fleet->log_Fmort[
i] = this->log_Fmort[
i].initial_value_m;
490 if (this->log_Fmort[
i].estimation_type_m.
get() ==
"fixed_effects") {
492 ss <<
"Fleet." << this->
id <<
".log_Fmort." << this->log_Fmort[
i].
id_m;
493 info->RegisterParameterName(
ss.str());
496 if (this->log_Fmort[
i].estimation_type_m.
get() ==
"random_effects") {
498 ss <<
"Fleet." << this->
id <<
".log_Fmort." << this->log_Fmort[
i].
id_m;
499 info->RegisterRandomEffectName(
ss.str());
500 info->RegisterRandomEffect(
fleet->log_Fmort[
i]);
506 if (this->n_lengths.
get() > 0) {
508 this->age_to_length_conversion.
size());
510 if (this->age_to_length_conversion.
size() !=
511 static_cast<size_t>(this->n_ages.
get() * this->n_lengths.
get())) {
513 "age_to_length_conversion don't match, " +
514 fims::to_string(this->age_to_length_conversion.
size()) +
" != " +
515 fims::to_string((
this->n_ages.get() *
this->n_lengths.get())));
518 for (
size_t i = 0;
i <
fleet->age_to_length_conversion.size();
i++) {
519 fleet->age_to_length_conversion[
i] =
520 this->age_to_length_conversion[
i].initial_value_m;
522 if (this->age_to_length_conversion[
i].estimation_type_m.
get() ==
525 ss <<
"Fleet." << this->
id <<
".age_to_length_conversion."
526 << this->age_to_length_conversion[
i].
id_m;
527 info->RegisterParameterName(
ss.str());
528 info->RegisterParameter(
fleet->age_to_length_conversion[
i]);
530 if (this->age_to_length_conversion[
i].estimation_type_m.
get() ==
533 "age_to_length_conversion cannot be set to random effects");
537 info->variable_map[this->age_to_length_conversion.
id_m] =
Base class for all interface objects.
Definition rcpp_interface_base.hpp:628
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:633
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:638
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:643
Rcpp interface that serves as the parent class for Rcpp fleet interfaces. This type should be inherit...
Definition rcpp_fleet.hpp:19
static uint32_t id_g
The static id of the FleetInterfaceBase object.
Definition rcpp_fleet.hpp:24
FleetInterfaceBase()
The constructor.
Definition rcpp_fleet.hpp:39
uint32_t id
The local id of the FleetInterfaceBase object.
Definition rcpp_fleet.hpp:28
virtual ~FleetInterfaceBase()
The destructor.
Definition rcpp_fleet.hpp:56
virtual uint32_t get_id()=0
Get the ID for the child fleet interface objects to inherit.
FleetInterfaceBase(const FleetInterfaceBase &other)
Construct a new Fleet Interface Base object.
Definition rcpp_fleet.hpp:51
static std::map< uint32_t, std::shared_ptr< FleetInterfaceBase > > live_objects
The map associating the IDs of FleetInterfaceBase to the objects. This is a live object,...
Definition rcpp_fleet.hpp:34
The Rcpp interface for Fleet to instantiate from R: fleet <- methods::new(Fleet)
Definition rcpp_fleet.hpp:68
VariableVector landings_expected
Total expected landings for a specific fleet, where the units of the measurement depend on the specif...
Definition rcpp_fleet.hpp:159
SharedInt n_years
The number of years in the fleet data.
Definition rcpp_fleet.hpp:106
uint32_t GetSelectivityID()
Get the unique ID for the selectivity object.
Definition rcpp_fleet.hpp:337
int GetObservedIndexDataID()
Get the unique id for the observed index data object.
Definition rcpp_fleet.hpp:357
VariableVector index_numbers_at_length
Numbers at length for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:186
VariableVector agecomp_proportion
Proportion of total landings by age used to specify the age composition.
Definition rcpp_fleet.hpp:169
FleetInterface(const FleetInterface &other)
Construct a new Fleet Interface object.
Definition rcpp_fleet.hpp:231
void SetObservedLengthCompDataID(int observed_lengthcomp_data_id)
Set the unique ID for the observed length-composition data object.
Definition rcpp_fleet.hpp:305
virtual void finalize()
Extracts the derived quantities from Information to the Rcpp object.
Definition rcpp_fleet.hpp:371
int GetObservedAgeCompDataID()
Get the unique ID for the observed age-composition data object.
Definition rcpp_fleet.hpp:342
void SetObservedAgeCompDataID(int observed_agecomp_data_id)
Set the unique ID for the observed age-composition data object.
Definition rcpp_fleet.hpp:297
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_fleet.hpp:279
void SetSelectivityID(int selectivity_id)
Set the unique ID for the selectivity object.
Definition rcpp_fleet.hpp:328
virtual ~FleetInterface()
The destructor.
Definition rcpp_fleet.hpp:273
VariableVector landings_numbers_at_length
Annual landings at length in numbers for a specific fleet.
Definition rcpp_fleet.hpp:146
VariableVector index_expected
Expected value for a fleet index, where the units of the measurement depend on the specified units fo...
Definition rcpp_fleet.hpp:199
VariableVector lengthcomp_expected
Expected length-composition proportions for the fleet.
Definition rcpp_fleet.hpp:212
SharedString observed_landings_units
What units are the observed landings for this fleet measured in. Options are weight or numbers,...
Definition rcpp_fleet.hpp:111
int GetObservedLengthCompDataID()
Get the unique ID for the observed length-composition data object.
Definition rcpp_fleet.hpp:350
VariableVector age_to_length_conversion
The vector of conversions to go from age to length, i.e., the age-to-length-conversion matrix.
Definition rcpp_fleet.hpp:132
SharedString name
The name of the fleet.
Definition rcpp_fleet.hpp:94
SharedInt n_ages
The number of age bins in the fleet data.
Definition rcpp_fleet.hpp:98
void SetName(const std::string &name)
Sets the name of the fleet.
Definition rcpp_fleet.hpp:285
VariableVector lengthcomp_proportion
Proportion of total landings by length used to specify the length composition.
Definition rcpp_fleet.hpp:174
VariableVector log_q
The natural log of the index of abundance scaling parameter for this fleet.
Definition rcpp_fleet.hpp:121
std::string GetName() const
Gets the name of the fleet.
Definition rcpp_fleet.hpp:291
VariableVector index_weight_at_age
Weight at age for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:182
VariableVector index_weight
Total weight for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:190
VariableVector landings_numbers_at_age
Annual landings at age in numbers for a specific fleet.
Definition rcpp_fleet.hpp:138
VariableVector log_Fmort
The vector of the natural log of fishing mortality rates for this fleet.
Definition rcpp_fleet.hpp:126
FleetInterface()
The constructor.
Definition rcpp_fleet.hpp:217
SharedInt n_lengths
The number of length bins in the fleet data.
Definition rcpp_fleet.hpp:102
VariableVector index_numbers
Total numbers for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:194
VariableVector landings_weight
Total landings in weight for a specific fleet.
Definition rcpp_fleet.hpp:150
VariableVector agecomp_expected
Expected age-composition proportions for the fleet.
Definition rcpp_fleet.hpp:208
VariableVector landings_numbers
Total landings in numbers for a specific fleet.
Definition rcpp_fleet.hpp:154
VariableVector landings_weight_at_age
Annual landings at age in weight for a specific fleet.
Definition rcpp_fleet.hpp:142
void SetObservedIndexDataID(int observed_index_data_id)
Set the unique ID for the observed index data object.
Definition rcpp_fleet.hpp:313
void SetObservedLandingsDataID(int observed_landings_data_id)
Set the unique ID for the observed landings data object.
Definition rcpp_fleet.hpp:321
SharedString observed_index_units
What units is the observed index of abundance for this fleet measured in. Options are weight or numbe...
Definition rcpp_fleet.hpp:116
VariableVector index_numbers_at_age
Numbers at age for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:178
VariableVector log_index_expected
Log expected value for a fleet index, where the units of the measurement depend on the specified unit...
Definition rcpp_fleet.hpp:204
int GetObservedLandingsDataID()
Get the unique id for the observed landings data object.
Definition rcpp_fleet.hpp:364
VariableVector log_landings_expected
Log total expected landings for a specific fleet, where the units of the measurement depend on the sp...
Definition rcpp_fleet.hpp:164
A class that provides shared ownership of an integer value.
Definition rcpp_shared_primitive.hpp:29
void set(int val)
Change the value of the integer.
Definition rcpp_shared_primitive.hpp:134
int get() const
Retrieve the value of the integer.
Definition rcpp_shared_primitive.hpp:127
A class that provides shared ownership of a string.
Definition rcpp_shared_primitive.hpp:1513
std::string get() const
Retrieves the string value managed by the object.
Definition rcpp_shared_primitive.hpp:1617
An Rcpp interface class that defines the VariableVector class.
Definition rcpp_interface_base.hpp:144
Variable & get(size_t pos)
An internal accessor for calling a position of a VariableVector from R.
Definition rcpp_interface_base.hpp:267
uint32_t id_m
The local ID of the Variable object.
Definition rcpp_interface_base.hpp:157
void resize(size_t size)
Resizes a VariableVector to the desired length.
Definition rcpp_interface_base.hpp:295
size_t size()
Returns the size of a VariableVector.
Definition rcpp_interface_base.hpp:288
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:648
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:664
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:236
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...