feat: add 3 boolean signal models

This commit is contained in:
Huamonarch 2026-05-13 15:13:31 +08:00
parent 2ef663af81
commit 3ce03911c3
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,17 @@
#pragma once
#include <TestProject/RNG/model/IModel.h>
#include <TestProject/RNG/read_csv.hpp>
#include <nlohmann/json.hpp>
#include <string>
using json = nlohmann::json;
struct BoolCsvModel : IModel {
ReadCSV::IntData data;
int column;
BoolCsvModel(const json& params, float)
: data(params["file"].get<std::string>())
, column(params["column"].get<int>()) {}
bool evaluateBool(size_t t) override { return (bool)data(t, column); }
};

View File

@ -0,0 +1,14 @@
#pragma once
#include <TestProject/RNG/model/IModel.h>
#include <nlohmann/json.hpp>
#include <cstdlib>
using json = nlohmann::json;
struct BoolRandomModel : IModel {
float prob_true;
BoolRandomModel(const json& params, float defaultVal)
: prob_true(params.value("prob_true", 0.5f)) {}
bool evaluateBool(size_t) override {
return (double)rand() / RAND_MAX < prob_true;
}
};

View File

@ -0,0 +1,13 @@
#pragma once
#include <TestProject/RNG/model/IModel.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
struct BoolToggleModel : IModel {
int period_ticks;
BoolToggleModel(const json& params, float)
: period_ticks(params.value("period_ms", 2000) / 20) {}
bool evaluateBool(size_t t) override {
return (t / period_ticks) % 2 == 0;
}
};