diff --git a/.clang-format b/Neuer Ordner/.clang-format similarity index 100% rename from .clang-format rename to Neuer Ordner/.clang-format diff --git a/.clang-tidy b/Neuer Ordner/.clang-tidy similarity index 100% rename from .clang-tidy rename to Neuer Ordner/.clang-tidy diff --git a/include/rosa/agent/Reliability.h b/include/rosa/agent/Reliability.h index 4ea9428..28ead80 100644 --- a/include/rosa/agent/Reliability.h +++ b/include/rosa/agent/Reliability.h @@ -1,155 +1,106 @@ //===-- rosa/agent/Reliability.h --------------------------------*- C++ -*-===// // // The RoSA Framework // //===----------------------------------------------------------------------===// /// /// \file rosa/agent/Reliability.h /// /// \author Daniel Schnoell (danielschnoell@tuwien.ac.at) /// /// \date 2019 /// /// \brief Declaration of `rosa::Reliability` base-class. /// //===----------------------------------------------------------------------===// #ifndef ROSA_AGENT_RELIABILITY_H #define ROSA_AGENT_RELIABILITY_H #include "rosa/agent/FunctionAbstractions.hpp" #include "rosa/agent/Functionality.h" -#include "rosa/agent/RangeConfidence.h" +#include "rosa/agent/RangeConfidence.hpp" #include namespace rosa { -namespace agent { - -template class Reliability_LowLevel : public Functionality { - struct PossibleScore { - int score; - Type confOrRel; - }; - std::vector Sensor_History; - std::vector actualPossibleScores; - vector *suggestedScores; - Abstraction *reliabilityAbsolute; - Abstraction *reliabilitySlope; - Confidence - - long ValueSetCounter = 1; // I have no idea what this is - - Type getRelibility(Type actualValue, Type lastValue, - unsigned int valueSetCounter) { - - Type relAbs, relSlo; - - relAbs = reliabilityAbsolute(actualValue); - relSlo = - reliabilitySlope((lastValue - actualValue) / (Type)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; - rel = std::min(relAbs, relSlo); - - return rel; - } - - Type getInputReliability(Type actualSensorValue) { - - Type inputReliability; - Type previousSensorValue; - - if (Sensor_History.size() > 0) { - inputReliability = reliabilityModule->getRelibility( - actualSensorValue, Sensor_History.at(0), ValueSetCounter); - } else { - inputReliability = - reliabilityModule->getAbsoluteReliability(actualSensorValue); - } - return inputReliability; - } - - void triggerLowLevelAgent(Type actualSensorValue) { - - // calculate input reliability - inputReliability = getInputReliability(actualSensorValue); - - // combine input reliability and confidence for all actual possible - // scores - combineConfidenceAndReliabilityOfActualPossibleScores(actualPossibleScores, - inputReliability); - - // printf("#actualPossibleScores (after combi): %u\n", - // actualPossibleScores->size()); - - // FROM HERE - MASTER INPUT - // clear suggested scores from last cycle - masterAgentHandlerOfAgent->clearSuggestedScores(); - masterAgentHandlerOfAgent->read_masterAgentValues(); - - vector *suggestedScores = - masterAgentHandlerOfAgent->getSuggestedScores(); - - // if (id == 6) - // printf("++++++++\nsuggestedScores: %u\nactualPossibleScores: - // %u\n+++++++++\n", suggestedScores->size(), - // actualPossibleScores->size()); - - for (auto &sS : *suggestedScores) { - for (auto &aPs : *actualPossibleScores) { - if (aPs->score == sS->score) { - // combine suggested score with actual score - // NOTE: multiplication, AND, or average would be alternatives - // (best to worst: AND > multiplication >> average) aPs->confOrRel - // = std::min(aPs->confOrRel, sS->confOrRel); - aPs->confOrRel = (aPs->confOrRel + sS->confOrRel); - // aPs->confOrRel = aPs->confOrRel * sS->confOrRel; - } - } - } - // TO HERE - MASTER INPUT - - // if (id == 6) - // printf("++++++++\nsuggestedScores: %u\nactualPossibleScores: - // %u\n+++++++++\n", suggestedScores->size(), - // actualPossibleScores->size()); - - // save actual possible scores in history - saveActualPossibleScoresInHistory(actualPossibleScores); - - // evaluate all possible scores (based on the history) - vector possibleScores; - - // printf("SIZE BEFORE: %u\n", possibleScores.size()); - - getAllPossibleScoresBasedOnHistory(&possibleScores); - - // printf("SIZE AFTER: %u\n", possibleScores.size()); - - // sort all possible scores so that outputRel_i >= outputRel_i+1 - std::sort(possibleScores.begin(), possibleScores.end(), compareByConfRel); + namespace agent { - // send possible scores to high level agent - // sendPossibleScoresToMaster(&possibleScores); + template + class try_2 { + struct ConfOrRel { + StateType score; + ReliabilityType Reliability; + }; - for (auto &pS : possibleScores) { -#ifdef PRINT - printf(" > possible Score %i / %f\n", pS->score, pS->confOrRel); -#endif // PRINT - } + std::vector> History; + std::size_t HistoryMaxSize; + std::vector ValuesFromMaster; - // send most likely score to high level agent - sendMostLikelyScoreToMaster(&possibleScores); - } -} - -}; // namespace agent + SensorValueType previousSensorValue; + unsigned int valueSetCounter; + std::vector States; -} // namespace rosa -} // namespace rosa + RangeConfidence* Confidence; + Abstraction* Reliability; + Abstraction* ReliabilitySlope; + + ReliabilityType getRelibility(SensorValueType actualValue, SensorValueType lastValue, unsigned int valueSetCounter) { + + ReliabilityType relAbs, relSlo; + + SensorValueType = Reliability(actualValue); + SensorValueType = ReliabilitySlope((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; + rel = std::min(relAbs, relSlo); + + return rel; + } + + ConfOrRel operator()(SensorValueType SensorValue) { + std::map ActuallPosibleScores_tmp = Confidence(SensorValue); + + std::vector ActuallPossibleScores; + for (auto state : States) + ActuallPossibleScores.push_back({ state, ActuallPosibleScores_tmp.find(state) }); + + ReliabilityType inputReliability; + + if (mountedAgent->getPreviousSensorValue(&previousSensorValue)) + inputReliability = Reliability(actualSensorValue, previousSensorValue, valueSetCounter); + else + inputReliability = Reliability(SensorValue); + + for (std::size_t at = 0, at < ActuallPossibleScores.size(); at++) + ActuallPossibleScores.at(at) = std::min(ActuallPossibleScores.at(at), 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; + } + } + + saveActualPossibleScoresInHistory(ActuallPossibleScores); + + std::vector possibleScores; + + getAllPossibleScoresBasedOnHistory(&possibleScores); + + + std::sort(possibleScores.begin(), possibleScores.end(), compareByConfRel); + + + previousSensorValue = SensorValue; + return possibleScores.at(0); + }; + + } // namespace agent + } // namespace rosa #endif // !ROSA_AGENT_RELIABILITY_H