8 #ifndef READUCT_ELEMENTARYSTEPOPTIMIZATION_COSTCALCULATORS_COSTCOMBINER_H
9 #define READUCT_ELEMENTARYSTEPOPTIMIZATION_COSTCALCULATORS_COSTCOMBINER_H
19 namespace ElementaryStepOptimization {
21 namespace CostBasedOptimization {
28 template<
typename C1,
typename C2>
30 static_assert(std::is_base_of<ReactionPathCostCalculator, C1>::value,
31 "C1 must be a descendant of ReactionPathCostCalculator");
32 static_assert(std::is_base_of<ReactionPathCostCalculator, C2>::value,
33 "C2 must be a descendant of ReactionPathCostCalculator");
38 assert(0.0 <= f && f <= 1.0);
39 contributionFromFirstCalculator_ = f;
42 double getFirstCalculatorContribution()
const {
43 return contributionFromFirstCalculator_;
53 const ReactionPathCostCalculator& secondCalculator()
const {
56 ReactionPathCostCalculator& secondCalculator() {
60 static constexpr
double defaultContributionFromFirstCalculator = 0.5;
63 std::unique_ptr<ReactionPathCostCalculator> cloneImpl()
const override {
64 return std::make_unique<CostCombiner<C1, C2>>(*this);
67 bool energiesRequiredImpl()
const override {
71 void calculateCostImpl(
const Utils::BSplines::BSpline& spline,
const EnergiesAndGradientsAlongSpline& energyValues)
override {
72 calculator1_.calculateCost(spline, energyValues);
73 calculator2_.calculateCost(spline, energyValues);
76 double getCostImpl()
const override {
77 double f1 = contributionFromFirstCalculator_;
80 return f1 * calculator1_.getCost() + f2 * calculator2_.getCost();
83 Eigen::MatrixXd getCostDerivativesImpl()
const override {
84 double f1 = contributionFromFirstCalculator_;
87 return f1 * calculator1_.getCostDerivatives() + f2 * calculator2_.getCostDerivatives();
90 double contributionFromFirstCalculator_ = defaultContributionFromFirstCalculator;
101 #endif // READUCT_ELEMENTARYSTEPOPTIMIZATION_COSTCALCULATORS_COSTCOMBINER_H
Interface for the cost calculation of reaction paths.
Definition: ReactionPathCostCalculator.h:39
void setFirstCalculatorContribution(double f)
Definition: CostCombiner.h:37
Definition: CostCombiner.h:29
bool energiesRequired() const
Whether energies (and their gradients) are required in the cost calculation.
Definition: ReactionPathCostCalculator.h:89