diff --git a/include/rosa/agent/DistanceMetrics.hpp b/include/rosa/agent/DistanceMetrics.hpp index 64de3d8..466a88c 100644 --- a/include/rosa/agent/DistanceMetrics.hpp +++ b/include/rosa/agent/DistanceMetrics.hpp @@ -1,136 +1,140 @@ //===-- rosa/agent/DistanceMetrics.hpp ---------------------*- C++ -*-===// // // The RoSA Framework // // Distributed under the terms and conditions of the Boost Software License 1.0. // See accompanying file LICENSE. // // If you did not receive a copy of the license file, see // http://www.boost.org/LICENSE_1_0.txt. // //===----------------------------------------------------------------------===// /// /// \file rosa/agent/DistanceMetrics.hpp /// /// \author Benedikt Tutzer (benedikt.tutzer@tuwien.ac.at) /// /// \date 2020 /// /// \brief Definition of *DistanceMetrics* *functionality*. /// //===----------------------------------------------------------------------===// #ifndef ROSA_AGENT_DISTANCEMETRICS_HPP #define ROSA_AGENT_DISTANCEMETRICS_HPP #include "rosa/agent/Abstraction.hpp" #include "rosa/agent/Functionality.h" #include "rosa/support/debug.hpp" namespace rosa { namespace agent { /// Implements \c rosa::agent::Abstraction as the absolute difference between /// two values /// /// \note This implementation is supposed to be used to represent a difference-metric /// function from an arithmetic domain to an arithmetic range. This is enforced /// statically. /// /// \tparam D type of the input values /// \tparam R type of the difference template class AbsoluteDistance : public Abstraction, R> { // 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"); public: /// Creates an instance by Initializing the underlying \c Abstraction. AbsoluteDistance(void) : Abstraction, R>(0) { } /// Destroys \p this object. ~AbsoluteDistance(void) = default; /// Checks wether the Abstraction evaluates to default at the given position /// /// \param V the value at which to check if the function falls back to it's /// default value. /// /// \return false if the value falls into a defined range and the Abstraction /// defined for that range does not fall back to it's default value. bool isDefaultAt(const std::pair &V) const noexcept override { (void)(V); return false; } /// Calculates the distance-metric for the given value. If this is the first /// value, the Default-Value is returned /// /// \param V value to abstract /// /// \return the absolute distanct R operator()(const std::pair &V) const noexcept override { return V.first - V.second; } }; /// Implements \c rosa::agent::Abstraction as the relative difference between /// two values /// /// \note This implementation is supposed to be used to represent a difference-metric /// function from an arithmetic domain to an arithmetic range. This is enforced /// statically. /// /// \tparam D type of the input values /// \tparam R type of the difference template class RelativeDistance : public Abstraction, R> { // 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"); public: /// Creates an instance by Initializing the underlying \c Abstraction. RelativeDistance(void) : Abstraction, R>(0) { } /// Destroys \p this object. ~RelativeDistance(void) = default; /// Checks wether the Abstraction evaluates to default at the given position /// /// \param V the value at which to check if the function falls back to it's /// default value. /// /// \return false if the value falls into a defined range and the Abstraction /// defined for that range does not fall back to it's default value. bool isDefaultAt(const std::pair &V) const noexcept override { (void)(V); return false; } /// Calculates the distance-metric for the given value. If this is the first /// value, the Default-Value is returned /// /// \param V value to abstract /// /// \return the absolute distanct R operator()(const std::pair &V) const noexcept override { R Dist = ((R)V.second) - V.first; if (Dist == 0) { return 0; } else { - Dist = Dist / V.first; + if (V.first >= 5 || V.second >= 5) { + Dist = Dist / V.first; + } else { + Dist = Dist / (V.second+46.008); + } } return Dist; } }; } // End namespace agent } // End namespace rosa #endif // ROSA_AGENT_DISTANCEMETRICS_HPP