9#ifndef FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_FLEET_HPP
10#define FIMS_INTERFACE_RCPP_RCPP_OBJECTS_RCPP_FLEET_HPP
12#include "../../../common/def.hpp"
14#include "../../../population_dynamics/fleet/fleet.hpp"
35 static std::map<uint32_t, std::shared_ptr<FleetInterfaceBase>>
live_objects;
68std::map<uint32_t, std::shared_ptr<FleetInterfaceBase>>
78 SharedInt interface_observed_agecomp_data_id_m = -999;
82 SharedInt interface_observed_lengthcomp_data_id_m = -999;
86 SharedInt interface_observed_index_data_id_m = -999;
90 SharedInt interface_observed_landings_data_id_m = -999;
94 SharedInt interface_selectivity_id_m = -999;
169 std::shared_ptr<FleetInterface>
fleet =
170 std::make_shared<FleetInterface>(*
this);
184 interface_observed_agecomp_data_id_m(
185 other.interface_observed_agecomp_data_id_m),
186 interface_observed_lengthcomp_data_id_m(
187 other.interface_observed_lengthcomp_data_id_m),
188 interface_observed_index_data_id_m(
189 other.interface_observed_index_data_id_m),
190 interface_observed_landings_data_id_m(
191 other.interface_observed_landings_data_id_m),
192 interface_selectivity_id_m(
other.interface_selectivity_id_m),
282 return interface_observed_agecomp_data_id_m.
get();
290 return interface_observed_lengthcomp_data_id_m.
get();
297 return interface_observed_index_data_id_m.
get();
304 return interface_observed_landings_data_id_m.
get();
314 " has been finalized already.");
319 std::shared_ptr<fims_info::Information<double>>
info =
324 it =
info->fleets.find(this->
id);
328 " not found in Information.");
331 std::shared_ptr<fims_popdy::Fleet<double>>
fleet =
332 std::dynamic_pointer_cast<fims_popdy::Fleet<double>>(
it->second);
334 for (
size_t i = 0;
i < this->log_Fmort.
size();
i++) {
335 if (this->log_Fmort[
i].estimation_type_m.
get() ==
"constant") {
336 this->log_Fmort[
i].final_value_m = this->log_Fmort[
i].initial_value_m;
338 this->log_Fmort[
i].final_value_m =
fleet->log_Fmort[
i];
342 for (
size_t i = 0;
i < this->log_q.
size();
i++) {
343 if (this->log_q[
i].estimation_type_m.
get() ==
"constant") {
344 this->log_q[
i].final_value_m = this->log_q[
i].initial_value_m;
346 this->log_q[
i].final_value_m =
fleet->log_q[
i];
350 for (
size_t i = 0;
i <
fleet->age_to_length_conversion.size();
i++) {
351 if (this->age_to_length_conversion[
i].estimation_type_m.
get() ==
353 this->age_to_length_conversion[
i].final_value_m =
354 this->age_to_length_conversion[
i].initial_value_m;
356 this->age_to_length_conversion[
i].final_value_m =
357 fleet->age_to_length_conversion[
i];
365 template <
typename Type>
367 std::shared_ptr<fims_info::Information<Type>>
info =
370 std::shared_ptr<fims_popdy::Fleet<Type>>
fleet =
371 std::make_shared<fims_popdy::Fleet<Type>>();
373 std::stringstream
ss;
377 fleet->n_ages = this->n_ages.
get();
378 fleet->n_lengths = this->n_lengths.
get();
379 fleet->n_years = this->n_years.
get();
383 fleet->fleet_observed_agecomp_data_id_m =
384 interface_observed_agecomp_data_id_m.
get();
386 fleet->fleet_observed_lengthcomp_data_id_m =
387 interface_observed_lengthcomp_data_id_m.
get();
389 fleet->fleet_observed_index_data_id_m =
390 interface_observed_index_data_id_m.
get();
391 fleet->fleet_observed_landings_data_id_m =
392 interface_observed_landings_data_id_m.
get();
394 fleet->fleet_selectivity_id_m = interface_selectivity_id_m.
get();
397 for (
size_t i = 0;
i < this->log_q.
size();
i++) {
398 fleet->log_q[
i] = this->log_q[
i].initial_value_m;
400 if (this->log_q[
i].estimation_type_m.
get() ==
"fixed_effects") {
402 ss <<
"Fleet." << this->
id <<
".log_q." << this->log_q[
i].
id_m;
403 info->RegisterParameterName(
ss.str());
406 if (this->log_q[
i].estimation_type_m.
get() ==
"random_effects") {
408 ss <<
"Fleet." << this->
id <<
".log_q." << this->log_q[
i].
id_m;
409 info->RegisterRandomEffectName(
ss.str());
414 if (this->log_Fmort.
size() !=
static_cast<size_t>(this->n_years.
get())) {
415 FIMS_ERROR_LOG(
"The size of `log_Fmort` does not match `n_years`: " +
416 fims::to_string(this->log_Fmort.
size()) +
417 " != " + fims::to_string(
this->n_years.get()));
418 throw std::invalid_argument(
419 "Fleet log_Fmort size mismatch."
420 "Fleet log_Fmort is of size " +
421 fims::to_string(this->log_Fmort.
size()) +
422 " and the number of years is " +
423 fims::to_string(
this->n_years.get()));
425 fleet->log_Fmort.resize(
static_cast<size_t>(this->log_Fmort.
size()));
427 fleet->log_Fmort[
i] = this->log_Fmort[
i].initial_value_m;
429 if (this->log_Fmort[
i].estimation_type_m.
get() ==
"fixed_effects") {
431 ss <<
"Fleet." << this->
id <<
".log_Fmort." << this->log_Fmort[
i].
id_m;
432 info->RegisterParameterName(
ss.str());
435 if (this->log_Fmort[
i].estimation_type_m.
get() ==
"random_effects") {
437 ss <<
"Fleet." << this->
id <<
".log_Fmort." << this->log_Fmort[
i].
id_m;
438 info->RegisterRandomEffectName(
ss.str());
439 info->RegisterRandomEffect(
fleet->log_Fmort[
i]);
445 if (this->n_lengths.
get() > 0) {
447 this->age_to_length_conversion.
size());
449 if (this->age_to_length_conversion.
size() !=
450 static_cast<size_t>(this->n_ages.
get() * this->n_lengths.
get())) {
452 "age_to_length_conversion don't match, " +
453 fims::to_string(this->age_to_length_conversion.
size()) +
" != " +
454 fims::to_string((
this->n_ages.get() *
this->n_lengths.get())));
457 for (
size_t i = 0;
i <
fleet->age_to_length_conversion.size();
i++) {
458 fleet->age_to_length_conversion[
i] =
459 this->age_to_length_conversion[
i].initial_value_m;
461 if (this->age_to_length_conversion[
i].estimation_type_m.
get() ==
464 ss <<
"Fleet." << this->
id <<
".age_to_length_conversion."
465 << this->age_to_length_conversion[
i].
id_m;
466 info->RegisterParameterName(
ss.str());
467 info->RegisterParameter(
fleet->age_to_length_conversion[
i]);
469 if (this->age_to_length_conversion[
i].estimation_type_m.
get() ==
472 "age_to_length_conversion cannot be set to random effects");
476 info->variable_map[this->age_to_length_conversion.
id_m] =
Base class for all interface objects.
Definition rcpp_interface_base.hpp:575
bool finalized
Is the object already finalized? The default is false.
Definition rcpp_interface_base.hpp:580
static std::vector< std::shared_ptr< FIMSRcppInterfaceBase > > fims_interface_objects
FIMS interface object vectors.
Definition rcpp_interface_base.hpp:585
virtual bool add_to_fims_tmb()
A virtual method to inherit to add objects to the TMB model.
Definition rcpp_interface_base.hpp:590
Rcpp interface that serves as the parent class for Rcpp fleet interfaces. This type should be inherit...
Definition rcpp_fleet.hpp:20
static uint32_t id_g
The static id of the FleetInterfaceBase object.
Definition rcpp_fleet.hpp:25
FleetInterfaceBase()
The constructor.
Definition rcpp_fleet.hpp:40
uint32_t id
The local id of the FleetInterfaceBase object.
Definition rcpp_fleet.hpp:29
virtual ~FleetInterfaceBase()
The destructor.
Definition rcpp_fleet.hpp:57
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:52
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:35
The Rcpp interface for Fleet to instantiate from R: fleet <- methods::new(Fleet)
Definition rcpp_fleet.hpp:74
ParameterVector agecomp_expected
The vector of expected landings-at-age in numbers for the fleet.
Definition rcpp_fleet.hpp:146
ParameterVector 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:163
ParameterVector log_index_expected
The vector of natural log of the expected index of abundance for the fleet.
Definition rcpp_fleet.hpp:142
SharedInt n_years
The number of years in the fleet data.
Definition rcpp_fleet.hpp:112
ParameterVector agecomp_proportion
The vector of expected landings-at-age in numbers for the fleet.
Definition rcpp_fleet.hpp:154
uint32_t GetSelectivityID()
Get the unique ID for the selectivity object.
Definition rcpp_fleet.hpp:276
int GetObservedIndexDataID()
Get the unique id for the observed index data object.
Definition rcpp_fleet.hpp:296
ParameterVector log_landings_expected
The vector of natural log of the expected total landings for the fleet.
Definition rcpp_fleet.hpp:137
ParameterVector lengthcomp_expected
The vector of expected landings-at-length in numbers for the fleet.
Definition rcpp_fleet.hpp:150
FleetInterface(const FleetInterface &other)
Construct a new Fleet Interface object.
Definition rcpp_fleet.hpp:182
void SetObservedLengthCompDataID(int observed_lengthcomp_data_id)
Set the unique ID for the observed length-composition data object.
Definition rcpp_fleet.hpp:244
virtual void finalize()
Extracts the derived quantities from Information to the Rcpp object.
Definition rcpp_fleet.hpp:310
int GetObservedAgeCompDataID()
Get the unique ID for the observed age-composition data object.
Definition rcpp_fleet.hpp:281
void SetObservedAgeCompDataID(int observed_agecomp_data_id)
Set the unique ID for the observed age-composition data object.
Definition rcpp_fleet.hpp:236
virtual uint32_t get_id()
Gets the ID of the interface base object.
Definition rcpp_fleet.hpp:218
void SetSelectivityID(int selectivity_id)
Set the unique ID for the selectivity object.
Definition rcpp_fleet.hpp:267
ParameterVector log_q
The natural log of the index of abundance scaling parameter for this fleet.
Definition rcpp_fleet.hpp:127
virtual ~FleetInterface()
The destructor.
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:117
int GetObservedLengthCompDataID()
Get the unique ID for the observed length-composition data object.
Definition rcpp_fleet.hpp:289
ParameterVector log_Fmort
The vector of the natural log of fishing mortality rates for this fleet.
Definition rcpp_fleet.hpp:132
SharedString name
The name of the fleet.
Definition rcpp_fleet.hpp:100
SharedInt n_ages
The number of age bins in the fleet data.
Definition rcpp_fleet.hpp:104
void SetName(const std::string &name)
Sets the name of the fleet.
Definition rcpp_fleet.hpp:224
std::string GetName() const
Gets the name of the fleet.
Definition rcpp_fleet.hpp:230
FleetInterface()
The constructor.
Definition rcpp_fleet.hpp:168
SharedInt n_lengths
The number of length bins in the fleet data.
Definition rcpp_fleet.hpp:108
void SetObservedIndexDataID(int observed_index_data_id)
Set the unique ID for the observed index data object.
Definition rcpp_fleet.hpp:252
void SetObservedLandingsDataID(int observed_landings_data_id)
Set the unique ID for the observed landings data object.
Definition rcpp_fleet.hpp:260
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:122
ParameterVector lengthcomp_proportion
The vector of expected landings-at-length in numbers for the fleet.
Definition rcpp_fleet.hpp:158
int GetObservedLandingsDataID()
Get the unique id for the observed landings data object.
Definition rcpp_fleet.hpp:303
An Rcpp interface class that defines the ParameterVector class.
Definition rcpp_interface_base.hpp:143
void resize(size_t size)
Resizes a ParameterVector to the desired length.
Definition rcpp_interface_base.hpp:288
size_t size()
Returns the size of a ParameterVector.
Definition rcpp_interface_base.hpp:281
uint32_t id_m
The local ID of the Parameter object.
Definition rcpp_interface_base.hpp:156
Parameter & get(size_t pos)
An internal accessor for calling a position of a ParameterVector from R.
Definition rcpp_interface_base.hpp:260
A class that provides shared ownership of an integer value.
Definition rcpp_shared_primitive.hpp:24
void set(int val)
Change the value of the integer.
Definition rcpp_shared_primitive.hpp:129
int get() const
Retrieve the value of the integer.
Definition rcpp_shared_primitive.hpp:122
A class that provides shared ownership of a string.
Definition rcpp_shared_primitive.hpp:1508
std::string get() const
Retrieves the string value managed by the object.
Definition rcpp_shared_primitive.hpp:1612
#define FIMS_WARNING_LOG(MESSAGE)
Definition def.hpp:639
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:655
void clear_internal()
Clears the internal objects.
Definition rcpp_interface.hpp:235
The Rcpp interface to declare objects that are used ubiquitously throughout the Rcpp interface,...