OptimizerBase.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef OPTIMIZERBASE_H
  2. #define OPTIMIZERBASE_H
  3. #include "IOptimizer.h"
  4. #include "exprtk.hpp"
  5. namespace mdd {
  6. ////////////////////////////////////////////////////////////
  7. //
  8. //Optimization is always minimization!
  9. //
  10. ////////////////////////////////////////////////////////////
  11. class OptimizerBase
  12. : public IOptimizer
  13. {
  14. protected:
  15. json _base_config;
  16. std::string key;
  17. const std::string type = "optimizer";
  18. std::shared_ptr<IModule> _module;
  19. std::vector<std::shared_ptr<IInput>> _inputs;
  20. std::vector<std::shared_ptr<IOutput>> _outputs;
  21. std::vector<double> _output_vals;
  22. exprtk::expression<double> _func_expr;
  23. struct opt_state {
  24. state module_state = state::STATE_ERROR;
  25. double opt_value = 0;
  26. };
  27. opt_state updateOutputs();
  28. OptimizerBase(const std::string& base_config);
  29. bool configureChild(const json& config) override;
  30. public:
  31. bool connect(std::shared_ptr<IModule> module) override;
  32. void updateLayout();
  33. bool setEvaluation(std::string func) override;
  34. bool configure(const json& config) override;
  35. const json& getConfiguration() override;
  36. //virtual std::string getGeneratorID() = 0;
  37. void load(const json& j);
  38. json dump();
  39. json getIdentifier() override;
  40. //state update() override;
  41. };
  42. }
  43. #endif