Page MenuHomePhorge

No OneTemporary

Size
128 KB
Referenced Files
None
Subscribers
None
diff --git a/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp b/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp
index 05dca08..c5fe44f 100755
--- a/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp
+++ b/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp
@@ -1,106 +1,109 @@
#include "LinearFunctionBlock.h"
#include <limits>
+#define PRINT
+
LinearFunctionBlock::LinearFunctionBlock() {
#ifdef PRINT
printf(" > Linear Function Block created\n");
#endif // PRINT
}
LinearFunctionBlock::LinearFunctionBlock(char* name) : Module(name) {
#ifdef PRINT
printf(" > %s (id:%u) created\n", name, id);
#endif // PRINT
}
LinearFunctionBlock::~LinearFunctionBlock() {
LinearFunction* cur_Linear_Function;
unsigned int index_cur_Linear_Function;
unsigned int size_vec_Linear_Functions = vLinearFunctions.size();
for(index_cur_Linear_Function = 0; index_cur_Linear_Function < size_vec_Linear_Functions; index_cur_Linear_Function++){
cur_Linear_Function = vLinearFunctions[index_cur_Linear_Function];
delete cur_Linear_Function;
}
vLinearFunctions.clear();
}
//NOTE: for this time being, linear functions have to be filled beginning from lowest x value
bool LinearFunctionBlock::addLinearFunction(LinearFunction *linearFunction) {
if (vLinearFunctions.empty()) {
//printf("empty\n");
if (!(linearFunction->getDomain()->lowerBoundaryExist())) {
vLinearFunctions.push_back(linearFunction);
#ifdef PRINT
printf(" - added function\n");
#endif // PRINT
return true;
}
}
else
{
//printf("nicht empty\n");
if (vLinearFunctions.back()->getDomain()->upperBoundaryExist() && linearFunction->getDomain()->lowerBoundaryExist()) {
//printf("last function ub = %f, new function lb = %f\n", lLinearFunctions.back()->getDomain()->getUpperBoundary(), linearFunction->getDomain()->getLowerBoundary());
if (vLinearFunctions.back()->getDomain()->getUpperBoundary() == linearFunction->getDomain()->getLowerBoundary()) {
vLinearFunctions.push_back(linearFunction);
#ifdef PRINT
printf(" - added function\n");
#endif // PRINT
return true;
}
}
}
-
+#ifdef PRINT
printf(" - couldn't add function\n");
+#endif // PRINT
return false;
}
//NOTE: Specific Function for CAH Project (DATE18)
void LinearFunctionBlock::changeFunctionBlockIncr(float newBoundary) {
vLinearFunctions[1]->setDomain(true, (float)0, true, newBoundary);
vLinearFunctions[1]->setKandD((float)0, (float)0, newBoundary, (float)1);
vLinearFunctions[2]->setDomain(true, newBoundary, false);
}
void LinearFunctionBlock::changeFunctionBlockDecr(float newBoundary) {
vLinearFunctions[1]->setDomain(true, (float)0, true, newBoundary);
vLinearFunctions[1]->setKandD((float)0, (float)1, newBoundary, (float)0);
vLinearFunctions[2]->setDomain(true, newBoundary, false);
}
//TODO: jump discontinuity -> user must have the probability to set the value there
float LinearFunctionBlock::getY(float x) {
for (auto &linearFunction : vLinearFunctions) {
if (linearFunction->getDomain()->lowerBoundaryExist() && linearFunction->getDomain()->upperBoundaryExist()) {
if (x >= linearFunction->getDomain()->getLowerBoundary() && x <= linearFunction->getDomain()->getUpperBoundary()) {
return linearFunction->getY(x);
}
}
else if (linearFunction->getDomain()->lowerBoundaryExist()) {
if (x >= linearFunction->getDomain()->getLowerBoundary()) {
return linearFunction->getY(x);
}
}
else if (linearFunction->getDomain()->upperBoundaryExist()) {
if (x <= linearFunction->getDomain()->getUpperBoundary()) {
return linearFunction->getY(x);
}
}
else {
return linearFunction->getY(x);
}
}
//the next two lines should be deleted, but if you call the function getY you have to check for NaN!
printf("DEFAULT!!!!!!!!!!!\n");
getchar();
return std::numeric_limits<double>::quiet_NaN();
}
vector<LinearFunction*>& LinearFunctionBlock::get_all_LinearFunctions()
{
return vLinearFunctions;
}
diff --git a/Version_Max_07_05_2018_CMake/src/SlaveAgentHandlerOfAgent.cpp b/Version_Max_07_05_2018_CMake/src/SlaveAgentHandlerOfAgent.cpp
index b7760f9..800fdf1 100755
--- a/Version_Max_07_05_2018_CMake/src/SlaveAgentHandlerOfAgent.cpp
+++ b/Version_Max_07_05_2018_CMake/src/SlaveAgentHandlerOfAgent.cpp
@@ -1,231 +1,231 @@
#include "SlaveAgentHandlerOfAgent.h"
#include "instruction_set_architecture.h"
#include <stdio.h>
#include "printError.h"
#include <algorithm>
#define MAXNUMOF_MOUNTEDSENSORS 100
-//#define PRINT
+#define PRINT
using namespace std;
SlaveAgentHandlerOfAgent :: SlaveAgentHandlerOfAgent() {
initSlaveAgentHandler();
}
void SlaveAgentHandlerOfAgent :: initSlaveAgentHandler() {
maxNumOfMountedSlaveAgents = MAXNUMOF_MOUNTEDSENSORS;
}
bool SlaveAgentHandlerOfAgent :: mount_slaveAgentIntoSlaveAgentSlot(Channel* inputPort) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = new SlaveAgentSlotOfAgent();
if(slaveAgentSlotOfAgent != NULL) {
if(slaveAgentSlotOfAgent->set_comPort(inputPort)) {
if(vMountedSlaveAgents.size() < maxNumOfMountedSlaveAgents) {
try {
vMountedSlaveAgents.push_back(slaveAgentSlotOfAgent);
}
catch(bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
delete slaveAgentSlotOfAgent;
return false;
}
}
else {
printError("Max number of mounted slaveAgents is already reached!");
delete slaveAgentSlotOfAgent;
return false;
}
return true;
}
else {
printError("Input port is no set!");
vMountedSlaveAgents.pop_back(); //TODO: check if it is right?!?!
delete slaveAgentSlotOfAgent;
return false;
}
}
else {
printError("Couldn't create SlaveAgentSlot!");
return false;
}
}
//TODO: what to do when 2 slaveAgentSlots have the same inputPort??!!
SlaveAgentSlotOfAgent* SlaveAgentHandlerOfAgent :: get_slaveAgentSlotAddress(Channel* inputPort) {
for(auto &slaveAgentSlot : vMountedSlaveAgents) {
if(slaveAgentSlot->get_comPort() == inputPort) {
return slaveAgentSlot;
}
}
return NULL;
}
//TODO: what to do when 2 slaveAgentSlots have the same inputPort??!!
//TODO: case if slot with comPort is not in this vector
unsigned int SlaveAgentHandlerOfAgent :: get_slaveAgentSlotNumber(Channel* inputPort) {
unsigned int slotNumber = 0;
for(auto &slaveAgentSlot : vMountedSlaveAgents) {
if(slaveAgentSlot->get_comPort() == inputPort) {
return slotNumber;
}
slotNumber++;
}
return NULL;
}
//TODO: what to do when 2 slaveAgentSlots have the same historyModule??!!
SlaveAgentSlotOfAgent* SlaveAgentHandlerOfAgent :: get_slaveAgentSlotAddress(HistoryModule* historyModule) {
for(auto &slaveAgentSlot : vMountedSlaveAgents) {
if(slaveAgentSlot->get_historyModule() == historyModule) {
return slaveAgentSlot;
}
}
return NULL;
}
//TODO: what to do when 2 slaveAgentSlots have the same confidenceModule??!!
SlaveAgentSlotOfAgent* SlaveAgentHandlerOfAgent :: get_slaveAgentSlotAddress(ConfidenceModule* confidenceModule) {
for(auto &slaveAgentSlot : vMountedSlaveAgents) {
if(slaveAgentSlot->get_confidenceModule() == confidenceModule) {
return slaveAgentSlot;
}
}
return NULL;
}
bool SlaveAgentHandlerOfAgent :: demount_slaveAgentIntoSlaveAgentSlot(Channel* inputPort) {
vMountedSlaveAgents.erase(vMountedSlaveAgents.begin() + get_slaveAgentSlotNumber(inputPort));
return false;
}
//TODO: do it also for integer variables
bool SlaveAgentHandlerOfAgent :: read_slaveAgentValue(SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent) {
if(slaveAgentSlotOfAgent != NULL) {
Channel* channel = slaveAgentSlotOfAgent->get_comPort();
if(channel != NULL) {
int msg;
if(channel->get_MsgUp(&msg)) {
if(msg == ISA_SensoryData) {
//printf("got msg: \n");
float inputValue;
if(channel->get_MsgUp(&inputValue)) {
slaveAgentSlotOfAgent->setSlaveAgentValue(inputValue);
//printf("got value: %f\n", inputValue);
return true;
}
}
}
}
}
return false;
}
bool SlaveAgentHandlerOfAgent :: read_allSlaveAgentValues() {
bool flag_readSlaveAgent = true;
for(auto &slaveAgentSlot : vMountedSlaveAgents) {
if(!read_slaveAgentValue(slaveAgentSlot)) {
flag_readSlaveAgent = false;
}
}
#ifdef PRINT
printf("\n");
#endif // PRINT
return flag_readSlaveAgent;
}
bool SlaveAgentHandlerOfAgent :: attach_historyModule(Channel* inputPort, HistoryModule* historyModule) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
if(slaveAgentSlotOfAgent != NULL) {
return slaveAgentSlotOfAgent->set_historyModule(historyModule);
}
return false;
}
bool SlaveAgentHandlerOfAgent :: detach_historyModule(SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent) {
if(slaveAgentSlotOfAgent != NULL) {
return slaveAgentSlotOfAgent->del_historyModule();
}
return false;
}
bool SlaveAgentHandlerOfAgent :: detach_historyModule(Channel* inputPort) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
return detach_historyModule(slaveAgentSlotOfAgent);
}
bool SlaveAgentHandlerOfAgent :: detach_historyModule(HistoryModule* historyModule) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(historyModule);
return detach_historyModule(slaveAgentSlotOfAgent);
}
HistoryModule* SlaveAgentHandlerOfAgent :: get_historyModuleOfSlaveAgentSlot(Channel* inputPort) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
return slaveAgentSlotOfAgent->get_historyModule();
}
bool SlaveAgentHandlerOfAgent :: attach_confidenceModule(Channel* inputPort, ConfidenceModule* confidenceModule) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
if(slaveAgentSlotOfAgent != NULL) {
return slaveAgentSlotOfAgent->set_confidenceModule(confidenceModule);
}
return false;
}
bool SlaveAgentHandlerOfAgent :: detach_confidenceModule(SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent) {
if(slaveAgentSlotOfAgent != NULL) {
return slaveAgentSlotOfAgent->del_confidenceModule();
}
return false;
}
bool SlaveAgentHandlerOfAgent :: detach_confidenceModule(Channel* inputPort) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
return detach_confidenceModule(slaveAgentSlotOfAgent);
}
bool SlaveAgentHandlerOfAgent :: detach_confidenceModule(ConfidenceModule* confidenceModule) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(confidenceModule);
return detach_confidenceModule(slaveAgentSlotOfAgent);
}
ConfidenceModule* SlaveAgentHandlerOfAgent :: get_confidenceModuleOfSlaveAgentSlot(Channel* inputPort) {
SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent = get_slaveAgentSlotAddress(inputPort);
return slaveAgentSlotOfAgent->get_confidenceModule();
}
vector<SlaveAgentSlotOfAgent*>* SlaveAgentHandlerOfAgent :: get_vMountedSlaveAgents() {
return &vMountedSlaveAgents;
}
bool SlaveAgentHandlerOfAgent::saveValueInHistory(SlaveAgentSlotOfAgent* slaveAgentSlotOfAgent) {
if (slaveAgentSlotOfAgent != NULL) {
//TODO: change this hardcoded value //Zeitfenster Sliding Window!!!!
while (slaveAgentSlotOfAgent->getHistoryLength() >= 10) {
slaveAgentSlotOfAgent->deleteOldestHistoryEntry();
}
//JUST FOR TESTING
//slaveAgentSlotOfAgent->printHistory();
return slaveAgentSlotOfAgent->saveValueInHistory();
}
return false;
}
bool SlaveAgentHandlerOfAgent::saveAllValuesInHistory() {
bool flagSavingSuccesful = true;
for (auto &slaveAgentSlot : vMountedSlaveAgents) {
if (!saveValueInHistory(slaveAgentSlot)) {
flagSavingSuccesful = false;
}
}
return flagSavingSuccesful;
}
diff --git a/Version_Max_07_05_2018_CMake/src/State.cpp b/Version_Max_07_05_2018_CMake/src/State.cpp
index a98ee91..07e036f 100755
--- a/Version_Max_07_05_2018_CMake/src/State.cpp
+++ b/Version_Max_07_05_2018_CMake/src/State.cpp
@@ -1,487 +1,487 @@
#include "State.h"
#include "printError.h"
#include "relationChecker.h"
#include "minmaxzeug.h"
#define INJECTIONPARTITIONING 10
-//#define PRINT
+#define PRINT
State::State() {
//discreteAveragePartitionSize = INJECTIONPARTITIONING;
discreteAveragePartitionCounter = 0;
stateIsValid = false;
}
/*
bool State::setDiscreteAveragePartitionSize(unsigned int discreteAveragePartitionSize) {
if (discreteAveragePartitionSize > 0) {
this->discreteAveragePartitionSize = discreteAveragePartitionSize;
return true;
}
return false;
}
unsigned int State::getDiscreteAveragePartitionSize() {
return discreteAveragePartitionSize;
}
*/
bool State::addSubState(vector<SubState*>* vSubStates, SlaveAgentSlotOfAgent* slot) {
SubState* subState = new (nothrow) SubState();
if (subState != NULL) {
subState->setSlot(slot);
try {
vSubStates->push_back(subState);
return true;
}
catch (bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
delete subState;
}
}
return false;
}
bool State::addInputSubState(SlaveAgentSlotOfAgent* slot) {
return addSubState(&vInputSubStates, slot);;
}
bool State::addOutputSubState(SlaveAgentSlotOfAgent* slot) {
return addSubState(&vOutputSubStates, slot);
}
void State::resetDiscreteAveragePartitionCounter() {
discreteAveragePartitionCounter = 0;
}
bool State::addNewdiscreteAveragePartition() {
bool flagWorkedForAll = true;
for (auto &subState : vInputSubStates) {
if (!subState->addNewDiscreteAverage())
flagWorkedForAll = false;
}
for (auto &subState : vOutputSubStates) {
if (!subState->addNewDiscreteAverage())
flagWorkedForAll = false;
}
return flagWorkedForAll;
}
bool State::injectValues(unsigned int discreteAveragePartitionSize) {
bool flagWorkedForAll = true;
if (discreteAveragePartitionCounter == 0) {
for (auto &subState : vInputSubStates) {
subState->deleteLastDiscreteAverageBlockIfNotCompleted(discreteAveragePartitionSize);
}
for (auto &subState : vOutputSubStates) {
subState->deleteLastDiscreteAverageBlockIfNotCompleted(discreteAveragePartitionSize);
}
flagWorkedForAll = addNewdiscreteAveragePartition();
}
if (flagWorkedForAll) {
discreteAveragePartitionCounter++;
// XXX - >= or > ??
if (discreteAveragePartitionCounter >= discreteAveragePartitionSize) {
discreteAveragePartitionCounter = 0;
}
for (auto &subState : vInputSubStates) {
if (subState->injectValue())
flagWorkedForAll = false;
}
for (auto &subState : vOutputSubStates) {
if (subState->injectValue())
flagWorkedForAll = false;
}
#ifdef PRINT
printf(" >>> Inject Values (partCounter: %u)\n", discreteAveragePartitionCounter);
#endif // PRINT
//getchar();
}
return flagWorkedForAll;
}
bool State::injectValuesAndMakeNewDiscreteAveragePartition(unsigned int discreteAveragePartitionSize) {
discreteAveragePartitionCounter = 0;
return injectValues(discreteAveragePartitionSize);
}
bool State::variablesAreRelated(vector<SubState*>* vSubStates, float thresholdToBeRelated) {
bool flagAllValuesAreRelated = true;
for (auto &subState : *vSubStates) {
if (!subState->valueIsRelated(thresholdToBeRelated)) {
flagAllValuesAreRelated = false;
}
}
return flagAllValuesAreRelated;
}
bool State::inputVariablesAreRelated(float thresholdToBeRelated) {
return variablesAreRelated(&vInputSubStates, thresholdToBeRelated);
}
bool State::outputVariablesAreRelated(float thresholdToBeRelated) {
return variablesAreRelated(&vOutputSubStates, thresholdToBeRelated);
}
unsigned int State::getNumOfInjections() {
if (!vInputSubStates.empty()) {
return vInputSubStates.front()->getNumOfInjections();
}
return 0;
}
bool State::checkSubStatesForNotDrifting(vector<SubState*>* vSubStates, unsigned int discreteAveragePartitionSize, unsigned int compareDistanceDiscreteAveragePartition, float thresholdNotDrift) {
for (auto &subState : *vSubStates) {
if (subState->getNumberOfCompletedDiscreteAverageBlocks(discreteAveragePartitionSize) > 1) {
//printf("completed blocks = %u\n", subState->getNumberOfCompletedDiscreteAverageBlocks(discreteAveragePartitionSize));
//getchar();
if (!valueIsRelatedToReferenceValue(subState->getDiscreteAverageOfFirstBlock(discreteAveragePartitionSize), subState->getDiscreteAverageOfLastBlock(discreteAveragePartitionSize), thresholdNotDrift)) {
//if (!valueIsRelatedToReferenceValue(subState->getDiscreteAverageOfBlockBeforeLastBlock(discreteAveragePartitionSize, compareDistanceDiscreteAveragePartition), subState->getDiscreteAverageOfLastBlock(discreteAveragePartitionSize), thresholdNotDrift)) {
return false;
}
}
}
//getchar();
return true;
}
bool State::checkAllVariablesForNotDrifting(unsigned int discreteAveragePartitionSize, unsigned int compareDistanceDiscreteAveragePartition, float thresholdNotDrift) {
return checkSubStatesForNotDrifting(&vInputSubStates, discreteAveragePartitionSize, compareDistanceDiscreteAveragePartition, thresholdNotDrift) && checkSubStatesForNotDrifting(&vOutputSubStates, discreteAveragePartitionSize, compareDistanceDiscreteAveragePartition, thresholdNotDrift);
}
//DATE18
float State::checkSubStatesForDriftingFuzzy(vector<SubState*>* vSubStates, unsigned int discreteAveragePartitionSize, LinearFunctionBlock* Drift) {
float confidenceDriftMax = 0;
for (auto &subState : *vSubStates) {
if (subState->getNumberOfCompletedDiscreteAverageBlocks(discreteAveragePartitionSize) > 1) {
float confidenceDrift = Drift->getY(deviationValueReferenceValue(subState->getDiscreteAverageOfLastBlock(discreteAveragePartitionSize), subState->getDiscreteAverageOfFirstBlock(discreteAveragePartitionSize)));
#ifdef PRINT
printf("confDrift = %f, deviationValueReferenceValue = %f\n", confidenceDrift, deviationValueReferenceValue(subState->getDiscreteAverageOfLastBlock(discreteAveragePartitionSize), subState->getDiscreteAverageOfFirstBlock(discreteAveragePartitionSize)));
#endif // PRINT
if (confidenceDrift > confidenceDriftMax)
confidenceDriftMax = confidenceDrift;
}
}
return confidenceDriftMax;
}
//DATE18
float State::checkAllVariablesForDriftingFuzzy(unsigned int discreteAveragePartitionSize, LinearFunctionBlock* Drift) {
float confidenceDriftInput = checkSubStatesForDriftingFuzzy(&vInputSubStates, discreteAveragePartitionSize, Drift);
float confidenceDriftOutput = checkSubStatesForDriftingFuzzy(&vOutputSubStates, discreteAveragePartitionSize, Drift);
if (confidenceDriftInput > confidenceDriftOutput)
return confidenceDriftInput;
else
return confidenceDriftOutput;
}
//DATE18
float State::variablesAreRelatedFuzzy(vector<SubState*>* vSubStates, LinearFunctionBlock* SameState) {
float confRelatedMin = 1;
for (auto &subState : *vSubStates) {
float confRelated = subState->valueIsRelatedFuzzy(SameState);
#ifdef PRINT
printf("conf %f\n", confRelated);
#endif // PRINT
if (confRelated < confRelatedMin)
confRelatedMin = confRelated;
}
return confRelatedMin;
}
float State::inputVariablesAreRelatedFuzzy(LinearFunctionBlock* SameState) {
return variablesAreRelatedFuzzy(&vInputSubStates, SameState);
}
float State::outputVariablesAreRelatedFuzzy(LinearFunctionBlock* SameState) {
return variablesAreRelatedFuzzy(&vOutputSubStates, SameState);
}
bool State::insertValueInState(LinearFunctionBlock* FuncBlockConfValStateDev, LinearFunctionBlock* FuncBlockConfInvStateDev, LinearFunctionBlock* FuncBlockConfValStateTime, LinearFunctionBlock* FuncBlockConfInvStateTime, unsigned int historySize, unsigned int discreteAveragePartitionSize) {
//bool insertionWorked = true;
if (discreteAveragePartitionCounter == 0) {
for (auto &subState : vInputSubStates)
subState->deleteLastDiscreteAverageBlockIfNotCompleted(discreteAveragePartitionSize);
for (auto &subState : vOutputSubStates)
subState->deleteLastDiscreteAverageBlockIfNotCompleted(discreteAveragePartitionSize);
//insertionWorked = addNewdiscreteAveragePartition();
addNewdiscreteAveragePartition();
}
discreteAveragePartitionCounter++;
if (discreteAveragePartitionCounter >= discreteAveragePartitionSize)
discreteAveragePartitionCounter = 0;
confValidState = 1;
confInvalidState = 0;
for (auto &subState : vInputSubStates) {
//if (!(subState->insertValueInSubState(FuncBlockConfValStateDev, FuncBlockConfInvStateDev, FuncBlockConfValStateTime, FuncBlockConfInvStateTime, historySize)))
//insertionWorked = false;
subState->insertValueInSubState(FuncBlockConfValStateDev, FuncBlockConfInvStateDev, FuncBlockConfValStateTime, FuncBlockConfInvStateTime, historySize);
confValidState = fuzzyAND(confValidState, subState->getConfidenceValidState());
confInvalidState = fuzzyOR(confInvalidState, subState->getConfidenceInvalidState());
}
for (auto &subState : vOutputSubStates) {
//if (!(subState->insertValueInSubState(FuncBlockConfValStateDev, FuncBlockConfInvStateDev, FuncBlockConfValStateTime, FuncBlockConfInvStateTime, historySize)))
//insertionWorked = false;
subState->insertValueInSubState(FuncBlockConfValStateDev, FuncBlockConfInvStateDev, FuncBlockConfValStateTime, FuncBlockConfInvStateTime, historySize);
confValidState = fuzzyAND(confValidState, subState->getConfidenceValidState());
confInvalidState = fuzzyOR(confInvalidState, subState->getConfidenceInvalidState());
}
#ifdef PRINT
printf("confValidState %f\nconfInvalidState %f\n", confValidState, confInvalidState);
#endif // PRINT
//getchar();
if (confValidState > confInvalidState) {
#ifdef PRINT
printf("VALID STATE\n");
#endif // PRINT
stateIsValid = true;
return true;
}
return false;
//return insertionWorked;
}
bool State::insertValueInState(float confValid, float confInvalid, unsigned int historySize, unsigned int discreteAveragePartitionSize) {
return true;
}
float State::getConfInputVarAreSim2State(LinearFunctionBlock* FuncBlockConfSim2StateDev, LinearFunctionBlock* FuncBlockConfSim2StateTime) {
return getConfVarAreSim2State(&vInputSubStates, FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime);
}
float State::getConfInputVarAreDif2State(LinearFunctionBlock* FuncBlockConfDif2StateDev, LinearFunctionBlock* FuncBlockConfDif2StateTime) {
return getConfVarAreDif2State(&vInputSubStates, FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime);
}
float State::getConfOutputVarAreSim2State(LinearFunctionBlock* FuncBlockConfSim2StateDev, LinearFunctionBlock* FuncBlockConfSim2StateTime) {
return getConfVarAreSim2State(&vOutputSubStates, FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime);
}
float State::getConfOutputVarAreDif2State(LinearFunctionBlock* FuncBlockConfDif2StateDev, LinearFunctionBlock* FuncBlockConfDif2StateTime) {
return getConfVarAreDif2State(&vOutputSubStates, FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime);
}
unsigned int State::getLengthOfHistory() {
if (!vInputSubStates.empty()) {
#ifdef PRINT
printf("historyLength: %u\n", vInputSubStates.front()->getSampleHistoryLength());
#endif // PRINT
return vInputSubStates.front()->getSampleHistoryLength();
}
return 0;
}
bool State::isStateValid() {
return stateIsValid;
}
float State::getConfStateValid() {
return confValidState;
}
float State::getConfStateInvalid() {
return confInvalidState;
}
//new
float State::getConfVarAreSim2State(vector<SubState*>* vSubStates, LinearFunctionBlock* FuncBlockConfSim2StateDev, LinearFunctionBlock* FuncBlockConfSim2StateTime) {
float lowestConfOfAllVarAreRelated = 1;
for (auto &subState : *vSubStates)
lowestConfOfAllVarAreRelated = fuzzyAND(lowestConfOfAllVarAreRelated, subState->getConfVarIsSim2State(FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime));
return lowestConfOfAllVarAreRelated;
}
float State::getConfVarAreDif2State(vector<SubState*>* vSubStates, LinearFunctionBlock* FuncBlockConfDif2StateDev, LinearFunctionBlock* FuncBlockConfDif2StateTime) {
float highestConfOfAllVarAreNotRelated = 0;
for (auto &subState : *vSubStates)
highestConfOfAllVarAreNotRelated = fuzzyOR(highestConfOfAllVarAreNotRelated, subState->getConfVarIsDif2State(FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime));
return highestConfOfAllVarAreNotRelated;
}
bool State::delete_All_Input_Substates()
{
SubState* cur_Sub_State;
unsigned int index_cur_Sub_State;
unsigned int size_vInSubStates = vInputSubStates.size();
for(index_cur_Sub_State = 0; index_cur_Sub_State < size_vInSubStates; index_cur_Sub_State++){
cur_Sub_State = vInputSubStates[index_cur_Sub_State];
delete cur_Sub_State;
}
vInputSubStates.clear();
return true; //added by Ali, it is an error in VS.
}
bool State::delete_All_Output_Substates()
{
SubState* cur_Sub_State;
unsigned int index_cur_Sub_State;
unsigned int size_vOutSubStates = vOutputSubStates.size();
for(index_cur_Sub_State = 0; index_cur_Sub_State < size_vOutSubStates; index_cur_Sub_State++){
cur_Sub_State = vOutputSubStates[index_cur_Sub_State];
delete cur_Sub_State;
}
vOutputSubStates.clear();
return true; //added by Ali, it is an error in VS.
}
State::~State()
{
delete_All_Input_Substates();
delete_All_Output_Substates();
}
/*
bool State :: setInjectionPartitioning(unsigned int injectionPartitioning) {
if (injectionPartitioning > 0) {
this->injectionPartitioning = injectionPartitioning;
return true;
}
return false;
}
unsigned int State :: getInjectionPartitioning() {
return injectionPartitioning;
}
bool State :: addDiscreteAveragePartition() {
AverageValue* avg = new AverageValue();
if (avg != NULL) {
try {
vDiscreteAveragePartition.push_back(avg);
return true;
}
catch (bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
delete avg;
}
}
return false;
}
bool State :: injectValue(float value) {
AverageValue* avg = NULL;
continuousStatisticValue.injectAndCalculateExtremeValue(value);
//injectionCounter++;
if (injectionPartitionCounter == 0) {
if (addDiscreteAveragePartition()) {
injectionPartitionCounter++;
avg = vDiscreteAveragePartition.back();
}
}
else {
avg = vDiscreteAveragePartition.back();
}
if (avg != NULL) {
avg->injectAndCalculateAverageValue(value);
if (injectionPartitionCounter > injectionPartitioning) {
injectionPartitionCounter = 0;
}
return true;
}
return false;
}
bool State :: valueIsRelated(float value, float thresholdToAverage) {
float diff;
float avg = continuousStatisticValue.getAverageValue();
printf("value: %f, avg: %f, th: %f\n", value, avg, thresholdToAverage);
if (value > avg)
diff = value - avg;
else
diff = avg - value;
if (diff / avg <= thresholdToAverage)
return true;
return false;
}
bool State :: isNew() {
if (continuousStatisticValue.getInjectedValuesCounter() == 0)
return true;
return false;
}
unsigned int State :: getNumberOfInjections() {
return continuousStatisticValue.getInjectedValuesCounter();
}
void State :: deleteState() {
vDiscreteAveragePartition.swap(vDiscreteAveragePartition);
}
*/
diff --git a/Version_Max_07_05_2018_CMake/src/StateHandler.cpp b/Version_Max_07_05_2018_CMake/src/StateHandler.cpp
index c3a2fb0..ee76269 100755
--- a/Version_Max_07_05_2018_CMake/src/StateHandler.cpp
+++ b/Version_Max_07_05_2018_CMake/src/StateHandler.cpp
@@ -1,1814 +1,1820 @@
#include "StateHandler.h"
#include <algorithm>
#include "printError.h"
#include "rlutil.h"
#include "relationChecker.h"
#include "minmaxzeug.h"
#include "file_util.h"
#include <iostream>
#include <ctime>
//CHANGE ALSO BOTH FUZZY FUNCTION!!!
// is used for the history length of the number of values which will be compared
//to the current value
#define MAX_STATE_HISTORY_LENGTH 10 //10
#define STOP_WHEN_BROKEN
//#define STOP_AFTER_BROKEN
//#define STOP_WHEN_DRIFT
//#define STOP_WHEN_STATE_VALID
+#define PRINT
+
+
+
//TODO: also change also hardcoded value in "SlaveAgentHandlerOfAgent.cpp"
#define SLIDINGWINDOWSIZE 3 //3 //10
#define STABLENUMBER 2 //2 //8
#define STABLETHRESHOLD (float)0.04 //0.4 //0.03
#define RELATEDTHRESHOLD (float)0.08 //0.08
#define INJECTIONPARTITIONING 5
#define CMPDISTANCE 3
#define THDRIFT (float)0.08 //0.8
#define MINNUMTOBEVALIDSTATE 11 //11 //8 //10
//three different status are for the system possible
#define STATUS_BROKEN 1
#define STATUS_DRIFT 2
#define STATUS_OKAY 3
using namespace rlutil;
void StateHandler::initStateHandler() {
+ csv_writer = NULL;
+
flagVariablesWereStable = false;
slidingWindowBufferSize = SLIDINGWINDOWSIZE;
minNumOfRelatedValuesToBeStable = STABLENUMBER;
thresholdToBeStable = STABLETHRESHOLD;
thresholdToBeRelated = RELATEDTHRESHOLD;
discreteAveragePartitionSize = INJECTIONPARTITIONING;
compareDistanceDiscreteAveragePartition = CMPDISTANCE;
thresholdNotDrift = THDRIFT;
minNumToBeValidState = MINNUMTOBEVALIDSTATE;
activeState = NULL;
maxStateHistoryLength = MAX_STATE_HISTORY_LENGTH;
time_t rawtime;
struct tm * timeinfo;
char output_file_name[200];
char datetime[80];
const std::string output_directory_name = ""; // "./output_data_csv/Opel/2018-08-09/"; there is no impact if we change it!
std::string output_file_name_str;
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(datetime, sizeof(datetime), "%Y-%m-%d_%I-%M-%S", timeinfo);
output_file_name_str = output_directory_name + "output" + datetime + ".csv";
cout << output_file_name_str << endl;
//XXX - only for now:
//Ali printf("\n csv_Writer is not NULL, but it is not initialized!! \n");
if (csv_writer == NULL) {
csv_writer = new CSV_Writer("CSV Writer", (char*)output_file_name_str.c_str());
}
//DATE18
confidenceStableInput = 0;
confidenceStableOutput = 0;
confidenceStable = 0;
confStableAdjustableThreshold = 0.5;
confidenceUnstableInput = 0;
confidenceUnstableOutput = 0;
confidenceUnstable = 0;
confidenceUnstableAdjustableThreshold = 0.5;
confidenceSameStateInput = 0;
confSameStateInputAdjustableThreshold = 0.5;
confidenceSameStateOutput = 0;
confSameStateOutputAdjustableThreshold = 0.5;
confidenceValidState = 0;
confValidStateAdjustableThreshold = 0.5;
brokenCounter = 0;
confidenceBroken = 0;
confidenceBrokenAdjustableThreshold = 0.5;
driftCounter = 0;
confidenceDrift = 0;
confidenceDriftAdjustableThreshold = 0.5;
}
StateHandler::StateHandler() {
set_name(NO_NAME);
initStateHandler();
}
StateHandler::StateHandler(char* name) {
set_name(name);
initStateHandler();
}
bool StateHandler::setDiscreteAveragePartitionSize(unsigned int discreteAveragePartitionSize) {
if (discreteAveragePartitionSize > 0) {
this->discreteAveragePartitionSize = discreteAveragePartitionSize;
return true;
}
return false;
}
unsigned int StateHandler::getDiscreteAveragePartitionSize() {
return discreteAveragePartitionSize;
}
bool StateHandler::addVariable(vector<SlaveAgentSlotOfAgent*>* vVariables, SlaveAgentSlotOfAgent* slot) {
if (vVariables != NULL && slot != NULL) {
if (find((*vVariables).begin(), (*vVariables).end(), slot) == (*vVariables).end()) {
try {
(*vVariables).push_back(slot);
return true;
}
catch (bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
}
}
}
return false;
}
bool StateHandler::addInputVariable(SlaveAgentSlotOfAgent* slot) {
return addVariable(&vInputVariables, slot);
}
bool StateHandler::addOutputVariable(SlaveAgentSlotOfAgent* slot) {
return addVariable(&vOutputVariables, slot);
}
bool StateHandler::delete_all_OuputVariables()
{
SlaveAgentSlotOfAgent* cur_sl_ag_sl_ag;
unsigned int index_v_OutVar;
unsigned int size_v_OutVar = vOutputVariables.size();
for(index_v_OutVar = 0; index_v_OutVar < size_v_OutVar; index_v_OutVar++) {
cur_sl_ag_sl_ag = vOutputVariables[index_v_OutVar];
delete cur_sl_ag_sl_ag;
}
vOutputVariables.clear();
return true; //added by Ali, it is an error in VS.
}
bool StateHandler::delete_all_InputVariables()
{
SlaveAgentSlotOfAgent* cur_sl_ag_sl_ag;
unsigned int index_v_InpVar;
unsigned int size_v_InpVar = vInputVariables.size();
for(index_v_InpVar = 0; index_v_InpVar < size_v_InpVar; index_v_InpVar++) {
cur_sl_ag_sl_ag = vInputVariables[index_v_InpVar];
delete cur_sl_ag_sl_ag;
}
vInputVariables.clear();
return true; //added by Ali, it is an error in VS.
}
bool StateHandler::delete_allStates()
{
State* cur_state;
unsigned int index_v_State;
unsigned int size_v_State = vStates.size();
for(index_v_State = 0; index_v_State < size_v_State; index_v_State++) {
cur_state = vStates[index_v_State];
delete cur_state;
}
vStates.clear();
return true; //added by Ali, it is an error in VS.
}
bool StateHandler::setSlidingWindowBufferSize(unsigned int slidingWindowBufferSize) {
if (slidingWindowBufferSize >= minNumOfRelatedValuesToBeStable) {
this->slidingWindowBufferSize = slidingWindowBufferSize;
return true;
}
return false;
}
bool StateHandler::setMinNumOfRelatedValuesToBeStable(unsigned int minNumOfRelatedValuesToBeStable) {
if (minNumOfRelatedValuesToBeStable <= slidingWindowBufferSize) {
this->minNumOfRelatedValuesToBeStable = minNumOfRelatedValuesToBeStable;
return true;
}
return false;
}
bool StateHandler::setThresholdToBeStable(float thresholdToBeStable) {
if (thresholdToBeStable >= 0 && thresholdToBeStable <= 1) {
this->thresholdToBeStable = thresholdToBeStable;
return true;
}
return false;
}
bool StateHandler::setThresholdToBeRelated(float thresholdToBeRelated) {
if (thresholdToBeRelated >= 0 && thresholdToBeRelated <= 1) {
this->thresholdToBeRelated = thresholdToBeRelated;
return true;
}
return false;
}
bool StateHandler::variablesAreStable(vector<SlaveAgentSlotOfAgent*>* vVariables) {
bool flagAllVariablesAreStable = true;
for (auto &slot : *vVariables) {
if (slot->getHistoryLength() >= slidingWindowBufferSize - 1) { //-1 because actual value is not in the history
if (slot->getNumberOfRelativesToActualValue(thresholdToBeStable) < minNumOfRelatedValuesToBeStable) { //-1 because actual value is also on of minNumOfRelatedValuesToBeStable
flagAllVariablesAreStable = false;
}
}
else {
return false;
}
}
return flagAllVariablesAreStable;
}
//Sorting with bigger Value in Front
struct descending
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
//DATE18
float StateHandler::getConfVariableIsStable(SlaveAgentSlotOfAgent* variable) {
float bestConfOf1Var = 0;
float sample;
if (variable->get_slaveAgentValue(&sample)) {
list<float> lHistoryTemporary = variable->getHistory();
vector<float> vDeviations;
for (auto &h : lHistoryTemporary)
vDeviations.push_back(deviationValueReferenceValue(sample, h));
std::sort(std::begin(vDeviations), std::end(vDeviations));
//all adaptabilities within the history of one variable
for (unsigned int numOfHistSamplesIncluded = 1; numOfHistSamplesIncluded <= vDeviations.size(); numOfHistSamplesIncluded++) {
float worstConfOfHistSampleSet = 1;
unsigned int histSampleCounter = 0;
for (auto &deviation : vDeviations) {
if (histSampleCounter >= numOfHistSamplesIncluded)
break;
worstConfOfHistSampleSet = minValueOf2Values(worstConfOfHistSampleSet, StabDeviation->getY(deviation));
histSampleCounter++;
}
bestConfOf1Var = maxValueOf2Values(bestConfOf1Var, minValueOf2Values(worstConfOfHistSampleSet, StabSamples->getY((float)histSampleCounter)));
}
}
return bestConfOf1Var;
}
//DATE18
float StateHandler::getConfVariablesAreStable(vector<SlaveAgentSlotOfAgent*>* vVariables) {
float worstConfOfAllVariables = 1;
for (auto &slot : *vVariables)
worstConfOfAllVariables = minValueOf2Values(worstConfOfAllVariables, getConfVariableIsStable(slot));
return worstConfOfAllVariables;
}
//DATE18
float StateHandler::getConfVariableIsUnstable(SlaveAgentSlotOfAgent* variable) {
float bestConfOf1Var = 0;
float sample;
if (variable->get_slaveAgentValue(&sample)) {
list<float> lHistoryTemporary = variable->getHistory();
vector<float> vDeviations;
for (auto &h : lHistoryTemporary)
vDeviations.push_back(deviationValueReferenceValue(sample, h));
sort(begin(vDeviations), end(vDeviations), descending());
//all adaptabilities within the history of one variable
for (unsigned int numOfHistSamplesIncluded = 1; numOfHistSamplesIncluded <= vDeviations.size(); numOfHistSamplesIncluded++) {
//float bestConfOfHistSampleSet = 1;
float bestConfOfHistSampleSet = 0;
unsigned int histSampleCounter = 0;
for (auto &deviation : vDeviations) {
if (histSampleCounter >= numOfHistSamplesIncluded)
break;
//bestConfOfHistSampleSet = minValueOf2Values(bestConfOfHistSampleSet, UnstabDeviation->getY(deviation));
bestConfOfHistSampleSet = maxValueOf2Values(bestConfOfHistSampleSet, UnstabDeviation->getY(deviation));
histSampleCounter++;
}
bestConfOf1Var = maxValueOf2Values(bestConfOf1Var, minValueOf2Values(bestConfOfHistSampleSet, StabSamples->getY((float)histSampleCounter)));
}
}
return bestConfOf1Var;
}
//DATE18 - Is there one unstable variable?
float StateHandler::getConfVariablesAreUnstable(vector<SlaveAgentSlotOfAgent*>* vVariables) {
float bestConfOfAllVariables = 0;
for (auto &slot : *vVariables)
bestConfOfAllVariables = maxValueOf2Values(bestConfOfAllVariables, getConfVariableIsUnstable(slot));
return bestConfOfAllVariables;
}
bool StateHandler::getConfAndUnconfVariableIsMatching(State* state, LinearFunctionBlock* confDeviation, LinearFunctionBlock* confTime, float* conf, float* unconf) {
float bestUnconfOf1Var = 0;
float worstConfOf1Var = 1;
if (state != NULL) {
}
/*
float sample;
if (variable->get_slaveAgentValue(&sample)) {
list<float> lHistoryTemporary = variable->getHistory();
vector<float> vDeviations;
for (auto &h : lHistoryTemporary)
vDeviations.push_back(deviationValueReferenceValue(sample, h));
sort(begin(vDeviations), end(vDeviations), descending());
//all adaptabilities within the history of one variable
for (unsigned int numOfHistSamplesIncluded = 1; numOfHistSamplesIncluded <= vDeviations.size(); numOfHistSamplesIncluded++) {
//float bestConfOfHistSampleSet = 1;
float bestConfOfHistSampleSet = 0;
unsigned int histSampleCounter = 0;
for (auto &deviation : vDeviations) {
if (histSampleCounter >= numOfHistSamplesIncluded)
break;
//bestConfOfHistSampleSet = minValueOf2Values(bestConfOfHistSampleSet, UnstabDeviation->getY(deviation));
bestConfOfHistSampleSet = maxValueOf2Values(bestConfOfHistSampleSet, UnstabDeviation->getY(deviation));
histSampleCounter++;
}
bestConfOf1Var = maxValueOf2Values(bestConfOf1Var, minValueOf2Values(bestConfOfHistSampleSet, StabSamples->getY((float)histSampleCounter)));
}
}
return bestConfOf1Var;
*/
return 0;
}
/*
bool StateHandler::getConfAndUnconfVariablesAreMatching(vector<SlaveAgentSlotOfAgent*>* vVariables, LinearFunctionBlock* confDeviation, LinearFunctionBlock* confTime, float* conf, float* unconf) {
float bestUnconfOfAllVariables = 0;
float worstConfOfAllVariables = 1;
for (auto &variable :* vVariables) {
bestUnconfOfAllVariables = maxValueOf2Values(bestUnconfOfAllVariables, getConfAndUnconfVariableIsMatching(variable, confDeviation, confTime, conf, unconf));
worstConfOfAllVariables = minValueOf2Values(worstConfOfAllVariables, getConfAndUnconfVariableIsMatching(variable, confDeviation, confTime, conf, unconf));
}
*conf = worstConfOfAllVariables;
*unconf = bestUnconfOfAllVariables;
return true;
}
*/
State* StateHandler::makeNewState() {
State* state = new (nothrow) State();
if (state != NULL) {
bool flagLoadVariablesWorked = true;
for (auto &slot : vInputVariables) {
if (!state->addInputSubState(slot))
flagLoadVariablesWorked = false;
}
for (auto &slot : vOutputVariables) {
if (!state->addOutputSubState(slot))
flagLoadVariablesWorked = false;
}
if (!flagLoadVariablesWorked) {
delete state;
return NULL;
}
}
else {
return NULL;
}
return state;
}
bool StateHandler::addActiveStateToStateVector() {
#ifdef PRINT
printf(" >> Save Active State\n");
#endif //PRINT
if (activeState != NULL) {
for (auto &state : vStates) {
if (state == activeState)
return true;
}
#ifdef STOP_WHEN_STATE_VALID
getchar();
#endif // STOP_WHEN_STATE_VALID
try {
vStates.push_back(activeState);
return true;
}
catch (bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
delete activeState;
}
}
return false;
}
/*
bool StateHandler::addStateAndMakeItActive() {
State* state = addState();
if (state != NULL) {
activeState = state;
return true;
}
return false;
}
*/
bool StateHandler::makeNewActiveState() {
State* state = makeNewState();
if (state != NULL) {
activeState = state;
return true;
}
return false;
}
State* StateHandler::findRelatedState() {
for (auto &state : vStates) {
if (state->inputVariablesAreRelated(thresholdToBeRelated) && state->outputVariablesAreRelated(thresholdToBeRelated)) {
return state;
}
}
return NULL;
}
bool StateHandler::findRelatedStateAndMakeItActive() {
State* state = findRelatedState();
if (state != NULL) {
activeState = state;
return true;
}
return false;
}
void StateHandler::eraseStatesWithLessInjections() {
if (activeState != NULL) {
if (activeState->getNumOfInjections() < minNumToBeValidState) {
activeState = NULL;
}
}
for (vector<State*>::iterator state = vStates.begin(); state < vStates.end(); state++) {
if ((*state)->getNumOfInjections() < minNumToBeValidState) {
//TODO: also delete all subStates (etc.) of the State? Because: Memory Leakage.
vStates.erase(state);
state--;
}
}
/*
for (auto &state : vStates) {
//TODO: also delete all subStates (etc.) of the State? Because: Memory Leakage.
if (state->getNumOfInjections() < minNumToBeValidState) {
vStates.erase(state);
}
}
*/
}
void StateHandler :: reset_States()
{
this->delete_allStates();
this->activeState = NULL;
}
void StateHandler :: reset_States_and_Slave_Agents()
{
reset_States();
this->delete_all_InputVariables();
this->delete_all_OuputVariables();
}
StateHandler :: ~StateHandler()
{
delete_all_OuputVariables();
delete_all_InputVariables();
delete_allStates();
//delete csv_writer;
}
//XXX - only for now
bool test = true;
unsigned int brokenCounter = 0, driftCounter = 0;
void printDrift() {
driftCounter++;
setColor(TXTCOLOR_YELLOW);
printf(" >> DRIFT\n");
setColor(TXTCOLOR_GREY);
test = true;
}
void printBroken() {
brokenCounter++;
setColor(TXTCOLOR_LIGHTRED);
printf(" >> BROKEN\n");
setColor(TXTCOLOR_GREY);
test = true;
}
//XXX - only for now
unsigned int old_cycle = 1;
int brokentest = 0;
/*
* makes a new state and reports if there is a anomaly = hearth piece of CAM :-)
*/
void StateHandler::trigger(unsigned int cycle) {
#ifdef PRINT
printf("cycle: %u\n", cycle);
#endif // PRINT
bool flagGotValues = true;
#ifdef PRINT
printf("Input Sample Values:\n");
#endif // PRINT
for (auto &slot : vInputVariables) {
float sampleValue;
if (!(slot->get_slaveAgentValue(&sampleValue)))
flagGotValues = false; //program never executes this line of code
#ifdef PRINT
printf("In, %s: %f\n", slot->get_comPort()->get_name(), sampleValue);
#endif // PRINT
if (cycle == 1)
csv_writer->write_field(slot->get_comPort()->get_name());
else
csv_writer->write_field(sampleValue);
csv_writer->make_new_field();
}
#ifdef PRINT
printf("Output Sample Values:\n");
#endif // PRINT
for (auto &slot : vOutputVariables) {
float sampleValue;
if (!(slot->get_slaveAgentValue(&sampleValue)))
flagGotValues = false; //program never executes this line of code
#ifdef PRINT
printf("Out, %s: %f\n", slot->get_comPort()->get_name(), sampleValue);
#endif // PRINT
if (cycle == 1)
csv_writer->write_field(slot->get_comPort()->get_name());
else
csv_writer->write_field(sampleValue);
csv_writer->make_new_field();
}
if (cycle == 1){
csv_writer->write_field("State Nr");
csv_writer->make_new_field();
csv_writer->write_field("Conf State Valid");
csv_writer->make_new_field();
csv_writer->write_field("Conf State Invalid");
csv_writer->make_new_field();
csv_writer->write_field("Conf Input unchanged");
csv_writer->make_new_field();
csv_writer->write_field("Conf Input changed");
csv_writer->make_new_field();
csv_writer->write_field("Conf Output unchanged");
csv_writer->make_new_field();
csv_writer->write_field("Conf Output changed");
csv_writer->make_new_field();
csv_writer->write_field("Status");
csv_writer->make_new_field();
csv_writer->write_field("Conf Status");
csv_writer->make_new_field();
}
else {
//in the beginning, a active state has to be created
if (activeState == NULL && vStates.empty()) {
brokenCounter = 0;
#ifdef PRINT
printf(" > new active state\n");
#endif // PRINT
makeNewActiveState();
if (activeState->insertValueInState(FuncBlockConfValStateDev, FuncBlockConfInvStateDev, FuncBlockConfValStateTime, FuncBlockConfInvStateTime, maxStateHistoryLength, discreteAveragePartitionSize))
addActiveStateToStateVector();
//NEW - Adjust FuncBlockConfSim2StateTime and FuncBlockConfDif2StateTime
float newBoundary = (float)activeState->getLengthOfHistory();
FuncBlockConfSim2StateTime->changeFunctionBlockIncr(newBoundary);
FuncBlockConfDif2StateTime->changeFunctionBlockDecr(newBoundary);
csv_writer->write_field((int)vStates.size() + 1);
csv_writer->make_new_field();
csv_writer->write_field(activeState->getConfStateValid());
csv_writer->make_new_field();
csv_writer->write_field(activeState->getConfStateInvalid());
csv_writer->make_new_field();
csv_writer->write_field(0); //confInputVarAreSim2ActiveState
csv_writer->make_new_field();
csv_writer->write_field(0); //confInputVarAreDif2ActiveState
csv_writer->make_new_field();
csv_writer->write_field(0); //confOutputVarAreSim2ActiveState
csv_writer->make_new_field();
csv_writer->write_field(0); //confOutputVarAreDif2ActiveState
csv_writer->make_new_field();
csv_writer->write_field(STATUS_OKAY);
csv_writer->make_new_field();
csv_writer->write_field(0); //Status Conf
csv_writer->make_new_field();
}
//there is an active state and/or other states
else {
float confInputVarAreSim2ActiveState = activeState->getConfInputVarAreSim2State(FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime);
float confInputVarAreDif2ActiveState = activeState->getConfInputVarAreDif2State(FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime);
float confOutputVarAreSim2ActiveState = activeState->getConfOutputVarAreSim2State(FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime);
float confOutputVarAreDif2ActiveState = activeState->getConfOutputVarAreDif2State(FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime);
float confInputIsSteady = confInputVarAreSim2ActiveState - confInputVarAreDif2ActiveState;
float confOutputIsSteady = confOutputVarAreSim2ActiveState - confOutputVarAreDif2ActiveState;
printf("input (sim/dif) %f/%f\noutput (sim/dif) %f/%f\n", confInputVarAreSim2ActiveState, confInputVarAreDif2ActiveState, confOutputVarAreSim2ActiveState, confOutputVarAreDif2ActiveState);
//same state
if ((confInputVarAreSim2ActiveState > confInputVarAreDif2ActiveState) && (confOutputVarAreSim2ActiveState > confOutputVarAreDif2ActiveState)) {
brokenCounter = 0;
#ifdef PRINT
printf(" > same state\n");
//printf("\nPROOF:\nconfInputVarAreSim2ActiveState = %f\nconfInputVarAreDif2ActiveState = %f\nconfOutputVarAreSim2ActiveState = %f\nconfOutputVarAreDif2ActiveState = %f\n", confInputVarAreSim2ActiveState, confInputVarAreDif2ActiveState, confOutputVarAreSim2ActiveState, confOutputVarAreDif2ActiveState);
#endif // PRINT
if (activeState->insertValueInState(FuncBlockConfValStateDev, FuncBlockConfInvStateDev, FuncBlockConfValStateTime, FuncBlockConfInvStateTime, maxStateHistoryLength, discreteAveragePartitionSize))
addActiveStateToStateVector();
//NEW - Adjust FuncBlockConfSim2StateTime and FuncBlockConfDif2StateTime
float newBoundary = (float)activeState->getLengthOfHistory();
FuncBlockConfSim2StateTime->changeFunctionBlockIncr(newBoundary);
FuncBlockConfDif2StateTime->changeFunctionBlockDecr(newBoundary);
//print state number
if(activeState->isStateValid())
csv_writer->write_field((int)vStates.size());
else
csv_writer->write_field((int)vStates.size()+1);
csv_writer->make_new_field();
//print conf valid
csv_writer->write_field(activeState->getConfStateValid());
csv_writer->make_new_field();
csv_writer->write_field(activeState->getConfStateInvalid());
csv_writer->make_new_field();
//print conf statechange
csv_writer->write_field(confInputVarAreSim2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confInputVarAreDif2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confOutputVarAreSim2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confOutputVarAreDif2ActiveState);
csv_writer->make_new_field();
confidenceDrift = activeState->checkAllVariablesForDriftingFuzzy(discreteAveragePartitionSize, DriftDeviation);
float confidenceNoDrift = 1 - confidenceDrift;
/*
//print conf drift
csv_writer->write_field(confidenceNoDrift);
csv_writer->make_new_field();
csv_writer->write_field(confidenceDrift);
csv_writer->make_new_field();
*/
if (confidenceDrift > 0.5) {
#ifdef PRINT
setColor(TXTCOLOR_YELLOW);
printf("DRIFT\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
#ifdef STOP_WHEN_DRIFT
getchar();
#endif // STOP_WHEN_DRIFT
setColor(TXTCOLOR_GREY);
//print drift
csv_writer->write_field(STATUS_DRIFT);
csv_writer->make_new_field();
//calc and print conf
float conf = fuzzyAND(fuzzyAND(confidenceDrift, activeState->getConfStateValid()), fuzzyAND(confInputVarAreSim2ActiveState, confOutputVarAreSim2ActiveState));
csv_writer->write_field(conf);
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("OK\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
//print ok
csv_writer->write_field(STATUS_OKAY);
csv_writer->make_new_field();
//calc and print conf
float conf = fuzzyAND(fuzzyAND(confInputVarAreSim2ActiveState, confOutputVarAreSim2ActiveState), fuzzyAND(activeState->getConfStateValid(), confidenceNoDrift));
csv_writer->write_field(conf);
}
csv_writer->make_new_field();
}
//state change
else {
//was Valid
if (activeState->isStateValid()) {
//only one sub set changed
if (((confInputVarAreSim2ActiveState > confInputVarAreDif2ActiveState) && (confOutputVarAreSim2ActiveState <= confOutputVarAreDif2ActiveState)) || ((confInputVarAreSim2ActiveState <= confInputVarAreDif2ActiveState) && (confOutputVarAreSim2ActiveState > confOutputVarAreDif2ActiveState))) {
//print state number
if (activeState->isStateValid())
csv_writer->write_field((int)vStates.size());
else
csv_writer->write_field((int)vStates.size() + 1);
csv_writer->make_new_field();
//print conf valid
csv_writer->write_field(activeState->getConfStateValid());
csv_writer->make_new_field();
csv_writer->write_field(activeState->getConfStateInvalid());
csv_writer->make_new_field();
//print conf statechange
csv_writer->write_field(confInputVarAreSim2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confInputVarAreDif2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confOutputVarAreSim2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confOutputVarAreDif2ActiveState);
csv_writer->make_new_field();
brokenCounter++;
printf("brokenCounter: %u\n", brokenCounter);
confidenceBroken = FuncBlockConfBrokenSamples->getY((float) brokenCounter);
float confidenceOK = 1 - confidenceBroken;
if (confidenceBroken > 0.5) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("BROKEN\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
#ifdef STOP_AFTER_BROKEN
brokentest = 1;
#endif // STOP_AFTER_BROKEN
#ifdef STOP_WHEN_BROKEN
getchar();
#endif // STOP_WHEN_BROKEN
//print broken
csv_writer->write_field(STATUS_BROKEN);
csv_writer->make_new_field();
//calculate and print conf
float conf = fuzzyAND(fuzzyOR(confInputVarAreDif2ActiveState, confOutputVarAreDif2ActiveState), fuzzyAND(confidenceBroken, activeState->getConfStateValid()));
csv_writer->write_field(conf);
//csv_writer->make_new_field();
}
else {
//print ok
csv_writer->write_field(STATUS_OKAY);
csv_writer->make_new_field();
//calculate and print conf
float conf = fuzzyAND(fuzzyOR(fuzzyAND(confInputVarAreSim2ActiveState, confOutputVarAreSim2ActiveState), fuzzyAND(confInputVarAreDif2ActiveState, confOutputVarAreDif2ActiveState)), fuzzyAND(confidenceOK, activeState->getConfStateValid()));
csv_writer->write_field(conf);
}
}
//In- and output changed
else {
brokenCounter = 0;
printf(" > delete active state\n");
activeState = NULL;
printf(" > new active state\n");
// search in vector for matching state //TODO in future: look for the best matching, Not for the first matching
bool flagFoundMatchingState = false;
float confInputVarAreSim2ActiveState;
float confInputVarAreDif2ActiveState;
float confOutputVarAreSim2ActiveState;
float confOutputVarAreDif2ActiveState;
for (auto &state : vStates) {
confInputVarAreSim2ActiveState = state->getConfInputVarAreSim2State(FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime);
confInputVarAreDif2ActiveState = state->getConfInputVarAreDif2State(FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime);
confOutputVarAreSim2ActiveState = state->getConfOutputVarAreSim2State(FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime);
confOutputVarAreDif2ActiveState = state->getConfOutputVarAreDif2State(FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime);
if ((confInputVarAreSim2ActiveState > confInputVarAreDif2ActiveState) && (confOutputVarAreSim2ActiveState > confOutputVarAreDif2ActiveState)) {
activeState = state;
flagFoundMatchingState = true;
}
}
if (flagFoundMatchingState == false) {
makeNewActiveState();
confInputVarAreSim2ActiveState = 0;
confInputVarAreDif2ActiveState = 0;
confOutputVarAreSim2ActiveState = 0;
confOutputVarAreDif2ActiveState = 0;
}
//insert in activeState
if (activeState->insertValueInState(FuncBlockConfValStateDev, FuncBlockConfInvStateDev, FuncBlockConfValStateTime, FuncBlockConfInvStateTime, maxStateHistoryLength, discreteAveragePartitionSize))
addActiveStateToStateVector();
//NEW - Adjust FuncBlockConfSim2StateTime and FuncBlockConfDif2StateTime
float newBoundary = (float)activeState->getLengthOfHistory();
FuncBlockConfSim2StateTime->changeFunctionBlockIncr(newBoundary);
FuncBlockConfDif2StateTime->changeFunctionBlockDecr(newBoundary);
//print state number
if (activeState->isStateValid())
csv_writer->write_field((int)vStates.size());
else
csv_writer->write_field((int)vStates.size() + 1);
csv_writer->make_new_field();
//print conf valid
csv_writer->write_field(activeState->getConfStateValid());
csv_writer->make_new_field();
csv_writer->write_field(activeState->getConfStateInvalid());
csv_writer->make_new_field();
//print conf statechange
csv_writer->write_field(confInputVarAreSim2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confInputVarAreDif2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confOutputVarAreSim2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confOutputVarAreDif2ActiveState);
csv_writer->make_new_field();
confidenceDrift = activeState->checkAllVariablesForDriftingFuzzy(discreteAveragePartitionSize, DriftDeviation);
float confidenceNoDrift = 1 - confidenceDrift;
if (confidenceDrift > 0.5) {
setColor(TXTCOLOR_YELLOW);
printf("DRIFT\n");
#ifdef STOP_WHEN_DRIFT
getchar();
#endif // STOP_WHEN_DRIFT
setColor(TXTCOLOR_GREY);
//print drift
csv_writer->write_field(STATUS_DRIFT);
csv_writer->make_new_field();
//calc and print conf
float conf = fuzzyAND(confidenceDrift, activeState->getConfStateValid());
csv_writer->write_field(conf);
}
else {
setColor(TXTCOLOR_LIGHTGREEN);
printf("OK\n");
setColor(TXTCOLOR_GREY);
//print ok
csv_writer->write_field(STATUS_OKAY);
csv_writer->make_new_field();
//calc and print conf
float conf = fuzzyAND(fuzzyAND(confInputVarAreDif2ActiveState, confOutputVarAreDif2ActiveState), fuzzyAND(activeState->getConfStateValid(), confidenceNoDrift));
csv_writer->write_field(conf);
}
csv_writer->make_new_field();
}
}
//was NOT Valid
else {
brokenCounter = 0;
printf(" > delete active state\n");
delete activeState;
activeState = NULL;
printf(" > new active state\n");
// search in vector for matching state //TODO in future: look for the best matching, Not for the first matching
bool flagFoundMatchingState = false;
float confInputVarAreSim2ActiveState;
float confInputVarAreDif2ActiveState;
float confOutputVarAreSim2ActiveState;
float confOutputVarAreDif2ActiveState;
for (auto &state : vStates) {
confInputVarAreSim2ActiveState = state->getConfInputVarAreSim2State(FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime);
confInputVarAreDif2ActiveState = state->getConfInputVarAreDif2State(FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime);
confOutputVarAreSim2ActiveState = state->getConfOutputVarAreSim2State(FuncBlockConfSim2StateDev, FuncBlockConfSim2StateTime);
confOutputVarAreDif2ActiveState = state->getConfOutputVarAreDif2State(FuncBlockConfDif2StateDev, FuncBlockConfDif2StateTime);
if ((confInputVarAreSim2ActiveState > confInputVarAreDif2ActiveState) && (confOutputVarAreSim2ActiveState > confOutputVarAreDif2ActiveState)) {
activeState = state;
flagFoundMatchingState = true;
}
}
if (flagFoundMatchingState == false) {
makeNewActiveState();
confInputVarAreSim2ActiveState = 0;
confInputVarAreDif2ActiveState = 0;
confOutputVarAreSim2ActiveState = 0;
confOutputVarAreDif2ActiveState = 0;
}
//insert in active state
if (activeState->insertValueInState(FuncBlockConfValStateDev, FuncBlockConfInvStateDev, FuncBlockConfValStateTime, FuncBlockConfInvStateTime, maxStateHistoryLength, discreteAveragePartitionSize))
addActiveStateToStateVector();
//NEW - Adjust FuncBlockConfSim2StateTime and FuncBlockConfDif2StateTime
float newBoundary = (float)activeState->getLengthOfHistory();
FuncBlockConfSim2StateTime->changeFunctionBlockIncr(newBoundary);
FuncBlockConfDif2StateTime->changeFunctionBlockDecr(newBoundary);
//print state number
if (activeState->isStateValid())
csv_writer->write_field((int)vStates.size());
else
csv_writer->write_field((int)vStates.size() + 1);
csv_writer->make_new_field();
//print conf valid
csv_writer->write_field(activeState->getConfStateValid());
csv_writer->make_new_field();
csv_writer->write_field(activeState->getConfStateInvalid());
csv_writer->make_new_field();
//print conf statechange
csv_writer->write_field(confInputVarAreSim2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confInputVarAreDif2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confOutputVarAreSim2ActiveState);
csv_writer->make_new_field();
csv_writer->write_field(confOutputVarAreDif2ActiveState);
csv_writer->make_new_field();
confidenceDrift = activeState->checkAllVariablesForDriftingFuzzy(discreteAveragePartitionSize, DriftDeviation);
float confidenceNoDrift = 1 - confidenceDrift;
if (confidenceDrift > 0.5) {
setColor(TXTCOLOR_YELLOW);
printf("DRIFT\n");
#ifdef STOP_WHEN_DRIFT
getchar();
#endif // STOP_WHEN_DRIFT
setColor(TXTCOLOR_GREY);
//print drift
csv_writer->write_field(2);
csv_writer->make_new_field();
//calc and print conf
float conf = fuzzyAND(confidenceDrift, activeState->getConfStateValid());
csv_writer->write_field(conf);
}
else {
setColor(TXTCOLOR_LIGHTGREEN);
printf("OK\n");
setColor(TXTCOLOR_GREY);
//print ok
csv_writer->write_field(STATUS_OKAY);
csv_writer->make_new_field();
//calc and print conf
float conf = fuzzyAND(fuzzyAND(confInputVarAreDif2ActiveState, confOutputVarAreDif2ActiveState), fuzzyAND(activeState->getConfStateValid(), confidenceNoDrift));
csv_writer->write_field(conf);
}
csv_writer->make_new_field();
}
}
#ifdef PRINT
printf("STATES: %u\n", vStates.size());
#endif // PRINT
}
}
csv_writer->make_new_line();
if (brokentest)
getchar();
/*
//XXX - only for now
for (unsigned int i = 1; i < (cycle - old_cycle); i++) {
csv_writer->make_new_field();
csv_writer->make_new_field();
csv_writer->make_new_field();
csv_writer->make_new_line();
//printf("%u\n", i);
}
old_cycle = cycle;
confidenceStableInput = getConfVariablesAreStable(&vInputVariables);
confidenceStableOutput = getConfVariablesAreStable(&vOutputVariables);
confidenceStable = minValueOf2Values(confidenceStableInput, confidenceStableOutput);
printf("confidence stable: %f\n", confidenceStable);
confidenceUnstableInput = getConfVariablesAreUnstable(&vInputVariables);
confidenceUnstableOutput = getConfVariablesAreUnstable(&vOutputVariables);
printf("unstable In: %f, Out: %f\n", confidenceUnstableInput, confidenceUnstableOutput);
confidenceUnstable = maxValueOf2Values(confidenceUnstableInput, confidenceUnstableOutput);
printf("confidence unstable: %f\n", confidenceUnstable);
if (confidenceUnstableInput > 0) {
printf("jetzt\n");
getchar();
}
//TEST
if (confidenceStable > confidenceUnstable) {
setColor(TXTCOLOR_LIGHTBLUE);
printf("jetzt\n");
setColor(TXTCOLOR_GREY);
getchar();
}
//getchar();
if (confidenceStable > confidenceUnstable) {
//if (false) {
printf(" > stable\n");
//for the beginning (there is no state available/created) -> create state
if (activeState == NULL && vStates.empty()) {
printf(" > new state\n");
makeNewActiveState();
activeState->injectValues(discreteAveragePartitionSize);
confidenceValidState = ValidState->getY((float)activeState->getNumOfInjections());
}
//there is an active state
else if (activeState != NULL) {
//caclulate confidences of deciding for same state
float confidenceSameStateInput = activeState->inputVariablesAreRelatedFuzzy(SameState);
float confidenceSameStateOutput = activeState->outputVariablesAreRelatedFuzzy(SameState);
printf("ConfSameState\nIn: %f\nout: %f\n", confidenceSameStateInput, confidenceSameStateOutput);
//In- and Outputs are unchanged
if ((confidenceSameStateInput > confSameStateInputAdjustableThreshold) && (confidenceSameStateOutput > confSameStateOutputAdjustableThreshold)) {
printf(" > same state\n");
//inject values
activeState->injectValues(discreteAveragePartitionSize);
//calculate the confidence to have a validState
confidenceValidState = ValidState->getY((float)activeState->getNumOfInjections());
//TODO DATE
//check for drifting!!!
//printDrift();
}
//In- and Outputs have changed
else if ((confidenceSameStateInput <= confSameStateInputAdjustableThreshold) && (confidenceSameStateOutput <= confSameStateOutputAdjustableThreshold)) {
printf(" > change state\n");
getchar();
//active state is/was valid
if (confidenceValidState > confValidStateAdjustableThreshold) {
printf("speicher\n");
getchar();
addActiveStateToStateVector();
//TODO DATE
//search for matching state
//or
printf(" > new state\n");
//create an new active state
makeNewActiveState();
//inject values
activeState->injectValues(discreteAveragePartitionSize);
//calculate the confidence to have a validState
confidenceValidState = ValidState->getY((float)activeState->getNumOfInjections());
//TODO DATE
//check for drifting!!!
//printDrift();
}
}
//Only in- or outputs have changed
else {
//active state is/was valid
if (confidenceValidState > confValidStateAdjustableThreshold) {
addActiveStateToStateVector();
printf(" > broken\n");
brokenCounter++;
confidenceBroken = BrokenCounterSamples->getY(brokenCounter);
//getchar();
//TODO DATE??
//Save State
}
}
}
//there is no active state, but there is/are state(s)
else {
printf(" > old or new state\n");
//getchar();
//TODO DATE
//search for matching state
//or
printf(" > new state\n");
makeNewActiveState();
activeState->injectValues(discreteAveragePartitionSize);
confidenceValidState = ValidState->getY((float)activeState->getNumOfInjections());
//TODO DATE
//check for drifting!!!
//printDrift();
}
if (activeState != NULL) {
confidenceDrift = activeState->checkAllVariablesForDriftingFuzzy(discreteAveragePartitionSize, DriftDeviation);
}
//getchar();
}
//unstable
else {
printf(" > unstable\n");
//there is/was an active state
if (activeState != NULL) {
//delete activeState;
if (confidenceValidState > confValidStateAdjustableThreshold)
addActiveStateToStateVector();
activeState = NULL;
}
}
//DATE TODO
//STABLE CONFIDENCE MITEINBEZIEHEN
if ((confidenceBroken >= confidenceBroken) && (confidenceBroken > confidenceBrokenAdjustableThreshold)) {
setColor(TXTCOLOR_LIGHTRED);
printf(" >> BROKEN - confidence %f\n", confidenceBroken);
setColor(TXTCOLOR_GREY);
getchar();
}
else if (confidenceDrift > confidenceDriftAdjustableThreshold) {
setColor(TXTCOLOR_YELLOW);
printf(" >> DRIFT - confidence %f\n", confidenceDrift);
setColor(TXTCOLOR_GREY);
//XXXXXXXXXX ????????????????????????????????????
if (brokenCounter > 0)
brokenCounter--;
getchar();
}
else {
setColor(TXTCOLOR_LIGHTGREEN);
float confidenceOK;
if (confidenceDrift > confidenceBroken)
confidenceOK = 1 - confidenceDrift;
else
confidenceOK = 1 - confidenceBroken;
printf(" >> SYSTEM OK - confidence %f\n", confidenceOK);
setColor(TXTCOLOR_GREY);
}
printf("brokenCounter %u\n", brokenCounter);
printf("number of states: %i\n", vStates.size());
*/
/*
if (variablesAreStable(&vInputVariables) && variablesAreStable(&vOutputVariables)) {
printf(" > stable\n");
//XXX - only for now
csv_writer->write_field(2); //stable
csv_writer->make_new_field();
//getchar();
if (activeState == NULL && vStates.empty()) {
makeNewActiveState();
activeState->injectValues(discreteAveragePartitionSize);
//XXX - only for now
csv_writer->write_field(1); //new active state
csv_writer->make_new_field();
csv_writer->make_new_field();
}
else {
if (activeState != NULL) {
printf("\nbeginning here:\n");
bool flagInputUnchanged = activeState->inputVariablesAreRelated(thresholdToBeRelated);
bool flagOutputUnchanged = activeState->outputVariablesAreRelated(thresholdToBeRelated);
//input and/or output unchanged?
if (flagInputUnchanged && flagOutputUnchanged) {
activeState->injectValues(discreteAveragePartitionSize);
if (!activeState->checkAllVariablesForNotDrifting(discreteAveragePartitionSize, compareDistanceDiscreteAveragePartition, thresholdNotDrift)) {
printDrift();
//XXX - only for now
csv_writer->make_new_field();
csv_writer->write_field(1); //drift
csv_writer->make_new_field();
}
//XXX - only for now
else {
csv_writer->make_new_field();
csv_writer->make_new_field();
}
}
else {
if (activeState->getNumOfInjections() >= minNumToBeValidState) {
if ((!flagInputUnchanged && flagOutputUnchanged) || (flagInputUnchanged && !flagOutputUnchanged)) {
printBroken();
getchar();
//XXX - only for now
csv_writer->make_new_field();
csv_writer->write_field(2); //broken
csv_writer->make_new_field();
}
else {
addActiveStateToStateVector();
if (!findRelatedStateAndMakeItActive()) {
makeNewActiveState();
activeState->injectValues(discreteAveragePartitionSize);
//XXX - only for now
csv_writer->write_field(1); //new active state
csv_writer->make_new_field();
csv_writer->make_new_field();
}
else {
//next line is new
activeState->resetDiscreteAveragePartitionCounter();
//XXX - only for now
csv_writer->write_field(2); //change to existing state
csv_writer->make_new_field();
activeState->injectValues(discreteAveragePartitionSize);
if (!activeState->checkAllVariablesForNotDrifting(discreteAveragePartitionSize, compareDistanceDiscreteAveragePartition, thresholdNotDrift)) {
printDrift();
//XXX - only for now
csv_writer->write_field(1); //drift
csv_writer->make_new_field();
}
//XXX - only for now
else {
csv_writer->make_new_field();
}
}
}
}
else {
delete activeState;
if (!findRelatedStateAndMakeItActive()) {
makeNewActiveState();
activeState->injectValues(discreteAveragePartitionSize);
//XXX - only for now
csv_writer->write_field(1); //new active state
csv_writer->make_new_field();
csv_writer->make_new_field();
}
else {
//next line is new
activeState->resetDiscreteAveragePartitionCounter();
//XXX - only for now
csv_writer->write_field(2); //change to existing state
csv_writer->make_new_field();
activeState->injectValues(discreteAveragePartitionSize);
if (!activeState->checkAllVariablesForNotDrifting(discreteAveragePartitionSize, compareDistanceDiscreteAveragePartition, thresholdNotDrift)) {
printDrift();
//XXX - only for now
csv_writer->write_field(1); //drift
csv_writer->make_new_field();
}
//XXX - only for now
else {
csv_writer->make_new_field();
}
}
}
}
}
else {
if (!findRelatedStateAndMakeItActive()) {
makeNewActiveState();
activeState->injectValues(discreteAveragePartitionSize);
//XXX - only for now
csv_writer->write_field(1); //new active state
csv_writer->make_new_field();
csv_writer->make_new_field();
}
else {
//next line is new
activeState->resetDiscreteAveragePartitionCounter();
//XXX - only for now
csv_writer->write_field(2); //change to existing state
csv_writer->make_new_field();
activeState->injectValues(discreteAveragePartitionSize);
if (!activeState->checkAllVariablesForNotDrifting(discreteAveragePartitionSize, compareDistanceDiscreteAveragePartition, thresholdNotDrift)) {
printDrift();
//XXX - only for now
csv_writer->write_field(1); //drift
csv_writer->make_new_field();
}
//XXX - only for now
else {
csv_writer->make_new_field();
}
}
}
}
if (activeState != NULL) {
printf(" -- an activeState exist: \n");
printf(" --- injections: %u\n", activeState->getNumOfInjections());
//XXX - only for now
csv_writer->write_field((int)activeState->getNumOfInjections()); //number of injections
csv_writer->make_new_line();
}
//XXX - only for now
else {
csv_writer->make_new_field();
}
printf(" -- Number of States (excl. activeState): %u\n", vStates.size());
for (auto &s : vStates) {
printf(" --- injections: %u\n", s->getNumOfInjections());
}
printf(" ... BrokenCounter: %u\n", brokenCounter);
printf(" ... driftCounter: %u\n", driftCounter);
printf("cycle: %u\n", cycle);
if (test) {
test = false;
//getchar();
}
flagVariablesWereStable = true;
}
else {
printf(" > unstable\n");
//XXX - only for now
csv_writer->write_field(1); //unstable
csv_writer->make_new_field();
csv_writer->make_new_field();
csv_writer->make_new_field();
csv_writer->make_new_line();
if (flagVariablesWereStable)
test = true;
//search for states with less injections in all states
if (flagVariablesWereStable) {
if (activeState != NULL) {
if (activeState->getNumOfInjections() >= minNumToBeValidState) {
addActiveStateToStateVector();
}
else {
delete activeState;
}
activeState = NULL;
//getchar();
}
}
flagVariablesWereStable = false;
}
//xxx - only for now
//csv_writer->make_new_line();
*/
}
void StateHandler::closeCsvFile() {
if(csv_writer != NULL)
csv_writer->close_file();
}
string StateHandler::create_Output_File_Name(string cfg_parameter)
{
time_t rawtime;
struct tm * timeinfo;
char output_file_name[200];
char datetime[80];
std::string output_file_name_str;
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(datetime, sizeof(datetime), "%Y-%m-%d_%I-%M-%S", timeinfo);
output_file_name_str = output_directory_name + "output" + datetime + cfg_parameter + ".csv";
//cout << output_file_name_str << endl;
return output_file_name_str;
}
void StateHandler::set_CSV_Writer_parameter(string cfg_parameter)
{
string cur_Output_File_Name = this->create_Output_File_Name(cfg_parameter);
csv_writer->reset_fpointer(cur_Output_File_Name);
}
/*
void StateHandler :: initStateHandler() {
//activeState = NULL;
thresholdToAverage = THRESHOLDTOAVG;
minNumOfChangedForValidStateChange = MINNUMCHANGEDFORVALIDSTATECHANGE;
minimumInjectionsForBeingState = MININJFORBEINGSTATE;
}
StateHandler :: StateHandler() {
set_name(NO_NAME);
initStateHandler();
}
StateHandler :: StateHandler(char* name) {
set_name(name);
initStateHandler();
}
bool StateHandler :: setMinimumInjectionsForBeingState(unsigned int minimumInjectionsForBeingState) {
if (minimumInjectionsForBeingState > 0) {
this->minimumInjectionsForBeingState = minimumInjectionsForBeingState;
return true;
}
return false;
}
unsigned int StateHandler :: getMinimumInjectionsForBeingState() {
return minimumInjectionsForBeingState;
}
bool StateHandler :: add_slot(SlaveAgentSlotOfAgent* slot) {
if(slot != NULL) {
try {
vSlots.push_back(slot);
return true;
}
catch(bad_alloc& error) {
printError("bad_alloc caught: ", error.what());
delete slot;
}
}
return false;
}
void StateHandler :: setThresholdToAverage(float thresholdToAverage) {
this->thresholdToAverage = thresholdToAverage;
}
float StateHandler :: getThresholdToAverage() {
return thresholdToAverage;
}
void StateHandler::set_minNumOfChangedForValidStateChange(unsigned int minNumOfChangedForValidStateChange) {
this->minNumOfChangedForValidStateChange = minNumOfChangedForValidStateChange;
}
unsigned int StateHandler::get_minNumOfChangedForValidStateChange() {
return minNumOfChangedForValidStateChange;
}
bool StateHandler :: trigger() {
bool flagWorked = true;
printf("NumOfStates: ");
for (auto &slot : vSlots) {
printf("%u, ", slot->getNumberOfStates());
}
printf("\n");
//Check all input values if they have changed more than threshold ...and count how many changed
unsigned int numberOfChanges = 0;
for (auto &slot : vSlots) {
float value;
if (slot->get_slaveAgentValue(&value)) {
State* activeState = slot->getActiveState();
if (activeState != NULL) {
printf("act - ");
if (activeState->isNew()) {
printf("new - ");
//numberOfChanges++;
}
else if (activeState->valueIsRelated(value, thresholdToAverage)) {
printf("rel - ");
}
else {
printf("nrel - ");
numberOfChanges++;
}
}
else {
printf("nact - ");
}
}
}
printf("\n");
printf(" >> Number of Changes: %u\n", numberOfChanges);
//nothing has changes more than threshold
if (numberOfChanges == 0) {
printf("\n\n >>> inject in active state\n");
for (auto &slot : vSlots) {
slot->injectValueInActiveState();
}
}
else if(numberOfChanges >= minNumOfChangedForValidStateChange) {
printf("\n\n >>> new (or another) state\n");
for (auto &slot : vSlots) {
State* activeState = slot->getActiveState();
if (activeState != NULL) {
if (activeState->getNumberOfInjections() < minimumInjectionsForBeingState) {
slot->deleteActiveState();
printf(" >> delete State\n");
}
}
}
//search for existing state
bool flagRelated = false;
if (vSlots.empty() == false) {
int ix = vSlots.front()->getIndexOfRelatedState(0, thresholdToAverage);
while (ix > -2) {
if (ix >= 0) {
//TODO: maybe another state fits a bit better.. approach -> euklidean distance?
flagRelated = true;
for (vector<SlaveAgentSlotOfAgent*>::iterator slot = vSlots.begin() + 1; slot < vSlots.end(); slot++) {
if ((*slot)->valueIsRelated(ix, thresholdToAverage) == false) {
flagRelated = false;
}
}
if (flagRelated == true) {
for (auto &slot : vSlots) {
slot->setActiveState(ix);
}
break;
}
ix = vSlots.front()->getIndexOfRelatedState(ix+1, thresholdToAverage);
}
}
}
if (flagRelated == false) {
printf(" >> No related state found\n");
printf("\n\n >>> inject in active state\n");
for (auto &slot : vSlots) {
slot->injectValueInActiveState();
}
}
}
printf("ende\n");
return false;
}
*/
diff --git a/Version_Max_07_05_2018_CMake/src/StateHandler.h b/Version_Max_07_05_2018_CMake/src/StateHandler.h
index 51c5f84..6d07826 100755
--- a/Version_Max_07_05_2018_CMake/src/StateHandler.h
+++ b/Version_Max_07_05_2018_CMake/src/StateHandler.h
@@ -1,194 +1,195 @@
#ifndef STATEHANDLER_HEADERFILE
#define STATEHANDLER_HEADERFILE
#include "Module.h"
#include "SlaveAgentSlotOfAgent.h"
#include "State.h"
#include "StateVariable.h"
#include <vector>
//XXX - only for now
#include "CSV_Writer.h"
#include "LinearFunctionBlock.h"
using namespace std;
class StateHandler : public Module {
public:
LinearFunctionBlock* StabSamples;
LinearFunctionBlock* StabDeviation;
LinearFunctionBlock* UnstabDeviation;
LinearFunctionBlock* SameState;
LinearFunctionBlock* DriftDeviation;
LinearFunctionBlock* BrokenCounterSamples;
LinearFunctionBlock* ValidState;
//NEU:
//compare
LinearFunctionBlock* FuncBlockConfSim2StateDev;
LinearFunctionBlock* FuncBlockConfDif2StateDev;
LinearFunctionBlock* FuncBlockConfSim2StateTime;
LinearFunctionBlock* FuncBlockConfDif2StateTime;
//insert
LinearFunctionBlock* FuncBlockConfValStateDev;
LinearFunctionBlock* FuncBlockConfInvStateDev;
LinearFunctionBlock* FuncBlockConfValStateTime;
LinearFunctionBlock* FuncBlockConfInvStateTime;
LinearFunctionBlock* FuncBlockConfBrokenSamples;
private:
//DATE18
//XXX - >0,5?
//discreate Average Partition Size adjustable?
float confidenceStableInput;
float confidenceStableOutput;
float confidenceStable;
float confStableAdjustableThreshold;
float confidenceUnstableInput;
float confidenceUnstableOutput;
float confidenceUnstable;
float confidenceUnstableAdjustableThreshold;
float confidenceSameStateInput;
float confSameStateInputAdjustableThreshold;
float confidenceSameStateOutput;
float confSameStateOutputAdjustableThreshold;
float confidenceValidState;
float confValidStateAdjustableThreshold;
unsigned int brokenCounter;
float confidenceBroken;
float confidenceBrokenAdjustableThreshold;
unsigned int driftCounter;
float confidenceDrift;
float confidenceDriftAdjustableThreshold;
//XXX - Maybe Object "StateVariable" between StateHandler and Slot?!
vector<SlaveAgentSlotOfAgent*> vInputVariables;
vector<SlaveAgentSlotOfAgent*> vOutputVariables;
vector<State*> vStates;
State* activeState;
unsigned int minNumToBeValidState;
bool flagVariablesWereStable;
unsigned int slidingWindowBufferSize;
unsigned int minNumOfRelatedValuesToBeStable;
float thresholdToBeStable;
float thresholdToBeRelated;
unsigned int discreteAveragePartitionSize;
unsigned int compareDistanceDiscreteAveragePartition;
float thresholdNotDrift;
unsigned int maxStateHistoryLength;
void initStateHandler();
bool addVariable(vector<SlaveAgentSlotOfAgent*>* vVariables, SlaveAgentSlotOfAgent* slot);
bool variablesAreStable(vector<SlaveAgentSlotOfAgent*>* vVariables);
//DATE18
float getConfVariableIsStable(SlaveAgentSlotOfAgent* variable);
float getConfVariablesAreStable(vector<SlaveAgentSlotOfAgent*>* vVariables);
float getConfVariableIsUnstable(SlaveAgentSlotOfAgent* variable);
float getConfVariablesAreUnstable(vector<SlaveAgentSlotOfAgent*>* vVariables);
//bool getConfAndUnconfVariableIsMatching(SlaveAgentSlotOfAgent* variable, LinearFunctionBlock* confDeviation, LinearFunctionBlock* confTime, float* conf, float* unconf);
bool getConfAndUnconfVariableIsMatching(State* state, LinearFunctionBlock* confDeviation, LinearFunctionBlock* confTime, float* conf, float* unconf);
bool getConfAndUnconfVariablesAreMatching(vector<SlaveAgentSlotOfAgent*>* vVariables, LinearFunctionBlock* confDeviation, LinearFunctionBlock* confTime, float* conf, float* unconf);
State* makeNewState();
string create_Output_File_Name(string cfg_Parameter);
bool addActiveStateToStateVector();
//bool addStateAndMakeItActive();
bool makeNewActiveState();
State* findRelatedState();
bool findRelatedStateAndMakeItActive();
void eraseStatesWithLessInjections();
bool delete_all_OuputVariables();
bool delete_all_InputVariables();
bool delete_allStates();
//XXX - only for now:
- CSV_Writer* csv_writer = NULL;
+ CSV_Writer *csv_writer;
+
public:
StateHandler();
StateHandler(char* name);
bool setDiscreteAveragePartitionSize(unsigned int discreteAverage);
unsigned int getDiscreteAveragePartitionSize();
bool addInputVariable(SlaveAgentSlotOfAgent* slot);
bool addOutputVariable(SlaveAgentSlotOfAgent* slot);
bool setSlidingWindowBufferSize(unsigned int slidingWindowBufferSize);
bool setMinNumOfRelatedValuesToBeStable(unsigned int minNumOfRelatedValuesToBeStable);
bool setThresholdToBeStable(float thresholdToBeStable);
bool setThresholdToBeRelated(float thresholdToBeRelated);
void trigger(unsigned int cycle);
//XXX - only for now
void closeCsvFile();
void set_CSV_Writer_parameter(string cfg_parameter);
void reset_States();
void reset_States_and_Slave_Agents();
~StateHandler();
/*
private:
vector<SlaveAgentSlotOfAgent*> vSlots;
unsigned int minNumOfChangedForValidStateChange;
unsigned int minimumInjectionsForBeingState;
void initStateHandler();
public:
StateHandler();
StateHandler(char* name);
bool setMinimumInjectionsForBeingState(unsigned int minimumInjectionsForBeingState);
unsigned int getMinimumInjectionsForBeingState();
//TODO: function for deleting slot and function with the whole vector as parameter
bool add_slot(SlaveAgentSlotOfAgent* slot);
void set_minNumOfChangedForValidStateChange(unsigned int minNumOfChangedForValidStateChange);
unsigned int get_minNumOfChangedForValidStateChange();
bool trigger();
*/
};
#endif
diff --git a/Version_Max_07_05_2018_CMake/src/attach_modules.cpp b/Version_Max_07_05_2018_CMake/src/attach_modules.cpp
index 67198ba..fd915b9 100755
--- a/Version_Max_07_05_2018_CMake/src/attach_modules.cpp
+++ b/Version_Max_07_05_2018_CMake/src/attach_modules.cpp
@@ -1,60 +1,60 @@
#include "attach_modules.h"
#include "rlutil.h"
-//#define PRINT
+#define PRINT
using namespace rlutil;
bool attach_historyModuleToSensorSlotInAgent(Agent* agent, Sensor* sensor, Channel* inputPort, HistoryModule* historyModule) {
if(agent != NULL && inputPort != NULL && historyModule != NULL) {
SensorSlotOfAgent* sensorSlotOfAgent = agent->get_sensorHandlerOfAgent()->get_sensorSlotAddress(inputPort);
if(sensorSlotOfAgent != NULL) {
#ifdef PRINT
printf(" > HistoryModule ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", historyModule->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", historyModule->get_id());
#endif // PRINT
if(sensorSlotOfAgent->set_historyModule(historyModule)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("attached ");
setColor(TXTCOLOR_GREY);
printf("to Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) in Agent ", sensor->get_id());
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", agent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("Couldn't attach the HistoryModule!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't attach the HistoryModule because Sensor isn't mounted in %s (id: %03u)!\n", agent->get_name(), agent->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't attach the HistoryModule because Agent, Channel, or HistoryModule is not valid!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
}
\ No newline at end of file
diff --git a/Version_Max_07_05_2018_CMake/src/attach_modulesToTestbench.cpp b/Version_Max_07_05_2018_CMake/src/attach_modulesToTestbench.cpp
index 25405c9..91c1c8a 100755
--- a/Version_Max_07_05_2018_CMake/src/attach_modulesToTestbench.cpp
+++ b/Version_Max_07_05_2018_CMake/src/attach_modulesToTestbench.cpp
@@ -1,62 +1,62 @@
#include "attach_modulesToTestbench.h"
#include "rlutil.h"
#include "SensorSlotOfTestbench.h"
-//#define PRINT
+#define PRINT
using namespace rlutil;
bool attach_csvReaderModuleToSensorSlotInAgent(Testbench* testbench, Sensor* sensor, CSVreaderModule* csvReaderModule) {
if(testbench != NULL && sensor != NULL && csvReaderModule != NULL) {
SensorSlotOfTestbench* sensorSlot = testbench->get_sensorSlotAddressOfTestbench(sensor);
if(sensorSlot != NULL) {
#ifdef PRINT
printf(" > CSV-Reader ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", csvReaderModule->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", csvReaderModule->get_id());
#endif // PRINT
if(sensorSlot->set_csvReaderModule(csvReaderModule)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("attached ");
setColor(TXTCOLOR_GREY);
printf("to Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) in Testbench ", sensor->get_id());
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", testbench->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", testbench->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("Couldn't attach the CSVreaderModule!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't attach the CSVreaderModule because Sensor isn't registered in %s (id: %03u)!\n", testbench->get_name(), testbench->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't attach the CSVreaderModule because Testbench, Sensorm or CSVreaderModule is not valid!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
}
\ No newline at end of file
diff --git a/Version_Max_07_05_2018_CMake/src/create_unit.cpp b/Version_Max_07_05_2018_CMake/src/create_unit.cpp
index 508a9a6..be16f5f 100755
--- a/Version_Max_07_05_2018_CMake/src/create_unit.cpp
+++ b/Version_Max_07_05_2018_CMake/src/create_unit.cpp
@@ -1,414 +1,416 @@
#include "create_unit.h"
#include <stdio.h>
#include "errno.h"
#include "rlutil.h"
using namespace rlutil;
+#define PRINT
+
void print_agent(Agent agent) {
}
Agent* create_agent() {
return create_agent(NO_NAME);
}
Agent* create_agent(char* name) {
Agent* agent = new Agent(name);
#ifdef PRINT
printf(" > Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", agent->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
return agent;
}
Sensor* create_sensor() {
return create_sensor(NO_NAME);
}
Sensor* create_sensor(char* name) {
Sensor* sensor = new Sensor(name);
#ifdef PRINT
printf(" > Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
return sensor;
}
HistoryModule create_historyModule(unsigned int history_length, int delimitation_mode) {
return create_historyModule(NO_NAME, history_length, delimitation_mode);
}
HistoryModule create_historyModule(char* name, unsigned int history_length, int delimitation_mode) {
HistoryModule historyModule(name);
#ifdef PRINT
printf(" > History ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", historyModule.get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", historyModule.get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
if(historyModule.set_maxHistoryLength(history_length)) {
#ifdef PRINT
printf(" > History length ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %u\n", history_length);
#endif // PRINT
}
else {
setColor(TXTCOLOR_LIGHTRED);
printf(" > historyLength could not set (out of allowed range).");
setColor(TXTCOLOR_GREY);
}
if(historyModule.set_delimitationMode(delimitation_mode)) {
#ifdef PRINT
printf(" > Delimitation Mode ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %u\n", delimitation_mode);
#endif // PRINT
}
else {
setColor(TXTCOLOR_LIGHTRED);
printf(" > Delimitation Mode could not set (out of allowed range).");
setColor(TXTCOLOR_GREY);
}
return historyModule;
}
Channel* create_channel(unsigned int transfer_rate) {
return create_channel(NO_NAME, transfer_rate);
}
Channel* create_channel(char* name, unsigned int transfer_rate) {
Channel* channel = new Channel(name);
#ifdef PRINT
printf(" > Channel ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", channel->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", channel->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
if(channel->set_transferRate(transfer_rate)) {
if(transfer_rate != 0) {
#ifdef PRINT
printf(" > transfer rate ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %i\n", transfer_rate);
#endif // PRINT
}
else {
#ifdef PRINT
printf(" > transfer ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to immediately transportation\n");
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Transfer Rate out of allowed bounds!\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return channel;
}
Testbench* create_testbench() {
return create_testbench(NO_NAME);
}
Testbench* create_testbench(char* name) {
Testbench* testbench = new Testbench(name);
#ifdef PRINT
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", testbench->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", testbench->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
#endif // PRINT
testbench->init_testbench();
return testbench;
}
/*
Lookuptable create_lookuptable() {
Lookuptable lut;
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", lut.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", lut.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
return lut;
}
Lookuptable create_lookuptable(char* name) {
Lookuptable lut(name);
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", lut.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", lut.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
return lut;
}
void print_confidence_validator(Confidence_Validator conf_valid) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", conf_valid.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", conf_valid.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
printf(" - range of validity ");
if(conf_valid.get_flag_lower_bound_exist())
printf("[ %.3f, ", conf_valid.get_lower_bound());
else
printf("] -inf, ");
if(conf_valid.get_flag_upper_bound_exist())
printf("%.3f ] ", conf_valid.get_upper_bound());
else
printf("+inf [ ");
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
if(conf_valid.get_flag_rates_of_change_exist()) {
printf(" - validity for rates of change of ");
printf("%.3f ", conf_valid.get_rates_of_change());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
}
}
Confidence_Validator create_confidence_validator(float lower_bound, bool flag_lower_bound_exist, float upper_bound, bool flag_upper_bound_exist, float rates_of_change, bool flag_rates_of_change_exist) {
Confidence_Validator conf_valid(lower_bound, flag_lower_bound_exist, upper_bound, flag_upper_bound_exist, rates_of_change, flag_rates_of_change_exist);
print_confidence_validator(conf_valid);
return conf_valid;
}
Confidence_Validator create_confidence_validator(char* name, float lower_bound, bool flag_lower_bound_exist, float upper_bound, bool flag_upper_bound_exist, float rates_of_change, bool flag_rates_of_change_exist) {
Confidence_Validator conf_valid(name, lower_bound, flag_lower_bound_exist, upper_bound, flag_upper_bound_exist, rates_of_change, flag_rates_of_change_exist);
print_confidence_validator(conf_valid);
return conf_valid;
}
void print_abstraction_module(Abstraction abstraction) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", abstraction.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", abstraction.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
//TODO: abstraction method printen
printf(" - abstraction method %u ", abstraction.get_abstraction_method());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
//TODO: auch das hier bissl sch�ner machen
if(abstraction.get_flag_lookuptable_exist(0)) {
printf(" - position 0 connected mit Look up Table ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", abstraction.get_lookuptable(0)->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", abstraction.get_lookuptable(0)->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
}
}
Abstraction create_abstraction_module(Lookuptable* lut, unsigned int abstraction_method) {
Abstraction abstraction(lut, abstraction_method);
print_abstraction_module(abstraction);
return abstraction;
}
Abstraction create_abstraction_module(char* name, Lookuptable* lut, unsigned int abstraction_method) {
Abstraction abstraction(name, lut, abstraction_method);
print_abstraction_module(abstraction);
return abstraction;
}
void print_bunch_module(Bunch_Module bunch_module) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", bunch_module.get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", bunch_module.get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
//TODO: abstraction method printen
printf(" - abstraction method %u ", bunch_module.get_bunch_method());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
rlutil::setColor(TXTCOLOR_GREY);
}
Bunch_Module create_bunch_module(unsigned int bunch_method) {
Bunch_Module bunch_module(bunch_method);
print_bunch_module(bunch_module);
return bunch_module;
}
Bunch_Module create_bunch_module(char* name, unsigned int bunch_method) {
Bunch_Module bunch_module(name, bunch_method);
print_bunch_module(bunch_module);
return bunch_module;
}
*/
FILE* make_file_pointer(const char* filepath, int mode) {
FILE* fpointer = nullptr;
if(mode == CSV_MODE_READ) {
// file_opened = fopen_s(&fpointer, filepath, "r"); //only windows compatible
fpointer = fopen(filepath, "r");
}
else if(mode == CSV_MODE_WRITE) {
// file_opened = fopen_s(&fpointer, filepath, "w"); //only windows compatible
fpointer = fopen(filepath, "w");
}
else {
#ifdef PRINT
printf("File pointer mode for \"%s\" ", filepath);
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("is not supported!\n");
rlutil::setColor(TXTCOLOR_GREY);
#endif // PRINT
return NULL;
}
//if(file_opened == 0) {
if(fpointer != nullptr) {
return fpointer;
}
#ifdef PRINT
printf("File pointer \"%s\" ", filepath);
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("could not created!\n");
rlutil::setColor(TXTCOLOR_GREY);
#endif // PRINT
return NULL;
}
void print_csv_reader(CSVreaderModule* csvReaderModule,const char* filepath) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", csvReaderModule->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) for \"%s\" ", csvReaderModule->get_id(), filepath);
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("created\n");
rlutil::setColor(TXTCOLOR_GREY);
}
CSVreaderModule* create_CSVreaderModule(const char* filepath, unsigned int column, unsigned int start_row) {
FILE* fpointer = make_file_pointer(filepath, CSV_MODE_READ);
if(fpointer) {
CSVreaderModule* csvr = new CSVreaderModule(fpointer, column, start_row);
print_csv_reader(csvr, filepath);
return csvr;
}
else {
CSVreaderModule* csvr = new CSVreaderModule();
return csvr;
}
}
CSVreaderModule* create_CSVreaderModule(char* name,const char* filepath, unsigned int column, unsigned int start_row) {
FILE* fpointer = make_file_pointer(filepath, CSV_MODE_READ);
if(fpointer) {
CSVreaderModule* csvr = new CSVreaderModule(name, fpointer, column, start_row);
#ifdef PRINT
print_csv_reader(csvr, filepath);
#endif // PRINT
return csvr;
}
else {
CSVreaderModule* csvr = new CSVreaderModule;
return csvr;
}
}
StateHandler create_stateHandler() {
return create_stateHandler(NO_NAME);
}
StateHandler create_stateHandler(char* name) {
StateHandler stateHandler(name);
return stateHandler;
}
diff --git a/Version_Max_07_05_2018_CMake/src/inAgentsRegistrations.cpp b/Version_Max_07_05_2018_CMake/src/inAgentsRegistrations.cpp
index 363e345..ccad09b 100755
--- a/Version_Max_07_05_2018_CMake/src/inAgentsRegistrations.cpp
+++ b/Version_Max_07_05_2018_CMake/src/inAgentsRegistrations.cpp
@@ -1,105 +1,105 @@
#include "inAgentsRegistrations.h"
#include "rlutil.h"
-//#define PRINT
+#define PRINT
using namespace rlutil;
bool registerSlaveAgentAsInputVariableInStateHandler(Agent* masteragent, Channel* channel) {
if(masteragent != NULL, channel != NULL) {
SlaveAgentSlotOfAgent* slot = masteragent->get_slaveAgentHandlerOfAgent()->get_slaveAgentSlotAddress(channel);
if(slot != NULL) {
if(masteragent->get_stateHandler()->addInputVariable(slot)){
#ifdef PRINT
printf(" > Channel ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", channel->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", channel->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("as ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("Input Variable ");
setColor(TXTCOLOR_GREY);
printf("in stateHandler of ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", masteragent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Channel %s (id: %03u) is not connected to Agent %s (id: %03u)\n", channel->get_name(), channel->get_id(), masteragent->get_name(), masteragent->get_id());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Channel %s (id: %03u) is not connected to Agent %s (id: %03u)\n", channel->get_name(), channel->get_id(), masteragent->get_name(), masteragent->get_id());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Agent or Channel is not valid\n");
#endif // PRINT
}
return false;
}
bool registerSlaveAgentAsOutputVariableInStateHandler(Agent* masteragent, Channel* channel) {
if (masteragent != NULL, channel != NULL) {
SlaveAgentSlotOfAgent* slot = masteragent->get_slaveAgentHandlerOfAgent()->get_slaveAgentSlotAddress(channel);
if (slot != NULL) {
if (masteragent->get_stateHandler()->addOutputVariable(slot)) {
#ifdef PRINT
printf(" > Channel ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", channel->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", channel->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("as ");
setColor(TXTCOLOR_LIGHTGREEN);
printf("Output Variable ");
setColor(TXTCOLOR_GREY);
printf("in stateHandler of ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", masteragent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Channel %s (id: %03u) is not connected to Agent %s (id: %03u)\n", channel->get_name(), channel->get_id(), masteragent->get_name(), masteragent->get_id());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Channel %s (id: %03u) is not connected to Agent %s (id: %03u)\n", channel->get_name(), channel->get_id(), masteragent->get_name(), masteragent->get_id());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Agent or Channel is not valid\n");
#endif // PRINT
}
return false;
}
\ No newline at end of file
diff --git a/Version_Max_07_05_2018_CMake/src/mount_nodes.cpp b/Version_Max_07_05_2018_CMake/src/mount_nodes.cpp
index 55b0622..81d1a17 100755
--- a/Version_Max_07_05_2018_CMake/src/mount_nodes.cpp
+++ b/Version_Max_07_05_2018_CMake/src/mount_nodes.cpp
@@ -1,408 +1,408 @@
#include "attach_modules.h"
#include "mount_nodes.h"
#include "rlutil.h"
#include <stdio.h>
-//#define PRINT
+#define PRINT
using namespace rlutil;
bool mount_sensorInAgent(Agent* agent, Sensor* sensor, Channel* channel) {
if(agent != NULL && sensor != NULL && channel != NULL) {
#ifdef PRINT
printf(" > Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
#endif // PRINT
if(agent->get_sensorHandlerOfAgent()->mount_sensorIntoSensorSlot(channel) && sensor->mount_agent(channel)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
setColor(TXTCOLOR_GREY);
printf("in Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", agent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u)\n", agent->get_name(), agent->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Agent, Sensor, or Channel is not valid\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
}
/*
void mount_sensor_in_agent(Agent* agent, Sensor* sensor, Channel* sensor_to_slave, unsigned int position) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
if(agent->mount_sensor(sensor_to_slave, position) && sensor->mount_agent(sensor_to_slave)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - on position %u\n", agent->get_id(), position);
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u) on position %u\n", agent->get_name(), agent->get_id(), position);
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
/*
void mount_sensor_in_agent(Agent* agent, Sensor* sensor, Channel* sensor_to_slave, Abstraction* abstraction) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
if(agent->mount_sensor(sensor_to_slave, abstraction) && sensor->mount_agent(sensor_to_slave)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", agent->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Abstraction Module ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", abstraction->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", abstraction->get_id());
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u) connected with Abstraction Module %s (id: %03u)\n", agent->get_name(), agent->get_id(), abstraction->get_name(), abstraction->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
/*
void mount_sensor_in_agent(Agent* agent, Sensor* sensor, Channel* sensor_to_slave, Confidence_Validator* confidence_validator) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
if(agent->mount_sensor(sensor_to_slave, confidence_validator) && sensor->mount_agent(sensor_to_slave)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", agent->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Range of Validity ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", confidence_validator->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", confidence_validator->get_id());
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u) connected with Look up Table %s (id: %03u)\n", agent->get_name(), agent->get_id(), confidence_validator->get_name(), confidence_validator->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
bool mount_sensorInAgent(Agent* agent, Sensor* sensor, Channel* channel, HistoryModule* historyModule) {
if(agent != NULL && sensor != NULL && channel != NULL && historyModule != NULL) {
if(mount_sensorInAgent(agent, sensor, channel)) {
return attach_historyModuleToSensorSlotInAgent(agent, sensor, channel, historyModule);
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("Agent, Sensor, Channel, or HistoryModule is not valid\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
}
/*
void mount_sensor_in_agent(Agent* agent, Sensor* sensor, Channel* sensor_to_slave, Confidence_Validator* confidence_validator, Abstraction* abstraction) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
if(agent->mount_sensor(sensor_to_slave, confidence_validator, abstraction) && sensor->mount_agent(sensor_to_slave)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", agent->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Range of Validity ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", confidence_validator->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", confidence_validator->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Abstraction Module ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", abstraction->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", abstraction->get_id());
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u) connected with Look up Table %s (id: %03u) and Abstraction Module %s (id: %03u)\n", agent->get_name(), agent->get_id(), confidence_validator->get_name(), confidence_validator->get_id(), abstraction->get_name(), abstraction->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
bool mount_agentInAgent(Agent *masteragent, Agent* slaveagent, Channel* channel) {
if(masteragent != NULL && slaveagent != NULL && channel != NULL) {
if(masteragent->get_slaveAgentHandlerOfAgent()->mount_slaveAgentIntoSlaveAgentSlot(channel)) {
if(slaveagent->get_masterAgentHandlerOfAgent()->mount_masterAgentIntoSlaveAgentSlot(channel)) {
#ifdef PRINT
printf(" > Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slaveagent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", slaveagent->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
setColor(TXTCOLOR_GREY);
printf("in Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", masteragent->get_id());
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Could not mount Master Agent %s (id: %03u) in Slave Agent %s (id: %03u)\n", masteragent->get_name(), masteragent->get_id(), slaveagent->get_name(), slaveagent->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
masteragent->get_slaveAgentHandlerOfAgent()->demount_slaveAgentIntoSlaveAgentSlot(channel);
}
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > One of the Agents or Channel not valid\n");
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
return false;
/*
if(masteragent->mount_slaveagent(slave_to_master, master_to_slave) && slaveagent->mount_masteragent(master_to_slave, slave_to_master)) {
setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
setColor(TXTCOLOR_GREY);
printf("in Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", masteragent->get_id());
if(master_to_slave != NULL && slave_to_master != NULL) {
printf(" > bidirectional communication ");
}
else {
printf(" > unidirectional communication ");
if(master_to_slave != NULL) {
printf("(Master to Slave: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", master_to_slave->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)) ", master_to_slave->get_id());
}
if(slave_to_master != NULL) {
printf("(Slave to Master: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slave_to_master->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)) ", slave_to_master->get_id());
}
}
setColor(TXTCOLOR_LIGHTGREEN);
printf("set\n");
setColor(TXTCOLOR_GREY);
}
else {
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in Agent %s (id: %03u)\n", masteragent->get_name(), masteragent->get_id());
setColor(TXTCOLOR_GREY);
}
*/
}
/*
void mount_slaveagent_in_agent(Agent *masteragent, Agent* slaveagent, Channel* master_to_slave, Channel* slave_to_master, unsigned int position) {
printf(" > Slave - ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slaveagent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", slaveagent->get_id());
if(masteragent->mount_slaveagent(slave_to_master, master_to_slave, position) && slaveagent->mount_masteragent(master_to_slave, slave_to_master)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in Master - ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - on position %u\n - ", masteragent->get_id(), position);
if(master_to_slave != NULL && slave_to_master != NULL)
printf("bidirectional communication\n");
else
printf("unidirectional communication\n");
if(master_to_slave != NULL) {
printf(" - Master to Slave: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", master_to_slave->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", master_to_slave->get_id());
}
if(slave_to_master != NULL) {
printf(" - Slave to Master: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slave_to_master->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", slave_to_master->get_id());
}
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in Master - %s (id: %03u) on position %u\n", masteragent->get_name(), masteragent->get_id(), position);
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
/*
void mount_slaveagent_in_agent(Agent *masteragent, Agent* slaveagent, Channel* master_to_slave, Channel* slave_to_master, Cross_Confidence_Validator* ccv) {
printf(" > Slave - ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slaveagent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", slaveagent->get_id());
if(masteragent->mount_slaveagent(slave_to_master, master_to_slave, ccv) && slaveagent->mount_masteragent(master_to_slave, slave_to_master)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in Master - ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", masteragent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", masteragent->get_id());
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("connected ");
rlutil::setColor(TXTCOLOR_GREY);
printf("with Cross Confidence Validator ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", ccv->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n - ", ccv->get_id());
if(master_to_slave != NULL && slave_to_master != NULL)
printf("bidirectional communication\n");
else
printf("unidirectional communication\n");
if(master_to_slave != NULL) {
printf(" - Master to Slave: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", master_to_slave->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", master_to_slave->get_id());
}
if(slave_to_master != NULL) {
printf(" - Slave to Master: ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", slave_to_master->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", slave_to_master->get_id());
}
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in Master - %s (id: %03u) with Cross Confidence Validator %s (id: %03u)\n", masteragent->get_name(), masteragent->get_id(), ccv->get_name(), ccv->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
/*
void mount_bunchmodule_in_agent(Agent *agent, Bunch_Module* bunch_module) {
printf(" > ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", bunch_module->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", bunch_module->get_id());
if(agent->mount_bunch_module(bunch_module)) {
rlutil::setColor(TXTCOLOR_LIGHTGREEN);
printf("mounted ");
rlutil::setColor(TXTCOLOR_GREY);
printf("in ");
rlutil::setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
rlutil::setColor(TXTCOLOR_GREY);
printf("(id: %03u)\n", agent->get_id());
}
else {
rlutil::setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be mounted in %s (id: %03u)\n", agent->get_name(), agent->get_id());
rlutil::setColor(TXTCOLOR_GREY);
}
}
*/
diff --git a/Version_Max_07_05_2018_CMake/src/register_in_testbench.cpp b/Version_Max_07_05_2018_CMake/src/register_in_testbench.cpp
index bae3c19..79ec1a4 100755
--- a/Version_Max_07_05_2018_CMake/src/register_in_testbench.cpp
+++ b/Version_Max_07_05_2018_CMake/src/register_in_testbench.cpp
@@ -1,130 +1,130 @@
#include "register_in_testbench.h"
#include "attach_modulesToTestbench.h"
#include "rlutil.h"
#include <stdio.h>
-//#define PRINT
+#define PRINT
using namespace rlutil;
bool register_agentInTestbench(Testbench *tb, Agent *agent) {
if(tb != NULL && agent != NULL) {
#ifdef PRINT
printf(" > Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", agent->get_id());
#endif // PRINT
if(tb->register_agent(agent)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("in Testbench ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s\n", tb->get_name());
setColor(TXTCOLOR_GREY);
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be registered in %s", tb->get_name());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Testbench or Agent is not valid\n");
#endif // PRINT
}
setColor(TXTCOLOR_GREY);
return false;
}
bool register_sensorInTestbench(Testbench *tb, Sensor *sensor) {
if(tb != NULL && sensor != NULL) {
#ifdef PRINT
printf(" > Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
#endif // PRINT
if(tb->register_sensor(sensor)) {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("in ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s\n", tb->get_name());
setColor(TXTCOLOR_GREY);
#endif // PRINT
return true;
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be registered in %s\n", tb->get_name());
#endif // PRINT
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Testbench or sensor is not valid\n");
#endif // PRINT
}
setColor(TXTCOLOR_GREY);
return false;
}
bool register_sensorInTestbench(Testbench *tb, Sensor *sensor, CSVreaderModule *csvReaderModule) {
if(tb != NULL && sensor != NULL && csvReaderModule != NULL) {
if(register_sensorInTestbench(tb, sensor)) {
return attach_csvReaderModuleToSensorSlotInAgent(tb, sensor, csvReaderModule);
}
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("Testbench or sensor is not valid\n");
#endif // PRINT
}
setColor(TXTCOLOR_GREY);
return false;
}
bool register_channelInTestbench(Testbench *tb, Channel *channel) {
#ifdef PRINT
printf(" > Channel ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", channel->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", channel->get_id());
#endif // PRINT
if(tb->register_channel(channel)){
#ifdef PRINT
setColor(TXTCOLOR_LIGHTGREEN);
printf("registered ");
setColor(TXTCOLOR_GREY);
printf("in Testbench ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s\n", tb->get_name());
#endif // PRINT
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf("couldn't be registered in %s\n", tb->get_name());
#endif // PRINT
}
setColor(TXTCOLOR_GREY);
return false;
}
diff --git a/Version_Max_07_05_2018_CMake/src/setupNode.cpp b/Version_Max_07_05_2018_CMake/src/setupNode.cpp
index 9ba5baa..4d906f3 100755
--- a/Version_Max_07_05_2018_CMake/src/setupNode.cpp
+++ b/Version_Max_07_05_2018_CMake/src/setupNode.cpp
@@ -1,54 +1,54 @@
#include "setupNode.h"
#include "rlutil.h"
-//#define PRINT
+#define PRINT
using namespace rlutil;
void setWorkingCycleOfSensor(Sensor* sensor, unsigned int workingCycle) {
if (sensor->set_workingCycle(workingCycle)) {
#ifdef PRINT
printf(" > WorkingCycle of Sensor ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", sensor->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", sensor->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %u\n", workingCycle);
#endif // PRINT
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't set WorkingCycle of Sensor %s (id: %03u)\n", sensor->get_name(), sensor->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
void setWorkingCycleOfAgent(Agent* agent, unsigned int workingCycle) {
if (agent->set_workingCycle(workingCycle)) {
#ifdef PRINT
printf(" > WorkingCycle of Agent ");
setColor(TXTCOLOR_LIGHTCYAN);
printf("%s ", agent->get_name());
setColor(TXTCOLOR_GREY);
printf("(id: %03u) ", agent->get_id());
setColor(TXTCOLOR_LIGHTGREEN);
printf("set ");
setColor(TXTCOLOR_GREY);
printf("to %u\n", workingCycle);
#endif // PRINT
}
else {
#ifdef PRINT
setColor(TXTCOLOR_LIGHTRED);
printf(" > Couldn't set WorkingCycle of Sensor %s (id: %03u)\n", agent->get_name(), agent->get_id());
setColor(TXTCOLOR_GREY);
#endif // PRINT
}
}
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Sun, Apr 27, 1:00 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
134503
Default Alt Text
(128 KB)

Event Timeline