[修改]修改了错误的exporter名称

This commit is contained in:
makotocc0107
2024-09-04 09:51:10 +08:00
committed by Coding
parent 211a89778c
commit d93daaab6b
37 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
add_library(simulation-manager INTERFACE)
target_sources(
simulation-manager
INTERFACE
simulation_manager.hpp
)
target_include_directories(
simulation-manager
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../include
)
target_link_libraries(
simulation-manager
INTERFACE
periodic-interference
step
temperature-drift
white-noise
)
#add_executable(simulation-manager main.cpp simulation_manager.hpp algorithm_wrap.hpp)

View File

@@ -0,0 +1,68 @@
//
// Created by fly on 2022/4/21.
//
#ifndef FAULT_SIMULATION_ALGORITHM_ALGORITHM_WRAP_HPP
#define FAULT_SIMULATION_ALGORITHM_ALGORITHM_WRAP_HPP
#include <algorithm.hpp>
#include <utility>
class algorithm_wrap : public algorithm {
public:
explicit algorithm_wrap(std::shared_ptr<algorithm> algo) {
algorithm_ = std::move(algo);
}
bool enable() const {
return enable_;
}
void set_enable(bool flag) {
enable_ = flag;
}
int duration_period() const {
return duration_period_;
}
void set_duration_period(int durationPeriod) {
duration_period_ = durationPeriod;
}
void set_config(nlohmann::json const &config) override {
if (algorithm_) {
algorithm_->set_config(config);
if (config.contains("enable") && config["enable"].is_boolean()) {
set_enable(config["enable"].get<bool>());
}
}
}
nlohmann::json config() override {
nlohmann::json config;
config["enable"] = enable();
if (algorithm_) {
return algorithm_->config();
}
return config;
}
double eval(double value) override {
if (algorithm_ && enable_ && duration_period_) {
if (duration_period_ > 0) {
--duration_period_;
}
return algorithm_->eval(value);
}
return value;
}
private:
std::shared_ptr<algorithm> algorithm_;
bool enable_ = false;
int duration_period_ = -1;
};
#endif //FAULT_SIMULATION_ALGORITHM_ALGORITHM_WRAP_HPP

View File

@@ -0,0 +1,10 @@
//
// Created by fly on 2022/4/21.
//
#include "simulation_manager.hpp"
int main(int argc, char *argv) {
return 0;
}

View File

@@ -0,0 +1,106 @@
//
// Created by fly on 2022/4/21.
//
#ifndef FAULT_SIMULATION_ALGORITHM_SIMULATION_MANAGER_HPP
#define FAULT_SIMULATION_ALGORITHM_SIMULATION_MANAGER_HPP
#include "algorithm_wrap.hpp"
#include <periodic_interference.h>
#include <step.h>
#include <white_noise.h>
#include <temperature_drift.h>
#include <spdlog/spdlog.h>
class simulation_manager {
public:
void add_algorithm(std::string const &name, std::shared_ptr<algorithm> algo) {
if (!algorithms_.contains(name)) {
algorithms_.emplace(name, std::make_shared<algorithm_wrap>(algo));
}
}
void remove_algorithm(std::string const &name) {
algorithms_.erase(name);
}
void set_algorithm_enable(std::string const &name, bool flag) {
if (algorithms_.contains(name)) {
algorithms_[name]->set_enable(flag);
}
}
bool algorithm_enable(std::string const &name) {
if (algorithms_.contains(name)) {
return algorithms_[name]->enable();
}
return false;
}
void set_algorithm_duration_period(std::string const &name, int duration_period) {
if (algorithms_.contains(name)) {
algorithms_[name]->set_duration_period(duration_period);
}
}
int algorithm_duration_period(std::string const &name) {
if (algorithms_.contains(name)) {
return algorithms_[name]->duration_period();
}
return -1;
}
void set_algorithm_config(std::string const &name, nlohmann::json const &config) {
if (!algorithms_.contains(name)) {
spdlog::debug("Create {} Algorithm Object", name);
if ("periodic_interference" == name) {
algorithms_[name] = std::make_shared<algorithm_wrap>(std::make_shared<periodic_interference>());
} else if ("step" == name) {
algorithms_[name] = std::make_shared<algorithm_wrap>(std::make_shared<step>());
} else if ("white_noise" == name) {
algorithms_[name] = std::make_shared<algorithm_wrap>(std::make_shared<white_noise>());
} else if ("temperature_drift" == name) {
algorithms_[name] = std::make_shared<algorithm_wrap>(std::make_shared<temperature_drift>());
} else if ("pulse" == name) {
algorithms_[name] = std::make_shared<algorithm_wrap>(std::make_shared<step>());
}
}
if (algorithms_.contains(name)) {
algorithms_[name]->set_config(config);
}
}
nlohmann::json algorithm_config(std::string const &name) {
if (algorithms_.contains(name)) {
return algorithms_[name]->config();
}
return {};
}
nlohmann::json config() {
nlohmann::json j;
for (auto iter = algorithms_.begin(); iter != algorithms_.end(); ++iter) {
j[iter->first] = iter->second->config();
}
return j;
}
void set_config(nlohmann::json const &c) {
for (auto iter = c.begin(); iter != c.end(); ++iter) {
set_algorithm_config(iter.key(), iter.value());
}
}
double eval(double value) {
for (auto &iter: algorithms_) {
value = iter.second->eval(value);
}
return value;
}
private:
std::map<std::string, std::shared_ptr<algorithm_wrap>> algorithms_;
};
#endif //FAULT_SIMULATION_ALGORITHM_SIMULATION_MANAGER_HPP