Scine::Readuct  6.0.0
This is the SCINE module ReaDuct.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
CostCombinerEditor.h
Go to the documentation of this file.
1 
8 #ifndef READUCT_ELEMENTARYSTEPOPTIMIZATION_COSTCALCULATORS_COSTCOMBINEREDITOR_H
9 #define READUCT_ELEMENTARYSTEPOPTIMIZATION_COSTCALCULATORS_COSTCOMBINEREDITOR_H
10 
11 #include "CostCalculatorEditor.h"
12 #include "CostCombiner.h"
15 
16 // TODO: Improve documentation
17 
18 namespace Scine {
19 namespace Readuct {
20 
21 namespace ElementaryStepOptimization {
22 
23 namespace CostBasedOptimization {
24 
25 /* typedef for the combiner class from the editor types instead of from the classes themselves. */
26 template<typename E1, typename E2>
27 using Combiner = CostCombiner<typename E1::InstanceClass, typename E2::InstanceClass>;
28 
34 template<typename E1, typename E2>
35 class CostCombinerEditor : public CostCalculatorEditorImpl<Combiner<E1, E2>> {
36  static constexpr const char* description = "Combined cost calculator";
37  static constexpr const char* factorKey = "first_weight";
38  static constexpr const char* factorDescription = "Weight for first calculator (between 0 and 1)";
39 
40  public:
41  CostCombinerEditor(std::string key1, std::string key2)
42  : calculator1Key_(std::move(key1)), calculator2Key_(std::move(key2)) {
43  }
44 
45  Utils::UniversalSettings::DescriptorCollection getSettingDescriptors() const override {
46  Utils::UniversalSettings::DescriptorCollection descriptors(description);
47 
48  Utils::UniversalSettings::DoubleDescriptor weight(factorDescription);
49  weight.setMinimum(0);
50  weight.setMaximum(1);
52 
53  auto descriptors1 = editor1_.getSettingDescriptors();
54  auto descriptors2 = editor2_.getSettingDescriptors();
55 
56  descriptors.push_back(calculator1Key_, std::move(descriptors1));
57  descriptors.push_back(calculator2Key_, std::move(descriptors2));
58  descriptors.push_back(factorKey, std::move(weight));
59  return descriptors;
60  }
61 
62  private:
63  void applyImpl(Combiner<E1, E2>& instance, const Utils::UniversalSettings::ValueCollection& values) const override {
64  editor1_.apply(instance.firstCalculator(), values.getCollection(calculator1Key_));
65  editor2_.apply(instance.secondCalculator(), values.getCollection(calculator2Key_));
66  instance.setFirstCalculatorContribution(values.getDouble(factorKey));
67  }
68 
69  Utils::UniversalSettings::ValueCollection getAppliedSettingsImpl(const Combiner<E1, E2>& instance) const override {
71 
72  auto firstCalculatorValues = editor1_.getAppliedSettings(instance.firstCalculator());
73  auto secondCalculatorValues = editor2_.getAppliedSettings(instance.secondCalculator());
74 
75  values.addCollection(calculator1Key_, std::move(firstCalculatorValues));
76  values.addCollection(calculator2Key_, std::move(secondCalculatorValues));
77  values.addDouble(factorKey, instance.getFirstCalculatorContribution());
78  return values;
79  }
80 
81  std::string calculator1Key_;
82  std::string calculator2Key_;
83  E1 editor1_;
84  E2 editor2_;
85 };
86 
87 } // namespace CostBasedOptimization
88 
89 } // namespace ElementaryStepOptimization
90 
91 } // namespace Readuct
92 } // namespace Scine
93 #endif // READUCT_ELEMENTARYSTEPOPTIMIZATION_COSTCALCULATORS_COSTCOMBINEREDITOR_H
void setFirstCalculatorContribution(double f)
Definition: CostCombiner.h:37