From 13d687bca9c24d838563f5b48fb3c2091e8b9b9e Mon Sep 17 00:00:00 2001 From: Nick Le Large Date: Mon, 8 Apr 2024 13:55:05 +0200 Subject: [PATCH 1/6] Add random arbitrator and corresponding unit test --- .../internal/random_arbitrator_io.hpp | 38 ++++ .../arbitration_graphs/random_arbitrator.hpp | 115 ++++++++++ test/random_arbitrator.cpp | 207 ++++++++++++++++++ 3 files changed, 360 insertions(+) create mode 100644 include/arbitration_graphs/internal/random_arbitrator_io.hpp create mode 100644 include/arbitration_graphs/random_arbitrator.hpp create mode 100644 test/random_arbitrator.cpp diff --git a/include/arbitration_graphs/internal/random_arbitrator_io.hpp b/include/arbitration_graphs/internal/random_arbitrator_io.hpp new file mode 100644 index 0000000..b6e9127 --- /dev/null +++ b/include/arbitration_graphs/internal/random_arbitrator_io.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "../random_arbitrator.hpp" + + +namespace arbitration_graphs { + + +////////////////////////////////////// +// RandomArbitrator::Option // +////////////////////////////////////// + +template +std::ostream& RandomArbitrator::Option::to_stream( + std::ostream& output, + const Time& time, + const int& option_index, + const std::string& prefix, + const std::string& suffix) const { + + output << option_index + 1 << ". "; + ArbitratorBase::Option::to_stream(output, time, option_index, prefix, suffix); + return output; +} + + +////////////////////////////////////// +// RandomArbitrator // +////////////////////////////////////// + +template +YAML::Node RandomArbitrator::toYaml(const Time& time) const { + YAML::Node node = ArbitratorBase::toYaml(time); + node["type"] = "RandomArbitrator"; + return node; +} + +} // namespace arbitration_graphs diff --git a/include/arbitration_graphs/random_arbitrator.hpp b/include/arbitration_graphs/random_arbitrator.hpp new file mode 100644 index 0000000..d558578 --- /dev/null +++ b/include/arbitration_graphs/random_arbitrator.hpp @@ -0,0 +1,115 @@ +#pragma once + +#include +#include + +#include + +#include "arbitrator.hpp" + +namespace arbitration_graphs { + +template , + typename VerificationResultT = typename decltype(std::function{VerifierT::analyze})::result_type> +class RandomArbitrator : public Arbitrator { +public: + using ArbitratorBase = Arbitrator; + + using Ptr = std::shared_ptr; + using ConstPtr = std::shared_ptr; + + struct Option : public ArbitratorBase::Option { + public: + using Ptr = std::shared_ptr