feat: add ! negation operator for boolean models

Prefix any boolean model reference with ! to negate its output.
Works with all boolean models: !toggle_2s, !valve_px_std:toggle_2s, !bool_50, etc.
This commit is contained in:
Huamonarch 2026-05-13 16:56:30 +08:00
parent e4233cc23d
commit 1e781a7c03
3 changed files with 20 additions and 0 deletions

View File

@ -66,6 +66,7 @@ make -j$(nproc)
| `csv:文件:列号` | 内联 CSV 数据回放 | `csv:spbdata:1` |
| `基模型+噪声模型` | 组合模型(叠加噪声) | `linear_slow+normal_tiny` |
| `pair模型:动作模型` | 阀到位传感器引用动作信号 | `valve_px_std:toggle_2s` |
| `!模型引用` | 布尔量取反 | `!toggle_2s` |
| 空或 `default` | 默认模型 `normal_tiny` | — |
## 模型参考

View File

@ -11,6 +11,7 @@
#include <TestProject/RNG/model/BoolToggleModel.h>
#include <TestProject/RNG/model/BoolCsvModel.h>
#include <TestProject/RNG/model/ValvePairModel.h>
#include <TestProject/RNG/model/NotModel.h>
#include <TestProject/RNG/model/CompositeModel.h>
#include <fstream>
#include <stdexcept>
@ -50,6 +51,11 @@ void ModelRegistry::loadModels(const std::string& jsonPath) {
}
std::unique_ptr<IModel> ModelRegistry::createModel(const std::string& modelName, float defaultVal) {
// Negation: !model
if (!modelName.empty() && modelName[0] == '!') {
return std::make_unique<NotModel>(createModel(modelName.substr(1), defaultVal));
}
// Composite: base+noise
auto plusPos = modelName.find('+');
if (plusPos != std::string::npos) {

View File

@ -0,0 +1,13 @@
#pragma once
#include <TestProject/RNG/model/IModel.h>
#include <memory>
struct NotModel : IModel {
std::unique_ptr<IModel> inner;
NotModel(std::unique_ptr<IModel> m) : inner(std::move(m)) {}
bool evaluateBool(size_t t) override { return !inner->evaluateBool(t); }
void linkPeers(ModelRegistry& reg) override { inner->linkPeers(reg); }
};