diff --git a/fwdpy11/headers/fwdpy11/genetic_values/fwdpp_wrappers/fwdpp_genetic_value.hpp b/fwdpy11/headers/fwdpy11/genetic_values/fwdpp_wrappers/fwdpp_genetic_value.hpp index fde032eaa9..80ae930083 100644 --- a/fwdpy11/headers/fwdpy11/genetic_values/fwdpp_wrappers/fwdpp_genetic_value.hpp +++ b/fwdpy11/headers/fwdpy11/genetic_values/fwdpp_wrappers/fwdpp_genetic_value.hpp @@ -4,7 +4,7 @@ #include #include #include "../DiploidGeneticValue.hpp" -#include +#include #include namespace fwdpy11 @@ -26,7 +26,7 @@ namespace fwdpy11 } inline double - operator()(const fwdpp::site_dependent_genetic_value& gv, + operator()(const fwdpy11::site_dependent_genetic_value& gv, const std::size_t diploid_index, const DiploidMetadata& /*metadata*/, const DiploidPopulation& pop) const @@ -47,7 +47,7 @@ namespace fwdpy11 } inline double - operator()(const fwdpp::site_dependent_genetic_value& gv, + operator()(const fwdpy11::site_dependent_genetic_value& gv, const std::size_t diploid_index, const DiploidMetadata& metadata, const DiploidPopulation& pop) const { @@ -75,7 +75,7 @@ namespace fwdpy11 }; using callback_type = std::function; using make_return_value_t = std::function; @@ -90,7 +90,7 @@ namespace fwdpy11 return multi_deme_callback(aa_scaling); } - fwdpp::site_dependent_genetic_value gv; + fwdpy11::site_dependent_genetic_value gv; double aa_scaling; make_return_value_t make_return_value; callback_type callback; diff --git a/fwdpy11/headers/fwdpy11/genetic_values/site_dependent_fitness.hpp b/fwdpy11/headers/fwdpy11/genetic_values/site_dependent_fitness.hpp new file mode 100644 index 0000000000..8c609a7415 --- /dev/null +++ b/fwdpy11/headers/fwdpy11/genetic_values/site_dependent_fitness.hpp @@ -0,0 +1,218 @@ +#pragma once + +#include + +namespace fwdpy11 +{ + struct site_dependent_genetic_value + { + //! The return value type + using result_type = double; + + template + inline result_type + operator()(iterator_t first1, iterator_t last1, iterator_t first2, + iterator_t last2, const MutationContainerType &mutations, + const updating_policy_hom &fpol_hom, + const updating_policy_het &fpol_het, + const make_return_value &rv_function, + const double starting_value) const noexcept + /*! + Range-based call operator. Calculates genetic values over ranges of + mutation keys first1/last1 + and first2/last2, which are iterators derived from the 'smutations' + of two haploid_genomes in a diploid. + + \param first1 Iterator to first mutation derived from haploid_genome 1 + \param last1 Iterator to one past the last mutation derived from + haploid_genome 1 + \param first2 Iterator to first mutation derived from haploid_genome 2 + \param last2 Iterator to one past the last mutation derived from + haploid_genome 2 + \param mutations The container of mutations for the simulation + \param fpol_hom Policy that updates genetic value for a homozygous + mutation. + \param fpol_het Policy that updates genetic value for a heterozygous + mutation. + \param make_return_value Policy generated the final return value. + Must be equivalent to std::function + \param starting_value The initial genetic value. + + \returns Fitness (double) + */ + { + static_assert(fwdpp::traits::is_mutation< + typename MutationContainerType::value_type>::value, + "MutationContainerType::value_type must be a mutation type"); + static_assert( + std::is_convertible< + updating_policy_hom, + std::function>::value, + "decltype(fpol_hom) must be convertible to " + "std::function>::value, + "decltype(fpol_het) must be convertible to " + "std::function + inline result_type + operator()(iterator_t first1, iterator_t last1, iterator_t first2, + iterator_t last2, const MutationContainerType &mutations, + const updating_policy_hom &fpol_hom, + const updating_policy_het &fpol_het, + const double starting_value) const noexcept + { + return this->operator()( + first1, last1, first2, last2, mutations, fpol_hom, fpol_het, + [](double d) { return d; }, starting_value); + } + + template + inline result_type + operator()(const HaploidGenomeType &g1, const HaploidGenomeType &g2, + const MutationContainerType &mutations, + const updating_policy_hom &fpol_hom, + const updating_policy_het &fpol_het, + const make_return_value &rv_function, + const double starting_value) const noexcept + /*! + Calculates genetic value for a diploid whose genotype + across sites is given by haploid_genomes g1 and g2. + + \param g1 A haploid_genome + \param g2 A haploid_genome + \param mutations The container of mutations for the simulation + \param fpol_hom Policy that updates genetic value for a homozygous + mutation. + \param fpol_het Policy that updates genetic value for a heterozygous + mutation. + \param starting_value The initial genetic value. + + \returns Fitness (double) + */ + { + static_assert(fwdpp::traits::is_haploid_genome::value, + "HaploidGenomeType::value_type must be a haploid_genome " + "type"); + return this->operator()(g1.smutations.cbegin(), g1.smutations.cend(), + g2.smutations.cbegin(), g2.smutations.cend(), + mutations, fpol_hom, fpol_het, rv_function, + starting_value); + } + + template + inline result_type + operator()(const HaploidGenomeType &g1, const HaploidGenomeType &g2, + const MutationContainerType &mutations, + const updating_policy_hom &fpol_hom, + const updating_policy_het &fpol_het, + const double starting_value) const noexcept + { + return this->operator()( + g1, g2, mutations, fpol_hom, fpol_het, [](double d) { return d; }, + starting_value); + } + + template + inline result_type + operator()(const DiploidType &dip, const GenomeContainerType &haploid_genomes, + const MutationContainerType &mutations, + const updating_policy_hom &fpol_hom, + const updating_policy_het &fpol_het, + const make_return_value &rv_function, + const double starting_value) const noexcept + /*! + Calculates genetic value for a diploid type. + + \param dip A diploid + \param haploid_genomes The container of haploid_genomes for the simulation. + \param mutations The container of mutations for the simulation + \param fpol_hom Policy that updates genetic value for a homozygous + mutation. + \param fpol_het Policy that updates genetic value for a heterozygous + mutation. + \param starting_value The initial genetic value. + + \returns Fitness (double) + */ + { + return this->operator()(haploid_genomes[dip.first], + haploid_genomes[dip.second], mutations, fpol_hom, + fpol_het, rv_function, starting_value); + } + + template + inline result_type + operator()(const DiploidType &dip, const GenomeContainerType &haploid_genomes, + const MutationContainerType &mutations, + const updating_policy_hom &fpol_hom, + const updating_policy_het &fpol_het, + const double starting_value) const noexcept + { + return this->operator()( + dip, haploid_genomes, mutations, fpol_hom, fpol_het, + [](double d) { return d; }, starting_value); + } + }; +}