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;
94 SharedInt interface_observed_index_data_id_m = -999;
98 SharedInt interface_observed_catch_data_id_m = -999;
102 SharedInt interface_selectivity_id_m = -999;
236 std::shared_ptr<FleetInterface> fleet =
237 std::make_shared<FleetInterface>(*
this);
251 interface_observed_agecomp_data_id_m(
252 other.interface_observed_agecomp_data_id_m),
253 interface_observed_lengthcomp_data_id_m(
254 other.interface_observed_lengthcomp_data_id_m),
255 interface_requires_age_length_mapping(
256 other.interface_requires_age_length_mapping),
257 interface_observed_index_data_id_m(
258 other.interface_observed_index_data_id_m),
259 interface_observed_catch_data_id_m(
260 other.interface_observed_catch_data_id_m),
261 interface_selectivity_id_m(other.interface_selectivity_id_m),
319 interface_observed_agecomp_data_id_m.
set(observed_agecomp_data_id);
327 interface_observed_lengthcomp_data_id_m.
set(observed_lengthcomp_data_id);
343 interface_requires_age_length_mapping.
set(requires_age_length_mapping);
351 interface_observed_index_data_id_m.
set(observed_index_data_id);
359 interface_observed_catch_data_id_m.
set(observed_catch_data_id);
366 interface_selectivity_id_m.
set(selectivity_id);
380 return interface_observed_agecomp_data_id_m.
get();
388 return interface_observed_lengthcomp_data_id_m.
get();
402 return interface_requires_age_length_mapping.
get();
409 return interface_observed_index_data_id_m.
get();
416 return interface_observed_catch_data_id_m.
get();
426 " has been finalized already.");
431 std::shared_ptr<fims_info::Information<double>> info =
436 it = info->
fleets.find(this->
id);
438 if (it == info->
fleets.end()) {
440 " not found in Information.");
443 std::shared_ptr<fims_popdy::Fleet<double>> fleet =
444 std::dynamic_pointer_cast<fims_popdy::Fleet<double>>(it->second);
446 for (
size_t i = 0; i < this->log_Fmort.
size(); i++) {
447 if (this->log_Fmort[i].estimation_type_m.
get() ==
"constant") {
448 this->log_Fmort[i].final_value_m = this->log_Fmort[i].initial_value_m;
450 this->log_Fmort[i].final_value_m = fleet->log_Fmort[i];
454 for (
size_t i = 0; i < this->log_q.
size(); i++) {
455 if (this->log_q[i].estimation_type_m.
get() ==
"constant") {
456 this->log_q[i].final_value_m = this->log_q[i].initial_value_m;
458 this->log_q[i].final_value_m = fleet->log_q[i];
462 for (
size_t i = 0; i < fleet->age_to_length_conversion.size(); i++) {
463 if (this->age_to_length_conversion[i].estimation_type_m.
get() ==
465 this->age_to_length_conversion[i].final_value_m =
466 this->age_to_length_conversion[i].initial_value_m;
468 this->age_to_length_conversion[i].final_value_m =
469 fleet->age_to_length_conversion[i];
477 template <
typename Type>
478 bool add_to_fims_tmb_internal() {
479 std::shared_ptr<fims_info::Information<Type>> info =
482 std::shared_ptr<fims_popdy::Fleet<Type>> fleet =
483 std::make_shared<fims_popdy::Fleet<Type>>();
485 std::stringstream ss;
488 fleet->id = this->
id;
489 fleet->n_ages = this->n_ages.
get();
490 fleet->n_lengths = this->n_lengths.
get();
491 fleet->n_years = this->n_years.
get();
495 fleet->fleet_observed_agecomp_data_id_m =
496 interface_observed_agecomp_data_id_m.
get();
498 fleet->fleet_observed_lengthcomp_data_id_m =
499 interface_observed_lengthcomp_data_id_m.
get();
500 fleet->requires_age_length_mapping =
501 interface_requires_age_length_mapping.
get();
503 fleet->fleet_observed_index_data_id_m =
504 interface_observed_index_data_id_m.
get();
505 fleet->fleet_observed_catch_data_id_m =
506 interface_observed_catch_data_id_m.
get();
508 fleet->fleet_selectivity_id_m = interface_selectivity_id_m.
get();
510 fleet->log_q.resize(this->log_q.
size());
511 for (
size_t i = 0; i < this->log_q.
size(); i++) {
512 fleet->log_q[i] = this->log_q[i].initial_value_m;
514 if (this->log_q[i].estimation_type_m.
get() ==
"fixed_effects") {
516 ss <<
"Fleet." << this->
id <<
".log_q." << this->log_q[i].
id_m;
517 info->RegisterParameterName(ss.str());
518 info->RegisterParameter(fleet->log_q[i]);
520 if (this->log_q[i].estimation_type_m.
get() ==
"random_effects") {
522 ss <<
"Fleet." << this->
id <<
".log_q." << this->log_q[i].
id_m;
523 info->RegisterRandomEffectName(ss.str());
524 info->RegisterRandomEffect(fleet->log_q[i]);
528 if (this->log_Fmort.
size() !=
static_cast<size_t>(this->n_years.
get())) {
529 FIMS_ERROR_LOG(
"The size of `log_Fmort` does not match `n_years`: " +
530 fims::to_string(this->log_Fmort.
size()) +
531 " != " + fims::to_string(this->n_years.get()));
532 throw std::invalid_argument(
533 "Fleet log_Fmort size mismatch."
534 "Fleet log_Fmort is of size " +
535 fims::to_string(this->log_Fmort.
size()) +
536 " and the number of years is " +
537 fims::to_string(this->n_years.get()));
539 fleet->log_Fmort.resize(
static_cast<size_t>(this->log_Fmort.
size()));
541 fleet->log_Fmort[i] = this->log_Fmort[i].initial_value_m;
543 if (this->log_Fmort[i].estimation_type_m.
get() ==
"fixed_effects") {
545 ss <<
"Fleet." << this->
id <<
".log_Fmort." << this->log_Fmort[i].
id_m;
546 info->RegisterParameterName(ss.str());
547 info->RegisterParameter(fleet->log_Fmort[i]);
549 if (this->log_Fmort[i].estimation_type_m.
get() ==
"random_effects") {
551 ss <<
"Fleet." << this->
id <<
".log_Fmort." << this->log_Fmort[i].
id_m;
552 info->RegisterRandomEffectName(ss.str());
553 info->RegisterRandomEffect(fleet->log_Fmort[i]);
557 info->variable_map[this->log_Fmort.
id_m] = &(fleet)->
log_Fmort;
559 if (this->n_lengths.
get() > 0) {
560 if (this->lengths.
size() !=
static_cast<size_t>(this->n_lengths.
get())) {
561 FIMS_ERROR_LOG(
"The size of `lengths` does not match `n_lengths`: " +
562 fims::to_string(this->lengths.
size()) +
563 " != " + fims::to_string(this->n_lengths.get()));
564 throw std::invalid_argument(
565 "Fleet lengths size mismatch. Fleet lengths is of size " +
566 fims::to_string(this->lengths.
size()) +
567 " and the number of lengths is " +
568 fims::to_string(this->n_lengths.get()));
571 fleet->lengths.resize(this->lengths.
size());
572 for (
size_t i = 0; i < fleet->lengths.size(); i++) {
573 fleet->lengths[i] = this->lengths[i];
576 fleet->age_to_length_conversion.
resize(
577 this->age_to_length_conversion.
size());
579 const size_t expected_age_to_length_conversion_size =
580 static_cast<size_t>(this->n_ages.
get() * this->n_lengths.
get());
581 const size_t supplied_age_to_length_conversion_size =
582 this->age_to_length_conversion.
size();
584 if (supplied_age_to_length_conversion_size != 0 &&
585 supplied_age_to_length_conversion_size !=
586 expected_age_to_length_conversion_size) {
588 "age_to_length_conversion size mismatch, " +
589 fims::to_string(supplied_age_to_length_conversion_size) +
590 " != " + fims::to_string(expected_age_to_length_conversion_size));
591 throw std::invalid_argument(
592 "Fleet age_to_length_conversion size mismatch. Expected " +
593 fims::to_string(expected_age_to_length_conversion_size) +
594 " values but received " +
595 fims::to_string(supplied_age_to_length_conversion_size) +
".");
598 for (
size_t i = 0; i < fleet->age_to_length_conversion.size(); i++) {
599 fleet->age_to_length_conversion[i] =
600 this->age_to_length_conversion[i].initial_value_m;
602 if (this->age_to_length_conversion[i].estimation_type_m.
get() ==
605 ss <<
"Fleet." << this->
id <<
".age_to_length_conversion."
606 << this->age_to_length_conversion[i].
id_m;
607 info->RegisterParameterName(ss.str());
608 info->RegisterParameter(fleet->age_to_length_conversion[i]);
610 if (this->age_to_length_conversion[i].estimation_type_m.
get() ==
613 "age_to_length_conversion cannot be set to random effects");
617 info->variable_map[this->age_to_length_conversion.
id_m] =
622 info->fleets[fleet->id] = fleet;
632 this->add_to_fims_tmb_internal<TMB_FIMS_REAL_TYPE>();
633 this->add_to_fims_tmb_internal<TMBAD_FIMS_TYPE>();
Base class for all interface objects.
Definition rcpp_interface_base.hpp:656
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:661
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:666
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:671
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
bool GetRequiresAgeLengthMapping()
Return whether this fleet requires age-to-length mapping.
Definition rcpp_fleet.hpp:401
SharedInt n_years
The number of years in the fleet data.
Definition rcpp_fleet.hpp:124
uint32_t GetSelectivityID()
Get the unique ID for the selectivity object.
Definition rcpp_fleet.hpp:374
VariableVector catch_numbers_at_age
Annual catch at age in numbers for a specific fleet.
Definition rcpp_fleet.hpp:156
int GetObservedIndexDataID()
Get the unique id for the observed index data object.
Definition rcpp_fleet.hpp:408
VariableVector catch_weight
Total catch in weight for a specific fleet.
Definition rcpp_fleet.hpp:168
VariableVector index_numbers_at_length
Numbers at length for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:204
int GetObservedCatchDataID()
Get the unique id for the observed catch data object.
Definition rcpp_fleet.hpp:415
VariableVector agecomp_proportion
Proportion of total catch by age used to specify the age composition.
Definition rcpp_fleet.hpp:187
FleetInterface(const FleetInterface &other)
Construct a new Fleet Interface object.
Definition rcpp_fleet.hpp:249
void SetObservedLengthCompDataID(int observed_lengthcomp_data_id)
Set the unique ID for the observed length-composition data object.
Definition rcpp_fleet.hpp:326
virtual void finalize()
Extracts the derived quantities from Information to the Rcpp object.
Definition rcpp_fleet.hpp:422
int GetObservedAgeCompDataID()
Get the unique ID for the observed age-composition data object.
Definition rcpp_fleet.hpp:379
void SetObservedAgeCompDataID(int observed_agecomp_data_id)
Set the unique ID for the observed age-composition data object.
Definition rcpp_fleet.hpp:318
void SetRequiresAgeLengthMapping(bool requires_age_length_mapping)
Set whether this fleet requires age-to-length mapping.
Definition rcpp_fleet.hpp:342
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_fleet.hpp:300
void SetSelectivityID(int selectivity_id)
Set the unique ID for the selectivity object.
Definition rcpp_fleet.hpp:365
virtual ~FleetInterface()
The destructor.
Definition rcpp_fleet.hpp:294
VariableVector catch_weight_at_age
Annual catch at age in weight for a specific fleet.
Definition rcpp_fleet.hpp:160
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:217
VariableVector lengthcomp_expected
Expected length-composition proportions for the fleet.
Definition rcpp_fleet.hpp:230
void SetObservedCatchDataID(int observed_catch_data_id)
Set the unique ID for the observed catch data object.
Definition rcpp_fleet.hpp:358
int GetObservedLengthCompDataID()
Get the unique ID for the observed length-composition data object.
Definition rcpp_fleet.hpp:387
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:150
SharedString name
The name of the fleet.
Definition rcpp_fleet.hpp:108
SharedInt n_ages
The number of age bins in the fleet data.
Definition rcpp_fleet.hpp:112
void SetName(const std::string &name)
Sets the name of the fleet.
Definition rcpp_fleet.hpp:306
VariableVector lengthcomp_proportion
Proportion of total catch by length used to specify the length composition.
Definition rcpp_fleet.hpp:192
VariableVector log_q
The natural log of the index of abundance scaling parameter for this fleet.
Definition rcpp_fleet.hpp:139
std::string GetName() const
Gets the name of the fleet.
Definition rcpp_fleet.hpp:312
VariableVector index_weight_at_age
Weight at age for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:200
VariableVector index_weight
Total weight for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:208
VariableVector log_catch_expected
Log total expected catch for a specific fleet, where the units of the measurement depend on the speci...
Definition rcpp_fleet.hpp:182
SharedString observed_catch_units
What units are the observed catch for this fleet measured in. Options are weight or numbers,...
Definition rcpp_fleet.hpp:129
VariableVector log_Fmort
The vector of the natural log of fishing mortality rates for this fleet.
Definition rcpp_fleet.hpp:144
FleetInterface()
The constructor.
Definition rcpp_fleet.hpp:235
SharedInt n_lengths
The number of length bins in the fleet data.
Definition rcpp_fleet.hpp:116
VariableVector index_numbers
Total numbers for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:212
VariableVector catch_numbers
Total catch in numbers for a specific fleet.
Definition rcpp_fleet.hpp:172
VariableVector agecomp_expected
Expected age-composition proportions for the fleet.
Definition rcpp_fleet.hpp:226
void SetObservedIndexDataID(int observed_index_data_id)
Set the unique ID for the observed index data object.
Definition rcpp_fleet.hpp:350
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:134
RealVector lengths
Fleet-specific observation-bin centers.
Definition rcpp_fleet.hpp:120
VariableVector index_numbers_at_age
Numbers at age for a fleet index such as survey or CPUE.
Definition rcpp_fleet.hpp:196
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:222
VariableVector catch_expected
Total expected catch for a specific fleet, where the units of the measurement depend on the specified...
Definition rcpp_fleet.hpp:177
VariableVector catch_numbers_at_length
Annual catch at length in numbers for a specific fleet.
Definition rcpp_fleet.hpp:164
An Rcpp interface class that defines the RealVector class.
Definition rcpp_interface_base.hpp:432
size_t size()
Returns the size of a RealVector.
Definition rcpp_interface_base.hpp:603
void resize(size_t size)
Resizes a RealVector to the desired length.
Definition rcpp_interface_base.hpp:610
A class that provides shared ownership of a boolean value.
Definition rcpp_shared_primitive.hpp:1704
void set(bool val)
Sets the boolean value of the object.
Definition rcpp_shared_primitive.hpp:1818
bool get() const
Retrieves the boolean value managed by the object.
Definition rcpp_shared_primitive.hpp:1809
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
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
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...