diff --git a/examples/agent-functionalities/CMakeLists.txt b/examples/agent-functionalities/CMakeLists.txt index 077f183..274d5d0 100644 --- a/examples/agent-functionalities/CMakeLists.txt +++ b/examples/agent-functionalities/CMakeLists.txt @@ -1,5 +1,9 @@ add_executable(agent-functionalities agent-functionalities.cpp) ROSA_add_library_dependencies(agent-functionalities ROSAConfig) ROSA_add_library_dependencies(agent-functionalities ROSACore) ROSA_add_library_dependencies(agent-functionalities ROSAAgent) +add_executable(Reliability-functionalities Reliability-functionality.cpp) +ROSA_add_library_dependencies(Reliability-functionalities ROSAConfig) +ROSA_add_library_dependencies(Reliability-functionalities ROSACore) +ROSA_add_library_dependencies(Reliability-functionalities ROSAAgent) diff --git a/examples/agent-functionalities/Reliability-functionality.cpp b/examples/agent-functionalities/Reliability-functionality.cpp new file mode 100644 index 0000000..4991b92 --- /dev/null +++ b/examples/agent-functionalities/Reliability-functionality.cpp @@ -0,0 +1,106 @@ +//===- examples/agent-functionalities/Reliability-functionality.cpp *C++-*-===// +// +// The RoSA Framework +// +//===----------------------------------------------------------------------===// +/// +/// \file examples/agent-functionalities/Reliability-functionality.cpp +/// +/// \author Daniel Schnoell (daniel.schnoell@tuwien.ac.at ) +/// +/// \date 2019 +/// +/// \brief A simple example on defining \c rosa::Agent instances using +/// Relianility Functionalities. +/// +//===----------------------------------------------------------------------===// + + + +#include "rosa/config/version.h" + +#include "rosa/core/Agent.hpp" +#include "rosa/core/MessagingSystem.hpp" + +#include "rosa/support/log.h" +#include "rosa/support/terminal_colors.h" + +#include "rosa/agent/Reliability.h" +#include "rosa/agent/RangeConfidence.hpp" + +#include +#include + +using namespace rosa::agent; + +int main(void) +{ + typedef double SensorValueType; + typedef long StateType; + typedef double ReliabilityType; + + // defining Range confidence + + + + auto Confidence = new RangeConfidence({ + {0, PartialFunction({ + {{0, 3}, std::make_shared> + (0, 1.0/3)}, + {{3, 6}, std::make_shared> + (1, 0)}, + {{6, 9}, std::make_shared> + (3.0, -1.0/3)}, + },0)}, + {1, PartialFunction({ + {{6, 9}, std::make_shared> + (-2, 1.0/3)}, + {{9, 12}, std::make_shared> + (1, 0)}, + {{12, 15}, std::make_shared> + (5, -1.0/3)}, + },0)}, + {2, PartialFunction({ + {{12, 15}, std::make_shared> + (-4, 1.0/3)}, + {{15, 18}, std::make_shared> + (1, 0)}, + {{18, 21}, std::make_shared> + (7, -1.0/3)}, + },0)} + }); + + + Abstraction* Reliability = new LinearFunction(1,-1.0/9); + + + auto ReliabilitySlope = new LinearFunction(1, -1.0/9); + + + auto TimeConfidence = new LinearFunction(1, -1.0/9); + + auto lowlevel = new LowLevel (); + + std::vector states; + states.push_back(0); + states.push_back(1); + states.push_back(2); + + + lowlevel->setConfidenceFunction(Confidence); + lowlevel->setReliabilityFunction(Reliability); + lowlevel->setReliabilitySlopeFunction(ReliabilitySlope); + lowlevel->setTimeConfidenceFunction(TimeConfidence); + lowlevel->setStates(states); + lowlevel->setHistoryLength(1); + + /* ----------------------------- Do Something ---------------------------------------------------------------- */ + + for ( int a= 0 ; a <10 ; a++) + std::cout <<"a: " << a << "\n" << (lowlevel->feedback({{0,0},{1,0.3},{2,0.5}}),lowlevel->operator()(a)) << "\n"; + + /* ----------------------------- Cleanup --------------------------------------------------------------------- */ + + delete lowlevel; + +} \ No newline at end of file diff --git a/include/rosa/agent/CrossReliability.h b/include/rosa/agent/CrossReliability.h index 03c6410..d3a1f16 100644 --- a/include/rosa/agent/CrossReliability.h +++ b/include/rosa/agent/CrossReliability.h @@ -1,345 +1,344 @@ //===-- 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/Reliability.h b/include/rosa/agent/Reliability.h index debe35d..70290d5 100644 --- a/include/rosa/agent/Reliability.h +++ b/include/rosa/agent/Reliability.h @@ -1,369 +1,413 @@ //===-- rosa/agent/Reliability.h --------------------------------*- C++ -*-===// // // The RoSA Framework // //===----------------------------------------------------------------------===// /// /// \file rosa/agent/Reliability.h /// /// \author Daniel Schnoell (danielschnoell@tuwien.ac.at) /// /// \date 2019 /// /// \brief Definition of *reliability* *functionality*. /// +/// \note All classes throw runtime errors if not all things are set +/// //===----------------------------------------------------------------------===// #ifndef ROSA_AGENT_RELIABILITY_H #define ROSA_AGENT_RELIABILITY_H #include "rosa/agent/FunctionAbstractions.hpp" #include "rosa/agent/Functionality.h" #include "rosa/agent/RangeConfidence.hpp" #include "rosa/agent/CrossReliability.h" #include +#include + +#define __ostream_output true namespace rosa { namespace agent { /// This is the Reliability Functionality for a low level Agent /// \tparam SensorValueType Datatype of the Sensor value ( Typically double or float) /// \tparam StateType Datatype of the State ( Typically long or int) /// \tparam ReliabilityType Datatype of the Reliability ( Typically double or float) /// /// use the () operator to get the reliability and feed the information from the master back to this /// \note all pointer for the functionalities will be deleted when this is object ist destroyed template class LowLevel { struct ConfOrRel { StateType score; ReliabilityType Reliability; + + ConfOrRel(StateType _score,ReliabilityType _Reliability):score(_score),Reliability(_Reliability){}; + ConfOrRel() {}; + #if __ostream_output + friend std::ostream & operator << (std::ostream &out, const ConfOrRel &c) + { + out << "Score: " << c.score << "\t Reliability: " << c.Reliability << " " ; + return out; + } + #endif }; public: /// Calculates the Conf/ Reliability /// \param SensorValue The current Values of the Sensor /// /// \return Reliability of the current Value ConfOrRel operator()(SensorValueType SensorValue) { - std::map ActuallPosibleScores_tmp = Confidence(SensorValue); + std::map ActuallPosibleScores_tmp = Confidence->operator()(SensorValue); std::vector ActuallPossibleScores; - for (auto state : States) - ActuallPossibleScores.push_back({ state, ActuallPosibleScores_tmp.find(state) }); - + for (StateType state : States) + { + if(ActuallPosibleScores_tmp.find(state)!=ActuallPosibleScores_tmp.end()) + { + ConfOrRel val; + val.score=state; + val.Reliability=ActuallPosibleScores_tmp.find(state)->second; + ActuallPossibleScores.push_back(val); + } + + } ReliabilityType inputReliability; if (PreviousSensorValueExists) inputReliability = getRelibility(SensorValue, previousSensorValue, valueSetCounter); else - inputReliability = Reliability(SensorValue); + inputReliability = Reliability->operator()(SensorValue); for (std::size_t at = 0; at < ActuallPossibleScores.size(); at++) - ActuallPossibleScores.at(at) = std::min(ActuallPossibleScores.at(at), inputReliability); + ActuallPossibleScores.at(at).Reliability = std::min(ActuallPossibleScores.at(at).Reliability, inputReliability); for (std::size_t APS_at = 0; APS_at < ActuallPossibleScores.size(); APS_at++) for (std::size_t VFM_at = 0; VFM_at < ValuesFromMaster.size(); VFM_at++) { if (ActuallPossibleScores.at(APS_at).score == ValuesFromMaster.at(VFM_at).score) { ActuallPossibleScores.at(APS_at).Reliability = ActuallPossibleScores.at(APS_at).Reliability + ValuesFromMaster.at(VFM_at).Reliability; } } saveInHistory(ActuallPossibleScores); std::vector possibleScores; - getAllPossibleScoresBasedOnHistory(&possibleScores); - + possibleScores=getAllPossibleScoresBasedOnHistory(possibleScores); - std::sort(possibleScores.begin(), possibleScores.end(), [](ReliabilityType A, ReliabilityType B)-> bool {return A > B; }); + std::sort(possibleScores.begin(), possibleScores.end(), [](ConfOrRel A, ConfOrRel B)-> bool {return A.Reliability > B.Reliability; }); previousSensorValue = SensorValue; PreviousSensorValueExists = true; + for(auto val:ActuallPossibleScores) + std::cout <<"inside APS:" << val << "\n"; + for(auto val:possibleScores) + std::cout <<"inside PS:" << val << "\n"; + return possibleScores.at(0); } /// Needed feedback from the Master /// \param ValuesFromMaster The Scores + Reliability from the Master for this Agent void feedback(std::vector ValuesFromMaster) { this->ValuesFromMaster = ValuesFromMaster; } /// This is the setter for Confidence Function /// \param Confidence A pointer to the Functional for the Confidence void setConfidenceFunction(RangeConfidence* Confidence) { this->Confidence = Confidence; } /// This is the setter for Reliability Function /// \param Reliability A pointer to the Functional for the Reliability void setReliabilityFunction(Abstraction* Reliability) { this->Reliability = Reliability; } /// This is the setter for ReliabilitySlope Function /// \param ReliabilitySlope A pointer to the Functional for the ReliabilitySlope void setReliabilitySlopeFunction(Abstraction* ReliabilitySlope) { this->ReliabilitySlope = ReliabilitySlope; } /// This is the setter for TimeConfidence Function /// \param TimeConfidence A pointer to the Functional for the TimeConfidence void setTimeConfidenceFunction(Abstraction* TimeConfidence) { this->TimeConfidence = TimeConfidence; } + /// This is the setter for all possible States + /// \param states A vertor for all states + void setStates(std::vector states) + { + this->States=states; + } + + /// This sets the Maximum length of the Histpry + /// \param length The length + void setHistoryLength(std::size_t length) + { + this->HistoryMaxSize=length; + } + + /// deletes all given pointers - void ~LowLevel() + ~LowLevel() { delete Confidence; Confidence = nullptr; delete Reliability; Reliability = nullptr; - delete ReliabilitySlop; + delete ReliabilitySlope; ReliabilitySlope = nullptr; delete TimeConfidence; TimeConfidence = nullptr; } private: std::vector> History; std::size_t HistoryMaxSize; std::vector ValuesFromMaster; SensorValueType previousSensorValue; unsigned int valueSetCounter; std::vector States; bool PreviousSensorValueExists = false; RangeConfidence* Confidence = nullptr; Abstraction* Reliability = nullptr; Abstraction* ReliabilitySlope = nullptr; Abstraction* TimeConfidence = nullptr; /*--------------------------------- needed Funktions -----------------------------------------------------*/ /// returns the Reliability /// \param actualValue The Value of the Sensor /// \param lastValue of the Sensor this is stored in the class - /// \param valueSetCounter + /// \param valueSetCounter Todo ReliabilityType getRelibility(SensorValueType actualValue, SensorValueType lastValue, unsigned int valueSetCounter) { ReliabilityType relAbs = Reliability->operator()(actualValue); if (PreviousSensorValueExists) { ReliabilityType relSlo = ReliabilitySlope->operator()((lastValue - actualValue) / (SensorValueType)valueSetCounter); // calculate signal input reliability // NOTE: options would be multiply, average, AND (best to worst: // average = AND > multiply) rel = relAbs * relSlo; rel = (relAbs + // relSlo)/2; return std::min(relAbs, relSlo); } else return relAbs; } /// adabts the possible Scores by checking the History and combines those values currently with max /// \param possibleScores This is returned from the Master std::vector getAllPossibleScoresBasedOnHistory(std::vector possibleScores) { //iterate through all history entries std::size_t posInHistory = 0; - typedef typename std::vector>::iterator iter; - for (iter pShE = History.begin(); pShE < History.end(); pShE++, posInHistory++) { + for (auto pShE = History.begin(); pShE < History.end(); pShE++, posInHistory++) { //iterate through all possible scores of each history entry - for (typename std::vector::iterator pSh : *pShE) { + for (ConfOrRel& pSh : *pShE) { //printf("a3\n"); - int historyScore = pSh->score; - float historyConf = pSh->Reliability; + StateType historyScore = pSh.score; + ReliabilityType historyConf = pSh.Reliability; //combine each history score with the confidence of time //NOTE: multiplication, AND, or average would be alternatives (best to worst: multiplication = AND = average) - historyConf = historyConf * TimeConfidence(posInHistory); + historyConf = historyConf * TimeConfidence->operator()(posInHistory); //historyConf = (historyConf + TimeConfidence(posInHistory)) / 2; //historyConf = std::min(historyConf, TimeConfidence(posInHistory)); //printf("a4\n"); bool foundScore = false; for (ConfOrRel& pS : possibleScores) { - if (pS->score == historyScore) { + if (pS.score == historyScore) { //calculate confidence for score //NOTE: multiplication, AND, or average would be alternatives (best to worst: AND >> average = multiplication ) //pS->confOrRel = pS->confOrRel * historyConf; //pS->confOrRel = (pS->confOrRel + historyConf) / 2; - pS->confOrRel = std::max(pS->confOrRel, historyConf); + pS.Reliability = std::max(pS.Reliability, historyConf); foundScore = true; } } if (foundScore == false) { ConfOrRel possibleScore; possibleScore.score = historyScore; possibleScore.Reliability = historyConf; - possibleScores->push_back(possibleScore); + possibleScores.push_back(possibleScore); } } } return possibleScores; } /// saves the Scores in the History /// \param actualPossibleScores The Scores which should be saved void saveInHistory(std::vector actualPossibleScores) { //check if the reliability of at least one possible score is high enough bool atLeastOneRelIsHigh = false; for (ConfOrRel pS : actualPossibleScores) { if (pS.Reliability > 0.5) { atLeastOneRelIsHigh = true; } } //save possible scores if at least one possible score is high enough (or if the history is empty) if (History.size() < 1 || atLeastOneRelIsHigh == true) { - - History.push_front(actualPossibleScores); + History.insert(History.begin(),actualPossibleScores); //if history size is higher than allowed, savo oldest element while (History.size() > HistoryMaxSize) { //delete possibleScoreHistory.back(); History.pop_back(); } } } }; /// This is the Reliability Functionality for the Highlevel Agent /// \tparam StateType Datatype of the State ( Typically double or float) /// \tparam ReliabilityType Datatype of the Reliability ( Typically long or int) /// /// use the () operator to calculate the Reliability and all cross confidences for all slaves /// \note all pouinter to Funcionalities get deleted upon termitation of the object template class HighLevel { public: struct ConfOrRel { StateType score; ReliabilityType Reliability; }; struct returnType { ReliabilityType CrossReliability; std::vector>> CrossConfidence; }; + StateType MaximumState; + returnType operator()(std::vector> Values) { StateType EWS = 0; ReliabilityType combinedInputRel = 1; ReliabilityType combinedCrossRel = 1; ReliabilityType outputReliability; std::vector> Agents; std::vector>> output; std::vector output_temporary; for (auto tmp : Values) { std::pair tmp2; tmp.first = std::get<0>(tmp); tmp.second = std::get<1>(tmp); Agents.push_back(tmp); } for (auto Value : Values) { StateType sc = std::get<1>(Value); ReliabilityType rel = std::get<2>(Value); EWS = EWS + sc; combinedInputRel = std::min(combinedInputRel, rel); //calculate the cross reliability for this slave agent ReliabilityType realCrossReliabilityOfSlaveAgent = CrossReliability({ std::get<0>(Value),std::get<1>(Value) }, Agents); //AVERAGE, MULTIPLICATION, CONJUNCTION (best to worst: AVERAGE = CONJUNCTION > MULTIPLICATION >> ) output_temporary.clear(); - for (int theoreticalScore = 0; theoreticalScore <= 3; theoreticalScore++) { + for (StateType theoreticalScore = 0; theoreticalScore <= MaximumState; theoreticalScore++) { //calculate the cross reliability for this slave agent ConfOrRel data; data.score = theoreticalScore; data.Reliability = CrossConfidence(std::get<0>(Value), theoreticalScore, Agents); output_temporary.push_back(data); } output.push_back({ std::get<0>(Value),output_temporary }); combinedCrossRel = std::min(combinedCrossRel, realCrossReliabilityOfSlaveAgent); } //combine cross reliabilites and input reliabilites of all slave agents //NOTE: options would be multiply, average, AND (best to worst: ) //outputReliability = combinedInputRel * combinedCrossRel; //outputReliability = (combinedInputRel + combinedCrossRel) / 2; outputReliability = std::min(combinedInputRel, combinedCrossRel); return { outputReliability,output }; } /// This is the setter for CrossReliability Function /// param A pointer to the Functional for the CrossReliability void setFunction(CrossReliability* CrossReliability) { this->CrossReliability = CrossReliability; } /// This is the setter for CrossConfidence Function /// param A pointer to the Functional for the CrossConfidence void setFunction(CrossConfidence * CrossConfidence) { this->CrossConfidence = CrossConfidence; } /// deletes all given pointers - void ~HighLevel() + ~HighLevel() { delete CrossReliability; CrossConfidence = nullptr; delete CrossConfidence; CrossConfidence = nullptr; } private: CrossReliability* CrossReliability = nullptr; CrossConfidence * CrossConfidence = nullptr; + + }; } // namespace agent }// namespace rosa #endif // !ROSA_AGENT_RELIABILITY_H diff --git a/lib/agent/CMakeLists.txt b/lib/agent/CMakeLists.txt index d4bdebc..4a5ffef 100644 --- a/lib/agent/CMakeLists.txt +++ b/lib/agent/CMakeLists.txt @@ -1,20 +1,22 @@ 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 + ${LIB_INCLUDE_DIR}/Reliability.h + Reliability.cpp )