diff --git a/.gitignore b/.gitignore index e136fcf..386d354 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode -.vs \ No newline at end of file +.vs + diff --git a/include/rosa/agent/Abstraction.hpp b/include/rosa/agent/Abstraction.hpp index 1c5a3c1..032c970 100644 --- a/include/rosa/agent/Abstraction.hpp +++ b/include/rosa/agent/Abstraction.hpp @@ -1,194 +1,225 @@ //===-- rosa/agent/Abstraction.hpp ------------------------------*- C++ -*-===// // // The RoSA Framework // //===----------------------------------------------------------------------===// /// /// \file rosa/agent/Abstraction.hpp /// /// \author David Juhasz (david.juhasz@tuwien.ac.at) /// /// \date 2017 /// /// \brief Definition of *abstraction* *functionality*. /// //===----------------------------------------------------------------------===// #ifndef ROSA_AGENT_ABSTRACTION_HPP #define ROSA_AGENT_ABSTRACTION_HPP #include "rosa/agent/Functionality.h" #include "rosa/support/debug.hpp" #include #include namespace rosa { namespace agent { /// Abstracts values from a type to another one. /// /// \tparam T type to abstract from /// \tparam A type to abstract to template class Abstraction : public Functionality { - -public: - +protected: /// Value to abstract to by default. const A Default; - +public: /// Creates an instance. /// /// \param Default value to abstract to by default Abstraction(const A Default) noexcept : Default(Default) {} /// Destroys \p this object. ~Abstraction(void) = default; + /// Checks wether the Abstraction evaluates to default at the given position + bool isDefaultAt(const T &V) const{ + (void)V; + return true; + } + /// Abstracts a value from type \p T to type \p A. /// /// \note The default implementation always returns /// \c rosa::agent::Abstraction::Default, hence the actual argument is /// ignored. /// /// \return the abstracted value virtual A operator()(const T &) const noexcept { return Default; } }; /// Implements \c rosa::agent::Abstraction as a \c std::map from a type to /// another one. /// /// \note This implementation is supposed to be used to abstract between /// enumeration types, which is statically enforced. /// /// \tparam T type to abstract from /// \tparam A type to abstract to template class MapAbstraction : public Abstraction, private std::map { // Make sure the actual type arguments are enumerations. STATIC_ASSERT((std::is_enum::value && std::is_enum::value), "mapping not enumerations"); // Bringing into scope inherited members. using Abstraction::Default; using std::map::end; using std::map::find; public: /// Creates an instance by initializing the underlying \c std::map. /// /// \param Map the mapping to do abstraction according to /// \param Default value to abstract to by default MapAbstraction(const std::map &Map, const A Default) noexcept : Abstraction(Default), std::map(Map) {} /// Destroys \p this object. ~MapAbstraction(void) = default; + /// Checks wether the Abstraction evaluates to default at the given position + bool isDefaultAt(const T &V) const { + const auto I = find(V); + return I == end() ? true : false; + } + /// Abstracts a value from type \p T to type \p A based on the set mapping. /// /// Results in the value associated by the set mapping to the argument, or /// \c rosa::agent::MapAbstraction::Default if the actual argument is not /// associated with anything by the set mapping. /// /// \param V value to abstract /// /// \return the abstracted value based on the set mapping A operator()(const T &V) const noexcept override { const auto I = find(V); return I == end() ? Default : *I; } }; /// Implements \c rosa::agent::Abstraction as a \c std::map from ranges of a /// type to values of another type. /// /// \note This implementation is supposed to be used to abstract ranges of /// arithmetic types into enumerations, which is statically enforced. /// /// \invariant The keys in the underlying \c std::map define valid ranges /// such that `first <= second` and there are no overlapping ranges defined by /// the keys. /// /// \tparam T type to abstract from /// \tparam A type to abstract to template class RangeAbstraction : public Abstraction, private std::map, A> { // Make sure the actual type arguments are matching our expectations. STATIC_ASSERT((std::is_arithmetic::value), "abstracting not arithmetic"); /// \todo check if this compiles with the definition of abstractions as /// self-aware properties //STATIC_ASSERT((std::is_enum::value), "abstracting not to enumeration"); // Bringing into scope inherited members. using Abstraction::Default; using std::map, A>::begin; using std::map, A>::end; using std::map, A>::find; public: /// Creates an instance by Initializing the unserlying \c std::map. /// /// \param Map the mapping to do abstraction according to /// \param Default value to abstract to by default /// /// \pre Each key defines a valid range such that `first <= second` and /// there are no overlapping ranges defined by the keys. RangeAbstraction(const std::map, A> &Map, const A &Default) : Abstraction(Default), std::map, A>(Map) { // Sanity check. ASSERT(std::all_of( begin(), end(), [this](const std::pair, A> &P) { return P.first.first <= P.first.second && std::all_of(++find(P.first), end(), [&P](const std::pair, A> &R) { // \note Values in \c Map are sorted. return P.first.first < P.first.second && P.first.second <= R.first.first || P.first.first == P.first.second && P.first.second < R.first.first; }); })); } /// Destroys \p this object. ~RangeAbstraction(void) = default; + /// Checks wether the Abstraction evaluates to default at the given position + bool isDefaultAt(const T &V) const{ + auto I = begin(); + bool Found = false; // Indicates if \c I refers to a matching range. + bool Failed = false; // Indicates if it is pointless to continue searching. + while (!Found && !Failed && I != end()) { + if (V < I->first.first) { + // No match so far and \p V is below the next range, never will match. + // \note Keys are sorted in the map. + return true; + } else if (I->first.first <= V && V < I->first.second) { + // Matching range found. + return false; + } else { + // Cannot conclude in this step, move to the next range. + ++I; + } + } + return true; + } + /// Abstracts a value from type \p T to type \p A based on the set mapping. /// /// Results in the value associated by the set mapping to the argument, or /// \c rosa::agent::RangeAbstraction::Default if the actual argument is not /// included in any of the ranges in the set mapping. /// /// \param V value to abstract /// /// \return the abstracted value based on the set mapping A operator()(const T &V) const noexcept override { auto I = begin(); bool Found = false; // Indicates if \c I refers to a matching range. bool Failed = false; // Indicates if it is pointless to continue searching. while (!Found && !Failed && I != end()) { if (V < I->first.first) { // No match so far and \p V is below the next range, never will match. // \note Keys are sorted in the map. Failed = true; } else if (I->first.first <= V && V < I->first.second) { // Matching range found. Found = true; } else { // Cannot conclude in this step, move to the next range. ++I; } } ASSERT(!Found || I != end()); return Found ? I->second : Default; } }; } // End namespace agent } // End namespace rosa #endif // ROSA_AGENT_ABSTRACTION_HPP diff --git a/include/rosa/agent/CrossReliability.h b/include/rosa/agent/CrossReliability.h new file mode 100644 index 0000000..03c6410 --- /dev/null +++ b/include/rosa/agent/CrossReliability.h @@ -0,0 +1,345 @@ +//===-- rosa/delux/CrossReliability.h ---------------------------*- C++ -*-===// +// +// The RoSA Framework +// +//===----------------------------------------------------------------------===// +/// +/// \file rosa/delux/CrossReliability.h +/// +/// \author Daniel Schnoell +/// +/// \date 2019 +/// +/// \brief +/// +/// \todo there is 1 exception that needs to be handled correctly. +/// \note the default search function is extremely slow maby this could be done +/// via template for storage class and the functions/methods to efficiently find +/// the correct LinearFunction +//===----------------------------------------------------------------------===// +#ifndef ROSA_AGENT_CROSSRELIABILITY_H +#define ROSA_AGENT_CROSSRELIABILITY_H + +#define ROSA_LOG_LEVEL 100 + +#include "rosa/agent/Abstraction.hpp" +#include "rosa/agent/Functionality.h" +#include "rosa/core/forward_declarations.h" // needed for id_t +#include "rosa/support/log.h" // needed for error "handling" + +// nedded headers + +#include +#include //assert +#include +// for static methods +#include +#include + +namespace rosa { +namespace agent { + +/// Calculates the Cross Reliability +/// \brief it uses the state represented by a numerical value and calculates the +/// Reliability of a given agent( represented by there id ) in connection to all +/// other given agents +/// +/// \note all combination of agents and there coresponding Cross Reliability +/// function have to be specified +template +class CrossReliability : public Abstraction { + using Abstraction = typename rosa::agent::Abstraction; + + struct Functionblock { + bool exists = false; + id_t A; + id_t B; + Abstraction *Funct; + }; + + /// From Maxi in his code defined as 1 can be changed by set + Type crossReliabilityParameter = 1; + + /// Stored Cross Reliability Functions + std::vector Functions; + + /// Method which is used to combine the generated values + Type (*Method)(std::vector values) = AVERAGE; + + //-------------------------------------------------------------------------------- + // helper function + /// evalues the absolute distance between two values + /// \note this is actually the absolute distance but to ceep it somewhat + /// conform with maxis code + template Type_t AbsuluteValue(Type_t A, Type_t B) { + static_assert(std::is_arithmetic::value); + return ((A - B) < 0) ? B - A : A - B; + } + + /// verry inefficient searchFunction + Functionblock (*searchFunction)(std::vector vect, + const id_t nameA, const id_t nameB) = + [](std::vector vect, const id_t nameA, + const id_t nameB) -> Functionblock { + for (Functionblock tmp : vect) { + if (tmp.A == nameA && tmp.B == nameB) + return tmp; + if (tmp.A == nameB && tmp.B == nameA) + return tmp; + } + return Functionblock(); + }; + + /// evaluest the corisponding LinearFunction thith the score difference + /// \param nameA these two parameters are the unique identifiers + /// \param nameB these two parameters are the unique identifiers + /// for the LinerFunction + /// + /// \note If the block nameA nameB doesn't exist it logs the error and returns + /// 0 + /// \note it doesn't matter if they are swapped + Type getCrossReliabilityFromProfile(id_t nameA, id_t nameB, + StateType scoreDifference) { + Functionblock block = searchFunction(Functions, nameA, nameB); + if (!block.exists) { + LOG_ERROR(("CrossReliability: Block:" + std::to_string(nameA) + "," + + std::to_string(nameB) + "doesn't exist returning 0")); + return 0; + } + return block.Funct->operator()(scoreDifference); + } + +public: + /// adds a Cross Reliability Profile used to get the Reliability of the state + /// difference + void addCrossReliabilityProfile(id_t idA, id_t idB, Abstraction *Function) { + Functions.push_back({true, idA, idB, Function}); + } + + /// sets the cross reliability parameter + void setCrossReliabilityParameter(Type val) { + crossReliabilityParameter = val; + } + /// sets the used method to combine the values + void setCrossReliabilityMethod(Type (*Meth)(std::vector values)) { + Method = Meth; + } + + ~CrossReliability() { + for (auto tmp : Functions) + delete tmp.Funct; + Functions.clear(); + } + + /// Calculets the CrossReliability + /// \note both Main and Slaveagents are represented by there data and an + /// unique identifier + /// + /// \param MainAgent defines the value pair around which the Cross Reliability + /// is calculated + /// \param SlaveAgents defines all value pairs of the connected Agents it + /// doesn't matter if Main agent exists inside this vector + Type operator()(std::pair &MainAgent, + std::vector> &SlaveAgents); + + /// predefined combination method + static Type CONJUNCTION(std::vector values) { + static_assert(std::is_arithmetic::value); // sanitny check + return *std::min_element(values.begin(), values.end()); + } + + /// predefined combination method + static Type AVERAGE(std::vector values) { + static_assert(std::is_arithmetic::value); // sanitny check + return std::accumulate(values.begin(), values.end(), 0.0) / values.size(); + } + + /// predefined combination method + static Type DISJUNCTION(std::vector values) { + static_assert(std::is_arithmetic::value); // sanitny check + return *std::max_element(values.begin(), values.end()); + } +}; + +template +inline Type CrossReliability:: +operator()(std::pair &MainAgent, + std::vector> &SlaveAgents) { + static_assert(std::is_arithmetic::value); // sanitny check + static_assert(std::is_arithmetic::value); // sanitny check + + Type crossReliabiability; + std::vector values; + + for (std::pair SlaveAgent : SlaveAgents) { + + if (SlaveAgent.first == MainAgent.first) + continue; + + if (MainAgent.second == SlaveAgent.second) + crossReliabiability = 1; + else + crossReliabiability = + 1 / (crossReliabilityParameter * + AbsuluteValue(MainAgent.second, SlaveAgent.second)); + + // profile reliability + Type crossReliabilityFromProfile = getCrossReliabilityFromProfile( + MainAgent.first, SlaveAgent.first, + AbsuluteValue(MainAgent.second, SlaveAgent.second)); + values.push_back( + std::max(crossReliabiability, crossReliabilityFromProfile)); + } + return Method(values); +} + +/// Calculates the Cross Confidence +/// \brief It uses the a theoretical state represented by a numerical value and +/// calculates the Reliability of a given agent( represented by there id ) in +/// connection to all other given agents this can be used to get a Confidence of +/// the current state +/// +/// \note all combination of agents and there coresponding Cross Reliability +/// function have to be specified +template +class CrossConfidence : public Abstraction { + using Abstraction = typename rosa::agent::Abstraction; + + struct Functionblock { + bool exists = false; + id_t A; + id_t B; + Abstraction *Funct; + }; + + /// From Maxi in his code defined as 1 can be changed by set + Type crossReliabilityParameter = 1; + + /// Stored Cross Reliability Functions + std::vector Functions; + + /// Method which is used to combine the generated values + Type (*Method)(std::vector values) = AVERAGE; + + //-------------------------------------------------------------------------------- + // helper function + /// evalues the absolute distance between two values + /// \note this is actually the absolute distance but to ceep it somewhat + /// conform with maxis code + template Type_t AbsuluteValue(Type_t A, Type_t B) { + static_assert(std::is_arithmetic::value); + return ((A - B) < 0) ? B - A : A - B; + } + + /// verry inefficient searchFunction + Functionblock (*searchFunction)(std::vector vect, + const id_t nameA, const id_t nameB) = + [](std::vector vect, const id_t nameA, + const id_t nameB) -> Functionblock { + for (Functionblock tmp : vect) { + if (tmp.A == nameA && tmp.B == nameB) + return tmp; + if (tmp.A == nameB && tmp.B == nameA) + return tmp; + } + return Functionblock(); + }; + + /// evaluest the corisponding LinearFunction thith the score difference + /// \param nameA these two parameters are the unique identifiers + /// \param nameB these two parameters are the unique identifiers + /// for the LinerFunction + /// + /// \note it doesn't matter if they are swapped + Type getCrossReliabilityFromProfile(id_t nameA, id_t nameB, + StateType scoreDifference) { + Functionblock block = searchFunction(Functions, nameA, nameB); + if (!block.exists) { + LOG_ERROR(("CrossReliability: Block:" + std::to_string(nameA) + "," + + std::to_string(nameB) + "doesn't exist returning 0")); + return 0; + } + return block.Funct->operator()(scoreDifference); + } + +public: + /// adds a Cross Reliability Profile used to get the Reliability of the state + /// difference + void addCrossReliabilityProfile(id_t idA, id_t idB, Abstraction *Function) { + Functions.push_back({true, idA, idB, Function}); + } + + /// sets the cross reliability parameter + void setCrossReliabilityParameter(Type val) { + crossReliabilityParameter = val; + } + /// sets the used method to combine the values + void setCrossReliabilityMethod(Type (*Meth)(std::vector values)) { + Method = Meth; + } + + ~CrossConfidence() { + for (auto tmp : Functions) + delete tmp.Funct; + Functions.clear(); + } + + Type operator()(id_t MainAgent, StateType TheoreticalValue, + std::vector> &SlaveAgents); + + /// predefined combination method + static Type CONJUNCTION(std::vector values) { + static_assert(std::is_arithmetic::value); // sanitny check + return *std::min_element(values.begin(), values.end()); + } + + /// predefined combination method + static Type AVERAGE(std::vector values) { + static_assert(std::is_arithmetic::value); // sanitny check + return std::accumulate(values.begin(), values.end(), 0.0) / values.size(); + } + + /// predefined combination method + static Type DISJUNCTION(std::vector values) { + static_assert(std::is_arithmetic::value); // sanitny check + return *std::max_element(values.begin(), values.end()); + } +}; + +template +inline Type CrossConfidence:: +operator()(id_t MainAgent, StateType TheoreticalValue, + std::vector> &SlaveAgents) { + static_assert(std::is_arithmetic::value); // sanitny check + static_assert(std::is_arithmetic::value); // sanitny check + + Type crossReliabiability; + + std::vector values; + + for (std::pair SlaveAgent : SlaveAgents) { + + if (SlaveAgent.first == MainAgent) + continue; + + if (TheoreticalValue == SlaveAgent.second) + crossReliabiability = 1; + else + crossReliabiability = + 1 / (crossReliabilityParameter * + AbsuluteValue(TheoreticalValue, SlaveAgent.second)); + + // profile reliability + Type crossReliabilityFromProfile = getCrossReliabilityFromProfile( + MainAgent, SlaveAgent.first, + AbsuluteValue(TheoreticalValue, SlaveAgent.second)); + values.push_back( + std::max(crossReliabiability, crossReliabilityFromProfile)); + } + return Method(values); +} + +} // End namespace agent +} // End namespace rosa + +#endif // ROSA_AGENT_CROSSRELIABILITY_H \ No newline at end of file diff --git a/include/rosa/agent/FunctionAbstractions.hpp b/include/rosa/agent/FunctionAbstractions.hpp index 31bbea4..606125a 100644 --- a/include/rosa/agent/FunctionAbstractions.hpp +++ b/include/rosa/agent/FunctionAbstractions.hpp @@ -1,175 +1,194 @@ //===-- rosa/agent/FunctionAbstractions.hpp ---------------------*- C++ -*-===// // // The RoSA Framework // //===----------------------------------------------------------------------===// /// /// \file rosa/agent/FunctionAbstractions.hpp /// /// \author Benedikt Tutzer (benedikt.tutzer@tuwien.ac.at) /// /// \date 2019 /// /// \brief Definition of *FunctionAbstractions* *functionality*. /// //===----------------------------------------------------------------------===// #ifndef ROSA_AGENT_FUNCTIONABSTRACTIONS_HPP #define ROSA_AGENT_FUNCTIONABSTRACTIONS_HPP #include "rosa/agent/Functionality.h" #include "rosa/agent/Abstraction.hpp" #include "rosa/support/debug.hpp" #include #include #include #include namespace rosa { namespace agent { /// Evaluates a linear function at a given value. /// /// \tparam T type of the functions domain /// \tparam A type of the functions range template class LinearFunction : public Abstraction{ // Make sure the actual type arguments are matching our expectations. STATIC_ASSERT((std::is_arithmetic::value), "LinearFunction not arithmetic T"); STATIC_ASSERT((std::is_arithmetic::value), "LinearFunction not to arithmetic"); protected: const T Intercept; const T Coefficient; public: /// Creates an instance. /// /// \param Intercept the intercept of the linear function /// \param Coefficient the coefficient of the linear function /// domain LinearFunction(T Intercept, T Coefficient) noexcept : Abstraction(Intercept), Intercept(Intercept), Coefficient(Coefficient) {} /// Destroys \p this object. ~LinearFunction(void) = default; + /// Checks wether the Abstraction evaluates to default at the given position + /// As LinearFunctions can be evaluated everythwere, this is always false + bool isDefaultAt(const T &V) const{ + (void)V; + return false; + } + /// Evaluates the linear function /// /// \param X the value at which to evaluate the function /// \return the result virtual A operator()(const T &X) const noexcept override { return Intercept + X*Coefficient; } }; /// Evaluates a sine function at a given value. /// /// \tparam T type of the functions domain /// \tparam A type of the functions range template class SineFunction : public Abstraction{ // Make sure the actual type arguments are matching our expectations. STATIC_ASSERT((std::is_arithmetic::value), "SineFunction not arithmetic T"); STATIC_ASSERT((std::is_arithmetic::value), "SineFunction not to arithmetic"); protected: const T Frequency; const T Amplitude; const T Phase; const T Average; public: /// Creates an instance. /// /// \param Frequency the frequency of the sine wave /// \param Amplitude the amplitude of the sine wave /// \param Phase the phase of the sine wave /// \param Average the average of the sine wave /// domain SineFunction(T Frequency, T Amplitude, T Phase, T Average) noexcept : Abstraction(Average), Frequency(Frequency), Amplitude(Amplitude), Phase(Phase), Average(Average) {} /// Destroys \p this object. ~SineFunction(void) = default; + /// Checks wether the Abstraction evaluates to default at the given position + /// As SineFunctions can be evaluated everythwere, this is always false + bool isDefaultAt(const T &V) const{ + (void)V; + return false; + } + /// Evaluates the linear function /// /// \param X the value at which to evaluate the function /// \return the result virtual A operator()(const T &X) const noexcept override { return Amplitude*sin(Frequency * X + Phase) + Average; } }; /// Implements \c rosa::agent::RangeAbstraction as an abstraction from /// \c std::map from ranges of a type to abstractions of that type to another /// type. The resulting abstractions are evaluated for the given values. /// /// \note This implementation is supposed to be used to abstract ranges of /// arithmetic types into abstractions from that type to another arithmetic /// type, which is statically enforced. /// /// \invariant The keys in the underlying \c std::map define valid ranges /// such that `first <= second` and there are no overlapping ranges defined by /// the keys. /// /// \tparam T type to abstract from /// \tparam A type to abstract to template class PartialFunction : public Abstraction { // Make sure the actual type arguments are matching our expectations. STATIC_ASSERT((std::is_arithmetic::value), "abstracting not arithmetic"); STATIC_ASSERT((std::is_arithmetic::value), "abstracting not to arithmetic"); private: RangeAbstraction>> RA; public: /// Creates an instance by Initializing the underlying \c RangeAbstraction. /// /// \param Map the mapping to do abstraction according to /// \param Default abstraction to abstract to by default /// /// \pre Each key defines a valid range such that `first <= second` and /// there are no overlapping ranges defined by the keys. PartialFunction(const std::map, std::shared_ptr>> &Map, const A Default) : Abstraction(Default), RA(Map, std::shared_ptr> (new Abstraction(Default))) { } /// Destroys \p this object. ~PartialFunction(void) = default; + /// Checks wether the Abstraction evaluates to default at the given position + bool isDefaultAt(const T &V) const{ + return RA.isDefaultAt(V); + } + /// Evaluates an Abstraction from type \p T to type \p A based on the set /// mapping. /// /// Results in the value associated by the set mapping to the argument, or /// \c rosa::agent::RangeAbstraction::Default if the actual argument is not /// included in any of the ranges in the set mapping. /// /// \param V value to abstract /// /// \return the abstracted value based on the set mapping A operator()(const T &V) const noexcept override { return RA(V)->operator()(V); } }; } // End namespace agent } // End namespace rosa #endif // ROSA_AGENT_FUNCTIONABSTRACTIONS_HPP diff --git a/include/rosa/agent/RangeConfidence.hpp b/include/rosa/agent/RangeConfidence.hpp index c5e86a6..83ba518 100644 --- a/include/rosa/agent/RangeConfidence.hpp +++ b/include/rosa/agent/RangeConfidence.hpp @@ -1,96 +1,90 @@ //===-- rosa/agent/RangeConfidence.hpp --------------------------*- C++ -*-===// // // The RoSA Framework // //===----------------------------------------------------------------------===// /// /// \file rosa/agent/RangeConfidence.hpp /// /// \author Benedikt Tutzer (benedikt.tutzer@tuwien.ac.at) /// /// \date 2019 /// /// \brief Definition of *RangeConfidence* *functionality*. /// //===----------------------------------------------------------------------===// #ifndef ROSA_AGENT_RANGECONFIDENCE_HPP #define ROSA_AGENT_RANGECONFIDENCE_HPP #include "rosa/agent/Functionality.h" #include "rosa/agent/Abstraction.hpp" #include "rosa/agent/FunctionAbstractions.hpp" #include "rosa/support/debug.hpp" #include #include #include #include namespace rosa { namespace agent { /// Evaluates a vector of Abstractions at a given value and returns the results /// as a vector /// /// \note This implementation is supposed to be used to abstract ranges of /// arithmetic types into vectors of another arithmetic type, which is /// statically enforced. /// /// \tparam T type to abstract from /// \tparam A type to abstract a vector of to template class RangeConfidence : protected Abstraction>, private std::map>{ // Make sure the actual type arguments are matching our expectations. STATIC_ASSERT((std::is_arithmetic::value), "abstracting not arithmetic"); STATIC_ASSERT((std::is_arithmetic::value), "abstracting not to arithmetic"); - // Bringing into scope inherited members. - using std::map>::size; - using std::map>::begin; - using std::map>::end; - private: bool IgnoreDefaults; public: /// Creates an instance by Initializing the underlying \c RangeAbstraction. /// /// \param Abstractions the Abstractions to be evaluated RangeConfidence(const std::map> &Abstractions, bool IgnoreDefaults = false) : Abstraction>({}), std::map>(Abstractions), IgnoreDefaults(IgnoreDefaults){ } /// Destroys \p this object. ~RangeConfidence(void) = default; /// Evaluates an Abstraction from type \p T to type \p A based on the set /// mapping. /// /// Results in the value associated by the set mapping to the argument, or /// \c rosa::agent::RangeAbstraction::Default if the actual argument is not /// included in any of the ranges in the set mapping. /// /// \param V value to abstract /// /// \return the abstracted value based on the set mapping std::map operator()(const T &V) const noexcept override { std::map ret; for (auto const& p : ((std::map>)*this)){ - B res = p.second(V); - if(!IgnoreDefaults || p.second.Default != res) - ret.insert(std::pair(p.first, res)); + if(!IgnoreDefaults || !p.second.isDefaultAt(V)) + ret.insert(std::pair(p.first, p.second(V))); } return ret; } }; } // End namespace agent } // End namespace rosa #endif // ROSA_AGENT_RANGECONFIDENCE_HPP diff --git a/lib/agent/CMakeLists.txt b/lib/agent/CMakeLists.txt index 7edb556..d4bdebc 100644 --- a/lib/agent/CMakeLists.txt +++ b/lib/agent/CMakeLists.txt @@ -1,18 +1,20 @@ set(LIB_INCLUDE_DIR ${ROSA_MAIN_INCLUDE_DIR}/rosa/agent) add_library(ROSAAgent ${LIB_INCLUDE_DIR}/namespace.h namespace.cpp ${LIB_INCLUDE_DIR}/Functionality.h Functionality.cpp ${LIB_INCLUDE_DIR}/Abstraction.hpp Abstraction.cpp ${LIB_INCLUDE_DIR}/FunctionAbstractions.hpp FunctionAbstractions.cpp ${LIB_INCLUDE_DIR}/RangeConfidence.hpp RangeConfidence.cpp ${LIB_INCLUDE_DIR}/History.hpp History.cpp ${LIB_INCLUDE_DIR}/Confidence.hpp Confidence.cpp + ${LIB_INCLUDE_DIR}/CrossReliability.h + CrossReliability.cpp ) diff --git a/lib/agent/CrossReliability.cpp b/lib/agent/CrossReliability.cpp new file mode 100644 index 0000000..21ed3b4 --- /dev/null +++ b/lib/agent/CrossReliability.cpp @@ -0,0 +1,20 @@ +//===-- agent/CrossReliability.cpp ------------------------------*- C++ -*-===// +// +// The RoSA Framework +// +//===----------------------------------------------------------------------===// +/// +/// \file agent/CrossReliability.cpp +/// +/// \author Daniel Schnoell (daniel.schnoell@tuwien.ac.at) +/// +/// \date 2019 +/// +/// \brief Implementation for rosa/agent/CrossReliability.cpp +/// +/// \note Empty implementation, source file here to have a compile database +/// entry for rosa/agent/CrossReliability.h +/// +//===----------------------------------------------------------------------===// + +#include "rosa/agent/CrossReliability.h"