diff --git a/Version_Max_07_05_2018_CMake/src/CSVreaderModule.cpp b/Version_Max_07_05_2018_CMake/src/CSVreaderModule.cpp index 6705ac2..f652c26 100755 --- a/Version_Max_07_05_2018_CMake/src/CSVreaderModule.cpp +++ b/Version_Max_07_05_2018_CMake/src/CSVreaderModule.cpp @@ -1,217 +1,235 @@ #include "CSVreaderModule.h" +#include "file_util.h" #include #include #include #define STRINGLENGTH 5000 /* void CSV_Reader :: initialize_csvreader(char* filepath_read, unsigned int num_of_datasets, unsigned int* list_of_datasets, unsigned int start_row) { //fpointer_read = fopen(filepath_read, "r"); fopen_s(&fpointer_read, filepath_read, "r"); this->num_of_datasets = num_of_datasets; //TODO: sort.. falls es nicht in aufsteigender folge kommt for(unsigned int d_ix=0; d_ixlist_of_datasets[d_ix] = list_of_datasets[d_ix]; } row = 1; this->start_row = start_row; } */ void CSVreaderModule :: initialize_csvreader(FILE* fpointer, unsigned int column, unsigned int start_row) { //fpointer_read = fopen(filepath_read, "r"); //TODO: file ponter schon aus CSV-Reader Creator Funktion �bergeben.. dann kann man n�mlich ausgeben, wenn da was nicht erstellt werden kann //bool file_opened = fopen_s(&fpointer_read, filepath_read, "r"); //TODO: etwas mit flag this->fpointer = fpointer; this->row = 1; this->column = column; this->start_row = start_row; flag_csv_reader_configured = true; } /* CSV_Reader :: CSV_Reader(char* filepath_read, unsigned int num_of_data_sets, unsigned int* list_of_datasets, unsigned int start_row) { set_name(NO_NAME); initialize_csvreader(filepath_read, num_of_data_sets, list_of_datasets, start_row); } CSV_Reader :: CSV_Reader(char* name, char* filepath_read, unsigned int num_of_data_sets, unsigned int* list_of_datasets, unsigned int start_row) { set_name(name); initialize_csvreader(filepath_read, num_of_data_sets, list_of_datasets, start_row); } */ CSVreaderModule :: CSVreaderModule() { set_name(NO_NAME); flag_csv_reader_configured = false; } CSVreaderModule :: CSVreaderModule(char* name) { set_name(name); flag_csv_reader_configured = false; } CSVreaderModule :: CSVreaderModule(FILE* fpointer, unsigned int column, unsigned int start_row) { set_name(NO_NAME); if(fpointer) { initialize_csvreader(fpointer, column, start_row); } else { flag_csv_reader_configured = false; } } CSVreaderModule :: CSVreaderModule(char* name, FILE* fpointer, unsigned int column, unsigned int start_row) { set_name(name); if(fpointer) { initialize_csvreader(fpointer, column, start_row); } else { flag_csv_reader_configured = false; } } /* CSV_Reader :: CSV_Reader(char* name, char* filepath_read, int column, int start_row) { } */ //XXX: Wird nicht mehr benutzt //TODO: �berarbeiten nach folgendem Beispiel https://msdn.microsoft.com/en-us/library/ftsafwz3.aspx bool CSVreaderModule :: read_one_row() { if(fpointer) { char readrow[STRINGLENGTH] = "", electedfield[STRINGLENGTH] = ""; //TODO: move following for-loop to "initialize_csvreader(...) for(;rowrow = row; } void CSVreaderModule:: set_position_fpointer_to_start() { long int cur_pos; if(this->fpointer) { cur_pos = ftell(this->fpointer); rewind(this->fpointer); } } //TODO: flag_csv_reader_configured abfragen void CSVreaderModule :: close_file() { fclose(fpointer); } CSVreaderModule :: ~CSVreaderModule(){ if(fpointer) { close_file(); } } diff --git a/Version_Max_07_05_2018_CMake/src/Channel.cpp b/Version_Max_07_05_2018_CMake/src/Channel.cpp index 2da808a..fec8a73 100755 --- a/Version_Max_07_05_2018_CMake/src/Channel.cpp +++ b/Version_Max_07_05_2018_CMake/src/Channel.cpp @@ -1,346 +1,350 @@ #include "Channel.h" #include #define MAX_BUFFER_LENGTH 100 void Channel :: init_channel() { maxBufferLength = MAX_BUFFER_LENGTH; transferRate = MAX_BUFFER_LENGTH; } Channel :: Channel() { init_channel(); } Channel :: Channel(char* name) { set_name(name); init_channel(); } bool Channel :: set_maxBufferLength(unsigned int maxBufferLength) { if(maxBufferLength <= MAX_BUFFER_LENGTH) { this->maxBufferLength = maxBufferLength; return true; } return false; } unsigned int Channel :: get_maxBufferLength() { return maxBufferLength; } unsigned int Channel :: get_avlInputBufferUp() { return maxBufferLength-lInputMsgBufferUp.size(); } unsigned int Channel :: get_avlOutputBufferUp() { return maxBufferLength-lOutputMsgBufferUp.size(); } unsigned int Channel :: get_avlInputBufferDown() { return maxBufferLength-lInputMsgBufferDown.size(); } unsigned int Channel :: get_avlOutputBufferDown() { return maxBufferLength-lOutputMsgBufferDown.size(); } bool Channel :: set_transferRate(unsigned int transferRate) { if(transferRate <= MAX_BUFFER_LENGTH) { this->transferRate = transferRate; return true; } return false; } unsigned int Channel :: get_transferRate() { return transferRate; } bool Channel :: add_msgAtBegin (list* buffer, Message* message) { try { buffer->push_front(message); } catch(bad_alloc& error) { delete message; return false; } return true; } bool Channel :: del_msgAtBegin (list* buffer) { try { /* printf("a\n"); getchar(); delete buffer->back(); printf("b\n"); getchar(); */ Message* first_Message = buffer->front(); delete first_Message; buffer->pop_front(); /* printf("c\n"); getchar(); */ } catch(bad_alloc& error) { return false; } return true; } bool Channel :: add_msgAtEnd (list* buffer, Message* message) { try { buffer->push_back(message); } catch(bad_alloc& error) { cerr << "bad_alloc caught: " << error.what() << endl; delete message; return false; } return true; } bool del_msgAtEnd (list* buffer) { try { Message* last_Message = buffer->back(); delete last_Message; buffer->pop_back(); } catch(bad_alloc& error) { return false; } return true; } bool Channel :: send_MsgUp(Message* message) { if(message != NULL) { if(transferRate == 0) { //TODO: at the moment only one packet (in the front) gets deleted if buffer is full. However, the whole message (instruction+value) should be deleted in case of a full buffer if(lOutputMsgBufferUp.size() == maxBufferLength) { del_msgAtBegin(&lOutputMsgBufferUp); } return add_msgAtEnd(&lOutputMsgBufferUp, message); } else { if(lInputMsgBufferUp.size() == maxBufferLength) { //TODO: at the moment only one packet (in the front) gets deleted if buffer is full. However, the whole message (instruction+value) should be deleted in case of a full buffer del_msgAtBegin(&lInputMsgBufferUp); } return add_msgAtEnd(&lInputMsgBufferUp, message); } } } bool Channel :: send_MsgUp(float msg) { Message* message = new Message(msg); return send_MsgUp(message); } bool Channel :: send_MsgUp(int msg) { Message* message = new Message(msg); return send_MsgUp(message); } bool Channel :: get_MsgUp(float* msg) { if(isThereFloatMsgUp()) { float tempMsg; if(lOutputMsgBufferUp.front()->getMsg(&tempMsg)) { *msg = tempMsg; del_msgAtBegin(&lOutputMsgBufferUp); return true; } } return false; } bool Channel :: get_MsgUp(int* msg) { if(isThereIntMsgUp()) { int tempMsg; if(lOutputMsgBufferUp.front()->getMsg(&tempMsg)) { *msg = tempMsg; del_msgAtBegin(&lOutputMsgBufferUp); return true; } } return false; } bool Channel :: isThereFloatMsgUp() { if(lOutputMsgBufferUp.size() > 0 ) { if(lOutputMsgBufferUp.front() != NULL) { return lOutputMsgBufferUp.front()->isMsgFloat(); } } return false; } bool Channel :: isThereIntMsgUp() { if(lOutputMsgBufferUp.size() > 0 ) { if(lOutputMsgBufferUp.front() != NULL) { return lOutputMsgBufferUp.front()->isMsgInt(); } } return false; } bool Channel :: send_MsgDown(Message* message) { if(message != NULL) { if(transferRate == 0) { if(lOutputMsgBufferDown.size() == maxBufferLength) { del_msgAtBegin(&lOutputMsgBufferDown); } return add_msgAtEnd(&lOutputMsgBufferDown, message); } else { if(lInputMsgBufferDown.size() == maxBufferLength) { del_msgAtBegin(&lInputMsgBufferDown); } return add_msgAtEnd(&lInputMsgBufferDown, message); } } } bool Channel :: send_MsgDown(float msg) { Message* message = new Message(msg); return send_MsgDown(message); } bool Channel :: send_MsgDown(int msg) { Message* message = new Message(msg); return send_MsgDown(message); } bool Channel :: get_MsgDown(float* msg) { if(isThereFloatMsgDown()) { float tempMsg; if(lOutputMsgBufferDown.front()->getMsg(&tempMsg)) { *msg = tempMsg; del_msgAtBegin(&lOutputMsgBufferDown); return true; } } return false; } bool Channel :: get_MsgDown(int* msg) { if(isThereIntMsgDown()) { int tempMsg; if(lOutputMsgBufferDown.front()->getMsg(&tempMsg)) { *msg = tempMsg; del_msgAtBegin(&lOutputMsgBufferDown); return true; } } return false; } bool Channel :: isThereFloatMsgDown() { if(lOutputMsgBufferDown.size() > 0 ) { if(lOutputMsgBufferDown.front() != NULL) { return lOutputMsgBufferDown.front()->isMsgFloat(); } } return false; } bool Channel :: isThereIntMsgDown() { if(lOutputMsgBufferDown.size() > 0 ) { if(lOutputMsgBufferDown.front() != NULL) { return lOutputMsgBufferDown.front()->isMsgInt(); } } return false; } bool Channel :: transferMsgs(list* dest_buffer, list* src_buffer) { unsigned int NumOfMsgsToMove; if(transferRate <= src_buffer->size()) { NumOfMsgsToMove = transferRate; } else { NumOfMsgsToMove = src_buffer->size(); } if(NumOfMsgsToMove <= maxBufferLength-dest_buffer->size()) { for(unsigned int i=0; ifront())) { if(!del_msgAtBegin(src_buffer)) { return false; } } else { return false; } } return true; } return false; } bool Channel :: trigger() { bool flag_worked = transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp) && transferMsgs(&lOutputMsgBufferUp, &lInputMsgBufferUp); //printf("Channel %s: in_up %u, out_up %u, in_dn %u, out_dn %u,\n", name, lInputMsgBufferUp.size(), lOutputMsgBufferUp.size(), lInputMsgBufferDown.size(), lOutputMsgBufferDown.size()); return flag_worked; } bool Channel :: delete_all_InputMsgBufferUp() { Message* cur_Message; unsigned int cur_index_Message = 0; unsigned int size_li_Inp_MsgBufUp = lInputMsgBufferUp.size(); for(cur_index_Message = 0; cur_index_Message < size_li_Inp_MsgBufUp; cur_index_Message){ cur_Message = lInputMsgBufferUp.front(); delete cur_Message; lInputMsgBufferUp.pop_front(); } + return true; //added by Ali, it is an error in VS. } bool Channel :: delete_all_OuputMsgBufferUp() { Message* cur_Message; unsigned int cur_index_Message = 0; unsigned int size_li_Out_MsgBufUp = lOutputMsgBufferUp.size(); for(cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufUp; cur_index_Message){ cur_Message = lOutputMsgBufferUp.front(); delete cur_Message; lOutputMsgBufferUp.pop_front(); } + return true; //added by Ali, it is an error in VS. } bool Channel :: delete_all_InputMsgBufferDown() { Message* cur_Message; unsigned int cur_index_Message = 0; unsigned int size_li_Out_MsgBufDown = lInputMsgBufferDown.size(); for(cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufDown; cur_index_Message){ cur_Message = lInputMsgBufferDown.front(); delete cur_Message; lInputMsgBufferDown.pop_front(); } + return true; //added by Ali, it is an error in VS. } bool Channel :: delete_all_OutputMsgBufferDown() { Message* cur_Message; unsigned int cur_index_Message = 0; unsigned int size_li_Out_MsgBufDown = lOutputMsgBufferDown.size(); for(cur_index_Message = 0; cur_index_Message < size_li_Out_MsgBufDown; cur_index_Message){ cur_Message = lOutputMsgBufferDown.front(); delete cur_Message; lOutputMsgBufferDown.pop_front(); } + return true; //added by Ali, it is an error in VS. } Channel :: ~Channel() { delete_all_InputMsgBufferUp(); delete_all_OuputMsgBufferUp(); delete_all_InputMsgBufferDown(); delete_all_OutputMsgBufferDown(); } diff --git a/Version_Max_07_05_2018_CMake/src/State.cpp b/Version_Max_07_05_2018_CMake/src/State.cpp index aac8c32..044cbf9 100755 --- a/Version_Max_07_05_2018_CMake/src/State.cpp +++ b/Version_Max_07_05_2018_CMake/src/State.cpp @@ -1,476 +1,478 @@ #include "State.h" #include "printError.h" #include "relationChecker.h" #include "minmaxzeug.h" #define INJECTIONPARTITIONING 10 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* 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; } printf(" >>> Inject Values (partCounter: %u)\n", discreteAveragePartitionCounter); //getchar(); } return flagWorkedForAll; } bool State::injectValuesAndMakeNewDiscreteAveragePartition(unsigned int discreteAveragePartitionSize) { discreteAveragePartitionCounter = 0; return injectValues(discreteAveragePartitionSize); } bool State::variablesAreRelated(vector* 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* 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* 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))); printf("confDrift = %f, deviationValueReferenceValue = %f\n", confidenceDrift, deviationValueReferenceValue(subState->getDiscreteAverageOfLastBlock(discreteAveragePartitionSize), subState->getDiscreteAverageOfFirstBlock(discreteAveragePartitionSize))); 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* vSubStates, LinearFunctionBlock* SameState) { float confRelatedMin = 1; for (auto &subState : *vSubStates) { float confRelated = subState->valueIsRelatedFuzzy(SameState); printf("conf %f\n", confRelated); 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()); } printf("confValidState %f\nconfInvalidState %f\n", confValidState, confInvalidState); //getchar(); if (confValidState > confInvalidState) { printf("VALID STATE\n"); 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()) { printf("historyLength: %u\n", vInputSubStates.front()->getSampleHistoryLength()); 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* 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* 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 3787862..0aa3c46 100755 --- a/Version_Max_07_05_2018_CMake/src/StateHandler.cpp +++ b/Version_Max_07_05_2018_CMake/src/StateHandler.cpp @@ -1,1785 +1,1788 @@ #include "StateHandler.h" #include #include "printError.h" #include "rlutil.h" #include "relationChecker.h" #include "minmaxzeug.h" #include "file_util.h" #include #include //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 //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() { 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/"; 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: 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* 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* 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 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 lHistoryTemporary = variable->getHistory(); vector 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* 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 lHistoryTemporary = variable->getHistory(); vector 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* 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 lHistoryTemporary = variable->getHistory(); vector 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* 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() { printf(" >> Save Active State\n"); 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::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) { printf("cycle: %u\n", cycle); bool flagGotValues = true; printf("Input Sample Values:\n"); for (auto &slot : vInputVariables) { float sampleValue; if (!(slot->get_slaveAgentValue(&sampleValue))) flagGotValues = false; //program never executes this line of code printf("In, %s: %f\n", slot->get_comPort()->get_name(), sampleValue); if (cycle == 1) csv_writer->write_field(slot->get_comPort()->get_name()); else csv_writer->write_field(sampleValue); csv_writer->make_new_field(); } printf("Output Sample Values:\n"); for (auto &slot : vOutputVariables) { float sampleValue; if (!(slot->get_slaveAgentValue(&sampleValue))) flagGotValues = false; //program never executes this line of code printf("Out, %s: %f\n", slot->get_comPort()->get_name(), sampleValue); 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; printf(" > new active state\n"); 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; printf(" > same state\n"); 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) { 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(fuzzyAND(confidenceDrift, activeState->getConfStateValid()), fuzzyAND(confInputVarAreSim2ActiveState, confOutputVarAreSim2ActiveState)); 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(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) { setColor(TXTCOLOR_LIGHTRED); printf("BROKEN\n"); setColor(TXTCOLOR_GREY); #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(); } } printf("STATES: %u\n", vStates.size()); } } 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::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/Testbench.cpp b/Version_Max_07_05_2018_CMake/src/Testbench.cpp index dc79a27..90a7c3e 100755 --- a/Version_Max_07_05_2018_CMake/src/Testbench.cpp +++ b/Version_Max_07_05_2018_CMake/src/Testbench.cpp @@ -1,1024 +1,1026 @@ #include "Testbench.h" #include "printError.h" #include using namespace std; void Testbench :: init_testbench() { //TODO //some init source code to add, if necessary } Testbench :: Testbench() { set_name(NO_NAME); } Testbench :: Testbench(char* name) { set_name(name); } bool Testbench :: register_agent(Agent* agent) { AgentSlotOfTestbench* agentSlot = new AgentSlotOfTestbench(); if(agentSlot != NULL) { if(agentSlot->set_agent(agent)) { try { if(vector_registeredAgents.size() < MAXNUM_OF_REGISTERED_AGENTS) { vector_registeredAgents.push_back(agentSlot); } else { printError("Max number of registered agents is already reached!"); return false; } } catch(bad_alloc& error) { printError("bad_alloc caught: ", error.what()); return false; } return true; } else { printError("Agent is not set!"); vector_registeredAgents.pop_back(); //TODO: check if it is right?!?! return false; } } else { printError("Couldn't create AgentSlot!"); return false; } } bool Testbench :: register_sensor(Sensor* sensor) { SensorSlotOfTestbench* sensorSlot = new SensorSlotOfTestbench(); if(sensorSlot != NULL) { if(sensorSlot->set_sensor(sensor)) { try { if(vector_registeredSensors.size() < MAXNUM_OF_REGISTERED_SENSORS) { vector_registeredSensors.push_back(sensorSlot); } else { printError("Max number of registered sensors is already reached!"); return false; } } catch(bad_alloc& error) { printError("bad_alloc caught: ", error.what()); return false; } return true; } else { printError("Input port is no set!"); vector_registeredSensors.pop_back(); //TODO: check if it is right?!?! return false; } } else { printError("Couldn't create SensorSlot!"); return false; } } SensorSlotOfTestbench* Testbench :: get_sensorSlotAddressOfTestbench(Sensor* sensor) { for(auto &sensorSlot : vector_registeredSensors) { if(sensorSlot->get_sensor() == sensor) { return sensorSlot; } } return NULL; } bool Testbench :: register_channel(Channel* channel) { ChannelSlotOfTestbench* channelSlot = new ChannelSlotOfTestbench(); if(channelSlot != NULL) { if(channelSlot->set_channel(channel)) { try { if(vector_registeredChannels.size() < MAXNUM_OF_REGISTERED_CHANNELS) { vector_registeredChannels.push_back(channelSlot); } else { printError("Max number of registered channels is already reached!"); return false; } } catch(bad_alloc& error) { printError("bad_alloc caught: ", error.what()); return false; } return true; } else { printError("Channel is not set!"); vector_registeredChannels.pop_back(); //TODO: check if it is right?!?! return false; } } else { printError("Couldn't create ChannelSlot!"); return false; } } bool Testbench :: register_testbench_config(Testbench_Config* tb_config) { vector_registered_Configs.push_back(tb_config); + return true; //added by Ali, it is an error in VS. } vector& Testbench :: get_all_registered_testbench_configs() { return vector_registered_Configs; } void Testbench :: simulate(unsigned int rounds) { for(unsigned int cycle = 1; cycle <=rounds; cycle++) { if (cycle == 312) { printf("DEBUG: Break point"); } //printf("cycle %u\n", sec); //update sensor values for(auto &sensorSlot : vector_registeredSensors) { Sensor *sensor = sensorSlot->get_sensor(); printf("Name of Sensor %s \n", sensor->get_name()); if(sensor != NULL) { CSVreaderModule *csvReader = sensorSlot->get_csvReaderModule(); if(csvReader != NULL) { float inputValue; if(csvReader->get_next_value(&inputValue)) { sensor->set_sensorValue(inputValue); } } } } //trigger sensors for(auto &sensorSlot : vector_registeredSensors) { Sensor *sensor = sensorSlot->get_sensor(); if(sensor != NULL) { sensor->trigger(); } } //trigger channels for(auto &channelSlot : vector_registeredChannels) { Channel *channel = channelSlot->get_channel(); if(channel != NULL) { channel->trigger(); } } //trigger agents for(auto &agentSlot : vector_registeredAgents) { Agent *agent = agentSlot->get_agent(); if(agent != NULL) { agent->trigger(cycle); } } //if(sec % 500 == 0) //getchar(); } //XXX - only for now for (auto &agentSlot : vector_registeredAgents) { Agent *agent = agentSlot->get_agent(); if (agent != NULL) { StateHandler *stateHandler = agent->get_stateHandler2(); if (stateHandler != NULL) { stateHandler->closeCsvFile(); } } } } vector& Testbench :: get_all_registeredAgents() { return vector_registeredAgents; } void Testbench :: set_current_tb_config_index(const int index) { Testbench_Config::set_active_Config(index); } void Testbench :: remove_all_Testbench_Configs() { unsigned int index_tb_conf = 0; unsigned int size_vec_tb_conf = vector_registered_Configs.size(); for(index_tb_conf = 0; index_tb_conf < size_vec_tb_conf; index_tb_conf++) { Testbench_Config* cur_config = vector_registered_Configs[index_tb_conf]; delete cur_config; } vector_registered_Configs.clear(); } void Testbench :: remove_all_Agents() { AgentSlotOfTestbench* cur_AgentSlot; unsigned int index_ag; unsigned int size_vec_reg_ag = vector_registeredAgents.size(); for(index_ag = 0; index_ag < size_vec_reg_ag; index_ag++) { cur_AgentSlot = vector_registeredAgents[index_ag]; delete cur_AgentSlot; } vector_registeredAgents.clear(); } void Testbench :: remove_all_Channels() { unsigned int index_ch; unsigned int size_vec_reg_chan = vector_registeredChannels.size(); for(index_ch = 0; index_ch < size_vec_reg_chan; index_ch++) { ChannelSlotOfTestbench* cur_ChaSlot = vector_registeredChannels[index_ch]; delete cur_ChaSlot; } vector_registeredChannels.clear(); } void Testbench :: remove_all_Sensors() { unsigned int index_sen; unsigned int size_vec_reg_sens = vector_registeredSensors.size(); for(index_sen = 0; index_sen < size_vec_reg_sens; index_sen++) { SensorSlotOfTestbench* cur_SenSlot = vector_registeredSensors[index_sen]; delete cur_SenSlot; } vector_registeredSensors.clear(); } bool Testbench :: free_resources() { AgentSlotOfTestbench* cur_Ag_Sl_Tb; unsigned int index_reg_Agents; unsigned int size_vec_reg_Agents = vector_registeredAgents.size(); for(index_reg_Agents = 0; index_reg_Agents < size_vec_reg_Agents; index_reg_Agents++) { cur_Ag_Sl_Tb = vector_registeredAgents[index_reg_Agents]; Agent* cur_Ag = cur_Ag_Sl_Tb->get_agent(); //cur_Ag->del_stateHandler(); } + return true; //added by Ali, it is an error in VS. } void Testbench::set_CSV_Writer_parameter() { unsigned int size_of_vec_reg_Agents = vector_registeredAgents.size(); AgentSlotOfTestbench* viability_slot_Agent = vector_registeredAgents[size_of_vec_reg_Agents - 1]; Agent* viability_Agent = viability_slot_Agent->get_agent(); StateHandler* cur_state_Handl = viability_Agent->get_stateHandler(); Testbench_Config* cur_tb_cfg; string tb_cfg; cur_tb_cfg = get_current_Testbench_config(); if(cur_tb_cfg != NULL) { tb_cfg = cur_tb_cfg->get_Config_as_String(); cur_state_Handl->set_CSV_Writer_parameter(tb_cfg); } } Testbench_Config* Testbench :: get_current_Testbench_config() { unsigned int index_cur_tb_cfg = 0; unsigned int size_tb_cfg = vector_registered_Configs.size(); Testbench_Config* cur_tb_cfg; for(index_cur_tb_cfg = 0; index_cur_tb_cfg < size_tb_cfg; index_cur_tb_cfg++){ cur_tb_cfg = vector_registered_Configs[index_cur_tb_cfg]; if(cur_tb_cfg->get_own_index() == Testbench_Config::get_active_Config()){ return cur_tb_cfg; } } return NULL; } void Testbench :: set_config_values_in_linear_functions() { unsigned int index_reg_Agents = 0; unsigned int size_of_vec_reg_Agents; vector vec_reg_Agents = this->get_all_registeredAgents(); size_of_vec_reg_Agents = vec_reg_Agents.size(); AgentSlotOfTestbench* viability_slot_Agent = vec_reg_Agents[vec_reg_Agents.size()-1]; Agent* viability_Agent = viability_slot_Agent->get_agent(); StateHandler* cur_state_Handl = viability_Agent->get_stateHandler(); set_parameters_FuncBlockConfSim2StateDev(cur_state_Handl->FuncBlockConfSim2StateDev); set_parameters_FuncBlockConfDif2StateDev(cur_state_Handl->FuncBlockConfDif2StateDev); set_parameters_FuncBlockConfSim2StateTime(cur_state_Handl->FuncBlockConfSim2StateTime); set_parameters_FuncBlockConfDif2StateTime(cur_state_Handl->FuncBlockConfDif2StateTime); set_parameters_FuncBlockConfValStateDev(cur_state_Handl->FuncBlockConfValStateDev); set_parameters_FuncBlockConfInvStateDev(cur_state_Handl->FuncBlockConfInvStateDev); set_parameters_FuncBlockConfValStateTime(cur_state_Handl->FuncBlockConfValStateTime); set_parameters_FuncBlockConfInvStateTime(cur_state_Handl->FuncBlockConfInvStateTime); set_parameters_DriftDeviation(cur_state_Handl->DriftDeviation); set_parameters_FuncBlockConfBrokenSamples(cur_state_Handl->FuncBlockConfBrokenSamples); } void Testbench :: set_parameters_FuncBlockConfSim2StateDev(LinearFunctionBlock* FuncBlockConfSim2StateDev) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfSim2StateDev->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_1) { cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_sim_dif); cur_Lin_Fun->setKandD((float)0, (float)0); }else if (cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_2) { cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_sim_dif, true, (float)-cur_values.inner_bound_sim_dif); cur_Lin_Fun->setKandD((float)-cur_values.outter_bound_sim_dif, (float)0, (float)-cur_values.inner_bound_sim_dif, (float)1); }else if (cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_3) { cur_Lin_Fun->setDomain(true, (float)-cur_values.inner_bound_sim_dif, true, (float)cur_values.inner_bound_sim_dif); cur_Lin_Fun->setKandD((float)0, (float)1); }else if(cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_4){ cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_sim_dif, true, (float)cur_values.outter_bound_sim_dif); cur_Lin_Fun->setKandD((float)cur_values.inner_bound_sim_dif, (float)1, (float)cur_values.outter_bound_sim_dif, (float)0); }else if(cur_Lin_Fun->getName() == CONF_SIM2_STATE_DEV_5){ cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_sim_dif, false); cur_Lin_Fun->setKandD((float)0, (float)0); } } } void Testbench :: set_parameters_FuncBlockConfDif2StateDev(LinearFunctionBlock* FuncBlockConfDif2StateDev) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfDif2StateDev->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_1) { cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_sim_dif); cur_Lin_Fun->setKandD((float)0, (float)1); }else if (cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_2) { cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_sim_dif, true, (float)-cur_values.inner_bound_sim_dif); cur_Lin_Fun->setKandD((float)-cur_values.outter_bound_sim_dif, (float)1, (float)-cur_values.inner_bound_sim_dif, (float)0); }else if (cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_3) { cur_Lin_Fun->setDomain(true, (float)-cur_values.inner_bound_sim_dif, true, (float)cur_values.inner_bound_sim_dif); cur_Lin_Fun->setKandD((float)0, (float)0); }else if(cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_4){ cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_sim_dif, true, (float)cur_values.outter_bound_sim_dif); cur_Lin_Fun->setKandD((float)cur_values.inner_bound_sim_dif, (float)0, (float)cur_values.outter_bound_sim_dif, (float)1); }else if(cur_Lin_Fun->getName() == CONF_DIF2_STATE_DEV_5){ cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_sim_dif, false); cur_Lin_Fun->setKandD((float)0, (float)1); } } } void Testbench :: set_parameters_FuncBlockConfSim2StateTime(LinearFunctionBlock* FuncBlockConfSim2StateTime) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfSim2StateTime->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == CONF_SIM2_STATE_TIME_1) { cur_Lin_Fun->setDomain(false, true, (float)0); cur_Lin_Fun->setKandD((float)0, (float)0); }else if (cur_Lin_Fun->getName() == CONF_SIM2_STATE_TIME_2) { cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.length); cur_Lin_Fun->setKandD((float)0, (float)0, (float)cur_values.length, (float)1); }else if (cur_Lin_Fun->getName() == CONF_SIM2_STATE_TIME_3) { cur_Lin_Fun->setDomain(true, (float)cur_values.length, false); cur_Lin_Fun->setKandD((float)0, (float)1); } } } void Testbench :: set_parameters_FuncBlockConfDif2StateTime(LinearFunctionBlock* FuncBlockConfDif2StateTime) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfDif2StateTime->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == CONF_DIF2_STATE_TIME_1) { cur_Lin_Fun->setDomain(false, true, (float)0); cur_Lin_Fun->setKandD((float)0, (float)1); }else if (cur_Lin_Fun->getName() == CONF_DIF2_STATE_TIME_2) { cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.length); cur_Lin_Fun->setKandD((float)0, (float)1, (float)cur_values.length, (float)0); }else if (cur_Lin_Fun->getName() == CONF_DIF2_STATE_TIME_3) { cur_Lin_Fun->setDomain(true, (float)cur_values.length, false); cur_Lin_Fun->setKandD((float)0, (float)0); } } } void Testbench :: set_parameters_FuncBlockConfValStateDev(LinearFunctionBlock* FuncBlockConfValStateDev) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfValStateDev->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_1) { cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_sim_dif); cur_Lin_Fun->setKandD((float)0, (float)0); }else if (cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_2) { cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_sim_dif, true, (float)-cur_values.inner_bound_sim_dif); cur_Lin_Fun->setKandD((float)-cur_values.outter_bound_sim_dif, (float)0, (float)-cur_values.inner_bound_sim_dif, (float)1); }else if (cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_3) { cur_Lin_Fun->setDomain(true, (float)-cur_values.inner_bound_sim_dif, true, (float)cur_values.inner_bound_sim_dif); cur_Lin_Fun->setKandD((float)0, (float)1); }else if(cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_4){ cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_sim_dif, true, (float)cur_values.outter_bound_sim_dif); cur_Lin_Fun->setKandD((float)cur_values.inner_bound_sim_dif, (float)1, (float)cur_values.outter_bound_sim_dif, (float)0); }else if(cur_Lin_Fun->getName() == CONF_VALID_STATE_DEV_5){ cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_sim_dif, false); cur_Lin_Fun->setKandD((float)0, (float)0); } } } void Testbench :: set_parameters_FuncBlockConfInvStateDev(LinearFunctionBlock* FuncBlockConfInvStateDev) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfInvStateDev->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_1) { cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_sim_dif); cur_Lin_Fun->setKandD((float)0, (float)1); }else if (cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_2) { cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_sim_dif, true, (float)-cur_values.inner_bound_sim_dif); cur_Lin_Fun->setKandD((float)-cur_values.outter_bound_sim_dif, (float)1, (float)-cur_values.inner_bound_sim_dif, (float)0); }else if (cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_3) { cur_Lin_Fun->setDomain(true, (float)-cur_values.inner_bound_sim_dif, true, (float)cur_values.inner_bound_sim_dif); cur_Lin_Fun->setKandD((float)0, (float)0); }else if(cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_4){ cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_sim_dif, true, (float)cur_values.outter_bound_sim_dif); cur_Lin_Fun->setKandD((float)cur_values.inner_bound_sim_dif, (float)0, (float)cur_values.outter_bound_sim_dif, (float)1); }else if(cur_Lin_Fun->getName() == CONF_INVALID_STATE_DEV_5){ cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_sim_dif, false); cur_Lin_Fun->setKandD((float)0, (float)1); } } } void Testbench :: set_parameters_FuncBlockConfValStateTime(LinearFunctionBlock* FuncBlockConfValStateTime) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfValStateTime->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == VALID_STATE_TIME_1) { cur_Lin_Fun->setDomain(false, true, (float)0); cur_Lin_Fun->setKandD((float)0, (float)0); }else if (cur_Lin_Fun->getName() == VALID_STATE_TIME_2) { cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.length); cur_Lin_Fun->setKandD((float)0, (float)0, (float)cur_values.length, (float)1); }else if (cur_Lin_Fun->getName() == VALID_STATE_TIME_3) { cur_Lin_Fun->setDomain(true, (float)cur_values.length, false); cur_Lin_Fun->setKandD((float)0, (float)1); } } } void Testbench :: set_parameters_FuncBlockConfInvStateTime(LinearFunctionBlock* FuncBlockConfInvStateTime) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfInvStateTime->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == INVALID_STATE_TIME_1) { cur_Lin_Fun->setDomain(false, true, (float)0); cur_Lin_Fun->setKandD((float)0, (float)1); }else if (cur_Lin_Fun->getName() == INVALID_STATE_TIME_2) { cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.length); cur_Lin_Fun->setKandD((float)0, (float)1, (float)cur_values.length, (float)0); }else if (cur_Lin_Fun->getName() == INVALID_STATE_TIME_3) { cur_Lin_Fun->setDomain(true, (float)cur_values.length, false); cur_Lin_Fun->setKandD((float)0, (float)0); } } } void Testbench :: set_parameters_DriftDeviation(LinearFunctionBlock* DriftDeviation) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = DriftDeviation->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_1) { cur_Lin_Fun->setDomain(false, true, (float)-cur_values.outter_bound_drift); cur_Lin_Fun->setKandD((float)0, (float)1); }else if (cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_2) { cur_Lin_Fun->setDomain(true, (float)-cur_values.outter_bound_drift, true, (float)-cur_values.inner_bound_drift); cur_Lin_Fun->setKandD((float)-cur_values.inner_bound_drift, (float)1, (float)-cur_values.inner_bound_drift, (float)0); }else if (cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_3) { //this line causes a small deviation between the old solution with define and the new one //I didn't figure out how to get an totally equal result. cur_Lin_Fun->setDomain(true,(float) -cur_values.inner_bound_drift, true,(float) cur_values.inner_bound_drift); cur_Lin_Fun->setKandD((float)0, (float)0); }else if(cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_4){ cur_Lin_Fun->setDomain(true, (float)cur_values.inner_bound_drift, true, (float)cur_values.outter_bound_drift); cur_Lin_Fun->setKandD((float)cur_values.inner_bound_drift, (float)0, (float)cur_values.outter_bound_drift, (float)1); }else if(cur_Lin_Fun->getName() == CONFIDENCE_DRIFT_DEVIATION_5){ cur_Lin_Fun->setDomain(true, (float)cur_values.outter_bound_drift, false); cur_Lin_Fun->setKandD((float)0, (float)1); } } } void Testbench :: set_parameters_FuncBlockConfBrokenSamples(LinearFunctionBlock* FuncBlockConfBrokenSamples) { LinearFunction* cur_Lin_Fun; vector vec_Lin_Fun = FuncBlockConfBrokenSamples->get_all_LinearFunctions(); unsigned int size_vec_Lin_Fun = vec_Lin_Fun.size(); unsigned int index_cur_Lin_Fun = 0; Testbench_Config* cur_Tb_cfg = this->get_current_Testbench_config(); for(index_cur_Lin_Fun = 0; index_cur_Lin_Fun < size_vec_Lin_Fun; index_cur_Lin_Fun++) { One_Config_t cur_values = cur_Tb_cfg->get_Config(); cur_Lin_Fun = vec_Lin_Fun[index_cur_Lin_Fun]; if(cur_Lin_Fun->getName() == CONFIDENCE_BROKEN_1) { cur_Lin_Fun->setDomain(false, true, (float)0); cur_Lin_Fun->setKandD((float)0, (float)0); }else if (cur_Lin_Fun->getName() == CONFIDENCE_BROKEN_2) { cur_Lin_Fun->setDomain(true, (float)0, true, (float)cur_values.bound_broken); cur_Lin_Fun->setKandD((float)0, (float)0, (float)cur_values.bound_broken, (float)1); }else if (cur_Lin_Fun->getName() == CONFIDENCE_BROKEN_3) { cur_Lin_Fun->setDomain(true, (float)cur_values.bound_broken, false); cur_Lin_Fun->setKandD((float)0, (float)1); } } } void Testbench :: set_CSV_Reader_row(const int start_row) { unsigned int size_of_vec_reg_Sens = vector_registeredSensors.size(); SensorSlotOfTestbench* cur_sens_Slot; unsigned int index_cur_Slot = 0; CSVreaderModule* assigned_CSVReader; for(index_cur_Slot = 0; index_cur_Slot < size_of_vec_reg_Sens; index_cur_Slot++){ cur_sens_Slot = vector_registeredSensors[index_cur_Slot]; assigned_CSVReader = cur_sens_Slot->get_csvReaderModule(); assigned_CSVReader->reset_row(start_row); } } void Testbench :: set_CSV_Reader_to_beginning() { unsigned int size_of_vec_reg_Sens = vector_registeredSensors.size(); SensorSlotOfTestbench* cur_sens_Slot; unsigned int index_cur_Slot = 0; CSVreaderModule* assigned_CSVReader; unsigned const int START_ROW = 1; for(index_cur_Slot = 0; index_cur_Slot < size_of_vec_reg_Sens; index_cur_Slot++){ cur_sens_Slot = vector_registeredSensors[index_cur_Slot]; assigned_CSVReader = cur_sens_Slot->get_csvReaderModule(); assigned_CSVReader->set_position_fpointer_to_start(); } } void Testbench:: reset_States() { unsigned int size_of_vec_reg_Agents = vector_registeredAgents.size(); AgentSlotOfTestbench* viability_slot_Agent = vector_registeredAgents[size_of_vec_reg_Agents - 1]; Agent* viability_Agent = viability_slot_Agent->get_agent(); StateHandler* cur_state_Handl = viability_Agent->get_stateHandler(); cur_state_Handl->reset_States(); } void Testbench:: reset_States_and_Slave_Agents() { unsigned int size_of_vec_reg_Agents = vector_registeredAgents.size(); AgentSlotOfTestbench* viability_slot_Agent = vector_registeredAgents[size_of_vec_reg_Agents - 1]; Agent* viability_Agent = viability_slot_Agent->get_agent(); StateHandler* cur_state_Handl = viability_Agent->get_stateHandler(); cur_state_Handl->reset_States_and_Slave_Agents(); } Testbench :: ~Testbench() { remove_all_Testbench_Configs(); remove_all_Agents(); remove_all_Channels(); remove_all_Sensors(); } /* Testbench :: Testbench() { num_of_registered_agents = 0; num_of_registered_sensors = 0; num_of_registered_channels = 0; this->id = num_of_units; num_of_units++; this->set_name(NO_NAME); //csv flag_csv_reader_exist = false; flag_csv_writer_exist = false; } Testbench :: Testbench(char* name) { num_of_registered_agents = 0; num_of_registered_sensors = 0; num_of_registered_channels = 0; this->id = num_of_units; num_of_units++; this->set_name(name); //csv flag_csv_reader_exist = false; flag_csv_writer_exist = false; } void Testbench :: simulate() { if(flag_csv_writer_exist) { csv_writer->write_field("second"); csv_writer->make_new_field(); for(unsigned int s_ix=0; s_ixwrite_field(registered_sensors[s_ix]->get_name()); csv_writer->make_new_field(); } for(unsigned int a_ix=0; a_ixwrite_field(registered_agents[a_ix]->get_name()); csv_writer->make_new_field(); } csv_writer->write_field("confidence counter"); csv_writer->make_new_field(); csv_writer->make_new_line(); } //TODO: HIER ENDLOSSCHLEIFE ODER SO - Irgendwas, dass stoppt, wenn file zu ende for(unsigned int sec=1; sec<=29208; sec++) { printf("second %u\n", sec); if(flag_csv_writer_exist) { csv_writer->write_field((int)sec); csv_writer->make_new_field(); } //Update Sensor Values for(unsigned int s_ix = 0; s_ix < num_of_registered_sensors; s_ix++) { //TODO: make possibility of non-registered csv-reader if(flag_sensor_has_csvr[s_ix]) { float value_from_csv; if(registered_sensors_csvr[s_ix] != NULL) { if(registered_sensors_csvr[s_ix]->get_next_value(&value_from_csv)) { registered_sensors[s_ix]->update_sensor_value(value_from_csv); //printf("field of %s: %f", registered_sensors[s_ix]->get_name(), value_from_csv); } } } } for(unsigned int s_ix = 0; s_ix < num_of_registered_sensors; s_ix++) { registered_sensors[s_ix]->trigger(); if(flag_csv_writer_exist) { if(registered_sensors[s_ix]->get_flag_sensor_value_is_valid()) { csv_writer->write_field(registered_sensors[s_ix]->get_sensor_value()); } csv_writer->make_new_field(); } } for(unsigned int c_ix = 0; c_ix < num_of_registered_channels; c_ix++) { //printf("\n\n\nTRIGGER CHANNELS\n"); registered_channels[c_ix]->trigger(); } for(unsigned int a_ix = 0; a_ix < num_of_registered_agents; a_ix++) { registered_agents[a_ix]->trigger(); if(flag_csv_writer_exist) { if(registered_agents[a_ix]->get_flag_bunched_score_exist()) { csv_writer->write_field(registered_agents[a_ix]->get_bunched_score()); csv_writer->make_new_field(); csv_writer->write_field((int)registered_agents[a_ix]->get_bunch_score_confidency()); } else if(registered_agents[a_ix]->get_flag_abstracted_sensor_score_exist(0)) { csv_writer->write_field(registered_agents[a_ix]->get_abstracted_sensor_score(0)); } if(a_ix < num_of_registered_agents-1) { csv_writer->make_new_field(); } } } if(flag_csv_writer_exist) { csv_writer->make_new_line(); } getchar(); } if(flag_csv_writer_exist) { csv_writer->close_file(); } } //for agents: unsigned int Testbench :: get_num_of_registered_agents() { return num_of_registered_agents; } bool Testbench :: register_agent(Agent *agent) { if(num_of_registered_agents < MAX_NUM_OF_AGENTS) { registered_agents[num_of_registered_agents] = agent; num_of_registered_agents++; return true; } return false; } bool Testbench :: deregister_agent(Agent *agent) { unsigned int agent_ix; if(get_ix_of_agent(agent, &agent_ix)) { return deregister_agent(agent_ix); } return false; } bool Testbench :: deregister_agent(unsigned int agent_ix) { if(agent_ix < num_of_registered_agents) { for(unsigned int a_ix=agent_ix; a_ixcsv_reader = csv_reader; flag_csv_reader_exist = true; return true; } return false; } bool Testbench :: register_csv_writer(CSV_Writer* csv_writer) { if(csv_writer != NULL) { this->csv_writer = csv_writer; flag_csv_writer_exist = true; return true; } return false; } */ diff --git a/Version_Max_07_05_2018_CMake/src/Testbench_Config.cpp b/Version_Max_07_05_2018_CMake/src/Testbench_Config.cpp index 9cca90a..a48dee0 100755 --- a/Version_Max_07_05_2018_CMake/src/Testbench_Config.cpp +++ b/Version_Max_07_05_2018_CMake/src/Testbench_Config.cpp @@ -1,226 +1,227 @@ /* * Testbench_Config.cpp * * Created on: 26.06.2018 * Author: edwin */ #include "Testbench_Config.h" vector Testbench_Config::s_vec_all_created_Configs; int Testbench_Config::s_counter_of_all_created_configs = 0; int Testbench_Config::s_active_Config = 0; /* * */ void Testbench_Config::register_Config() { if(s_vec_all_created_Configs.max_size() > s_vec_all_created_Configs.size()){ s_vec_all_created_Configs.push_back(this); this->m_current_index = s_counter_of_all_created_configs; s_counter_of_all_created_configs = s_counter_of_all_created_configs + 1; } else { cout << "It is not possible to add an Testbench_Config to vector, Testbench_Config not registered" << endl; } } /* * */ void Testbench_Config::deregister_Config() { if (!s_vec_all_created_Configs.empty()) { int index = 0; int old_max_index = 0; std::vector::iterator it = s_vec_all_created_Configs.begin(); for (; index != this->m_current_index; it++) { index = index + 1; } old_max_index = s_vec_all_created_Configs.size() -1; if (index == this->m_current_index) { s_vec_all_created_Configs.erase(it); } if(index < old_max_index) { adapt_Indices(index); } this->m_current_index = s_object_is_deleted; s_counter_of_all_created_configs = s_counter_of_all_created_configs - 1; } } /* * */ void Testbench_Config::adapt_Indices(int from_index_to_change) { int index = 0; for(index = 0; index < s_vec_all_created_Configs.size(); index++){ if(index >= from_index_to_change) { Testbench_Config* cur_config = s_vec_all_created_Configs[index]; cur_config->m_current_index = cur_config->m_current_index - 1; } } } Testbench_Config::Testbench_Config() { this->configuration.bound_broken = float(2); this->configuration.outter_bound_sim_dif = 0.20; this->configuration.inner_bound_sim_dif = 0.01; this->configuration.outter_bound_drift = 3 * this->configuration.outter_bound_sim_dif; this->configuration.inner_bound_drift = this->configuration.outter_bound_sim_dif; this->configuration.length = (float) 10; register_Config(); } /* * */ Testbench_Config::Testbench_Config(One_Config_t& a_config) { this->configuration = a_config; register_Config(); } /* * return the index of the object in the static class vector */ int Testbench_Config::get_own_index() { return this->m_current_index; } /* * */ One_Config_t Testbench_Config::get_Config() { if(this != NULL && this->m_current_index != s_object_is_deleted){ return this->configuration; } + } /* * */ void Testbench_Config::print() { if(this != NULL && this->m_current_index != s_object_is_deleted) { std::cout << "Index of the configuration: " << this->m_current_index; std::cout << "The values of the configuration are: "; std::cout << "Broken boundary: " << this->configuration.bound_broken << " "; std::cout << "Inner boundary similar state: " << this->configuration.inner_bound_sim_dif << " "; std::cout << "Outter boundary similar state: " << this->configuration.outter_bound_sim_dif << " "; std::cout << "Inner boundary drift: " << this->configuration.inner_bound_drift << " "; std::cout << "Outter boundary drift: " << this->configuration.outter_bound_drift << " "; std::cout << "Length: " << this->configuration.length << " "; std::cout << std::endl; }else { std::cout << "Object points to NULL" << std::endl; } } /** * returns the index of the active config of the Testbench. */ int Testbench_Config::get_active_Config() { return s_active_Config; } /** * Sets the index for the current config used. * @param index value >= 0, -1 = Invalid Index * */ void Testbench_Config::set_active_Config(const int index) { if(index < s_counter_of_all_created_configs) { s_active_Config = index; }else { s_active_Config = s_INVALID_INDEX; } } void Testbench_Config::cut_number_of_decimal_digits(std::string & str_number) { const std::string delimeter = "."; const std::string zero = "0"; std::string str_temp; std::size_t first_pos; std::size_t length; std::size_t first_not_zero; std::size_t index; length = str_number.length(); first_pos = str_number.find_first_of(delimeter); if (first_pos != std::string::npos) { //0 is the start of the string, add 1 to get also the delimeter into the string str_temp =str_number.substr(0, first_pos + 1); length = length - first_pos - 1; str_number = str_number.substr(first_pos + 1, length); first_not_zero = str_number.find_first_not_of(zero); if(first_not_zero == std::string::npos) { str_number = str_temp + str_number[0] + str_number[1]; } else { for(index = 0; index <= first_not_zero; index++){ str_temp = str_temp + str_number[index]; } str_number = str_temp; } } } /** * returns all parameters of the config as a string. * B_b means bound broken border, I_B_d means inner bound drift border * O_B_d means outter bound drift border, I_B_s_d means inner bound simular signal border * O_B_s_d means outter bound simular signalr border */ std::string Testbench_Config::get_Config_as_String() { std::string config; std::string str_part; str_part = std::to_string(this->configuration.bound_broken); cut_number_of_decimal_digits(str_part); config = " B_b: " + str_part; str_part = std::to_string(this->configuration.inner_bound_drift); cut_number_of_decimal_digits(str_part); config = config + " I_B_d: "+ str_part; str_part = std::to_string(this->configuration.outter_bound_drift); cut_number_of_decimal_digits(str_part); config = config + " O_B_d: " + str_part; str_part = std::to_string(this->configuration.inner_bound_sim_dif); cut_number_of_decimal_digits(str_part); config = config + " I_B_s_d: " + str_part; str_part = std::to_string(this->configuration.outter_bound_sim_dif); cut_number_of_decimal_digits(str_part); config = config + " O_B_s_d: " + str_part + " "; config = config + " Length: " + std::to_string(this->configuration.length) + " "; return config; } /* * */ Testbench_Config::~Testbench_Config() { deregister_Config(); } diff --git a/Version_Max_07_05_2018_CMake/src/file_util.h b/Version_Max_07_05_2018_CMake/src/file_util.h index 8751598..accc255 100755 --- a/Version_Max_07_05_2018_CMake/src/file_util.h +++ b/Version_Max_07_05_2018_CMake/src/file_util.h @@ -1,77 +1,81 @@ /* * file_util.h * * Created on: 22.05.2018 * Author: edwin * * This file contains constant definitions for different file names, which are * used as input files. */ #ifndef FILE_UTIL_H_ #define FILE_UTIL_H_ #include #include //defines to swtich the file-configurations applied in file file_util.h //#define CASE_WR_NEUSTADT 1 -#define CASE_OMV 1 -//#define CASE_OPEL 1 +//#define CASE_OMV 1 + +#define CASE_OPEL 1 + +#define WINDOWS_OS 1 #ifdef CASE_WR_NEUSTADT //information related to the csv data files //definitions for measurements from Wr. Neustadt. const std::string PATH_TO_CSV_DATA_FILES = "./data_csv/Messungen_Wr_Neustadt"; const std::string PATH_TO_DATE_OF_MEASUREMENT = "/2018_05_23"; const std::string PATH_TO_AN_MEASURMENT = "/20180523_normal_SS_closed_SB_open/"; const std::string FILE_NAME_VOLTAGE = "Voltage.csv"; const std::string FILE_NAME_TEMP_1 = "Temp1.csv"; const std::string FILE_NAME_TEMP_2 = "Temp2.csv"; const std::string FILE_NAME_SHARKY_S = "SharkyS.csv"; const std::string FILE_NAME_SHARKY_B = "SharkyB.csv"; const std::string FILE_NAME_RIELS = "Riels.csv"; const std::string FILE_NAME_DYNA = "Dyna.csv"; #elif CASE_OMV //information related to the csv data files //definitions for measurements from Wr. Neustadt. const std::string PATH_TO_CSV_DATA_FILES = "../../messdaten/data_csv/OMV"; //settings for file B960428-Jun-2018 09-15-21.csv //const std::string PATH_TO_DATE_OF_MEASUREMENT = "/2017_12_18"; //const std::string PATH_TO_AN_MEASURMENT = "/"; //extendend data with 30 minutes more than in file "B960425-Jun-2018 09-45-01.csv" //const std::string FILE_NAME_OF_ENTIRE_DATA = "B960428-Jun-2018 09-15-21.csv"; //const std::string FILE_NAME_OF_ENTIRE_DATA = "B960425-Jun-2018 09-45-01.csv"; //settings for file 2017_01_07__05_46_fc6504.csv const std::string PATH_TO_DATE_OF_MEASUREMENT = "/2017_01_07"; const std::string PATH_TO_AN_MEASURMENT = "/"; const std::string FILE_NAME_OF_ENTIRE_DATA = "2017_01_07__05_46_fc6504.csv"; const std::string output_directory_name = "../../messdaten/output_data_csv/OMV/"; //definitions for motor measurements const std::string FOLDERNAME_NORMAL_OPERATION = "/Normal_operation-Tm0/"; #elif CASE_OPEL const std::string PATH_TO_CSV_DATA_FILES = "./data_csv/Opel"; const std::string PATH_TO_DATE_OF_MEASUREMENT = ""; //for Draft Messergeb OP90_decimalPoint.csv //const std::string PATH_TO_AN_MEASURMENT = "/"; //for "GA_daten_200_samples.csv" //const std::string PATH_TO_AN_MEASURMENT = "/Ga_daten/"; //for "Ga_all_Symmetrie_Combined_25000_to_30000.csv" const std::string PATH_TO_AN_MEASURMENT = "/Ga_daten_with_Symmetrie/"; //entire data set //const std::string FILE_NAME_OF_ENTIRE_DATA = "Draft Messergeb OP90_decimalPoint.csv"; //only 200 data points beginning of row 8450 and only Ga data for 200 values. //const std::string FILE_NAME_OF_ENTIRE_DATA = "GA_daten_200_samples.csv"; //for data combination o all ga data with the symmetrie column and from data point 25000 to 30000 const std::string FILE_NAME_OF_ENTIRE_DATA = "Ga_all_Symmetrie_Combined_25000_to_30000.csv"; +const std::string output_directory_name = "../../init me correctly/"; #endif #endif /* FILE_UTIL_H_ */ diff --git a/Version_Max_07_05_2018_CMake/src/main_Opel_GA_Data_Symmetrie.cpp b/Version_Max_07_05_2018_CMake/src/main_Opel_GA_Data_Symmetrie.cpp index 41998d5..14e3f29 100755 --- a/Version_Max_07_05_2018_CMake/src/main_Opel_GA_Data_Symmetrie.cpp +++ b/Version_Max_07_05_2018_CMake/src/main_Opel_GA_Data_Symmetrie.cpp @@ -1,1204 +1,1204 @@ /* * main.cpp * * Created on: 09.08.2018 * Author: edwin willegger, edwin.willegger@tuwien.ac.at * This file is used to generate output data from measurements * from Opel for SAVE project. * In this case the data of the entire time frame is analysed. * Based on the implementation of Maximilian Götzinger. * * WITH this main you can analyse data of all four GA and the Symmetrie column. */ - + #include "Agent.h" #include "Channel.h" #include "create_unit.h" #include "CSVreaderModule.h" #include "inAgentsRegistrations.h" #include "mount_nodes.h" #include "register_in_testbench.h" #include "Sensor.h" #include "setupNode.h" #include #include #include #include #include #include "Testbench.h" #include "file_util.h" #include "LinearFunction.h" #include "LinearFunctionBlock.h" #include "Testbench_Config.h" using namespace std; /* to switch between different file configurations change the * selected DEFINE in file_util.h * because the case of data analysis is selected in file_util.h * current available, Wr. Neustsadt, OMV, Opel * * One run for the entire Opel data set needs around 5 minutes. */ /********************************************************************************************************************** ************************************************begin of global definitions of variables and constants *************** **********************************************************************************************************************/ //every n-th SAMBLING value will be read in from the CSV-Data-Input-Files. #define SAMPLING 1 //global vectors for the different elements static vector vec_of_Agents; static vector vec_of_Sensors; static vector vec_of_Channels_for_Sensors; static vector vec_of_Channels_for_Agents; static vector vec_of_linear_Function_Blocks; static vector vec_of_test_benches; static vector vec_of_csv_readers; /* * it is not possible to have inputs and outputs, because all data are mesaruements at the end * of the conrod line. * Workaround: All parameters are as inputs and outputs used. */ //names of the measured data const string FIRST_MEASURED_DATA_NAME = "GA_open_laengs"; //Input and Output const string SECOND_MEASURED_DATA_NAME = "GA_oben_quer"; //Input and Output const string THIRD_MEASURED_DATA_NAME = "GA_unten_laengs"; //Input and Output const string FOURTH_MEASURED_DATA_NAME = "GA_unten_quer"; //Input and Output const string FIFTH_MEASURED_DATA_NAME = "Symmetrie"; //Input and Output //viability monitor const string VIABILITY_MONITOR = "ViabilityMonitor"; //index number of output, only used for data aquisition from OMV //better implementation a const list, with the index of all outputs //and another list for all input indices. //const int INDEX_OUTPUT = 3; //name for the channels of the sensors and agents const string APPENDIX_FOR_CHANNEL_SENSOR_NAME = "(SA)"; const string FIRST_MEASURED_CHANNEL_SENSOR_NAME = FIRST_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_SENSOR_NAME; const string SECOND_MEASURED_CHANNEL_SENSOR_NAME = SECOND_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_SENSOR_NAME; const string THIRD_MEASURED_CHANNEL_SENSOR_NAME = THIRD_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_SENSOR_NAME; const string FOURTH_MEASURED_CHANNEL_SENSOR_NAME = FOURTH_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_SENSOR_NAME; const string FIFTH_MEASURED_CHANNEL_SENSOR_NAME = FIFTH_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_SENSOR_NAME; const string APPENDIX_FOR_CHANNEL_AGENT_NAME = "(AA-UP)"; const string FIRST_MEASURED_CHANNEL_AGENT_NAME = FIRST_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_AGENT_NAME; const string SECOND_MEASURED_CHANNEL_AGENT_NAME = SECOND_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_AGENT_NAME; const string THIRD_MEASURED_CHANNEL_AGENT_NAME = THIRD_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_AGENT_NAME; const string FOURTH_MEASURED_CHANNEL_AGENT_NAME = FOURTH_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_AGENT_NAME; const string FIFTH_MEASURED_CHANNEL_AGENT_NAME = FIFTH_MEASURED_DATA_NAME + APPENDIX_FOR_CHANNEL_AGENT_NAME; #define TRANSFER_RATE_CHANNEL_SENSOR 0 #define TRANSFER_RATE_CHANNEL_AGENT MAX_BUFFER_LENGTH ////////////////////////////////////////////// /* //out of the outer_bound the function is 0 or 1 and within 1 or 0 depending on function or complementery. inner_bound_xxx = /----------=1----|------=1---------\ = inner_bound_xxxx outer_bound_xxx = / | \ / | \ 0=__________/ | \ = outer_bound_xxxx ______ = 0 -------------------------------------------------------------------------- */ //parameters of boundary for similar function #define OUTTER_BOUND_SIM_DIF 0.20 //outer bound e. g. 0.14 = 14 percent; testested with 0.20, 0.14, 0.06, #define INNER_BOUND_SIM_DIF 0.01 //inner bound e. g. 0.01 = 1 percent //same way as above but shows drift. #define OUTTER_BOUND_DRIFT OUTTER_BOUND_SIM_DIF * 3 #define INNER_BOUND_DRIFT OUTTER_BOUND_SIM_DIF //timer sagt, dass nach dem DOWNSAMPLING der Ausgang bis zu //n Werte später sich ändern darf, nachdem Sich der Eingang geändert hat. #define BOUND_BROKEN 2 //length where fuzzy function raises from 0 to 1 or 1 to 0 for the complementery. //history of the data depends of it, and should change, if it changes. #define LENGTH 10//2//10 //definitions for the testbench const string TEST_BENCH = "testbench"; //defintions for the csv-reader-modules //every agent have a own-csv-reader const string APPENDIX_CSV_MODULES = " CSV-Reader"; const string FIRST_MEASURED_DATA_CSV_NAME = FILE_NAME_OF_ENTIRE_DATA + APPENDIX_CSV_MODULES; const string SECOND_MEASURED_DATA_CSV_NAME = FILE_NAME_OF_ENTIRE_DATA + APPENDIX_CSV_MODULES; const string THIRD_MEASURED_DATA_CSV_NAME = FILE_NAME_OF_ENTIRE_DATA + APPENDIX_CSV_MODULES; const string FOURTH_MEASURED_DATA_CSV_NAME = FILE_NAME_OF_ENTIRE_DATA + APPENDIX_CSV_MODULES; const string FIFTH_MEASURED_DATA_CSV_NAME = FILE_NAME_OF_ENTIRE_DATA + APPENDIX_CSV_MODULES; /********************************************************************************************************************** ************************************************end of global definitions of variables and constants ***************** **********************************************************************************************************************/ /********************************************************************************************************************** ************************************************begin of function prototypes ***************************************** **********************************************************************************************************************/ void create_and_register_all_Testbench_Configs(Testbench* current_tb); void create_and_register_All_Agents(); void set_working_cycle_of_All_Agents(); void create_and_register_All_Sensors(); void set_working_cycle_of_All_Sensors(); void create_and_register_channels(); void create_and_register_channels_for_sensors(); void create_and_register_channels_for_agents(); void mount_sensors_in_agents(); void mount_agents_in_agents(); void register_data_agents_in_agent_state_Handler(); void create_linear_function_blocks(); void create_same_state_deviation_function_block(); void create_another_state_deviation_function_block(); void create_state_time_function_block(); void create_another_state_time_function_block(); void create_valid_state_deviation_function_block(); void create_invalid_state_deviation_function_block(); void create_valid_state_time_function_block(); void create_invalid_state_time_function_block(); void create_confidence_state_drift_function_block(); void create_confidence_broken_function_block(); void mount_function_blocks_to_viability_monitor(); void create_all_testbenches(); void create_csvr_modules(); void register_agents_in_testbenches(); void register_sensors_in_testbenches(); void register_channels_in_testbenches(); void register_channels_of_sensors_in_testbenches(); void register_channels_of_actors_in_testbenches(); void set_config_values_in_linear_functions(Testbench* current_tb); void set_parameters_LinearFunctionBlock(LinearFunctionBlock* cur_lin_func_block); void set_parameters_LinearFunction(vector vec_Lin_Func); void set_CSV_Writer_parameter(Testbench* current_tb); void run_simulation_of_all_testbenches(); void close_file_pointers(); void empty_static_vectors(); void empty_vec_Agent(); void empty_vec_Channel_Agent(); void empty_vec_Channel_Sensor(); void empty_vec_Sensors(); void empty_vec_csv_raders(); void empty_vec_linear_func_Blocks(); void empty_vec_TestBench(); /********************************************************************************************************************** ************************************************end of function prototypes ******************************************* **********************************************************************************************************************/ int main() { cout << "This program processes test data from Opel conrod production." << endl; create_and_register_All_Agents(); set_working_cycle_of_All_Agents(); create_and_register_All_Sensors(); set_working_cycle_of_All_Sensors(); create_and_register_channels(); mount_sensors_in_agents(); mount_agents_in_agents(); register_data_agents_in_agent_state_Handler(); create_linear_function_blocks(); mount_function_blocks_to_viability_monitor(); create_all_testbenches(); create_csvr_modules(); register_agents_in_testbenches(); register_sensors_in_testbenches(); register_channels_in_testbenches(); run_simulation_of_all_testbenches(); //close_file_pointers(); //TODO memory free of all objects. empty_static_vectors(); cout << "Program finished successfully" << endl; return 0; } void create_and_register_all_Testbench_Configs(Testbench* current_tb) { One_Config_t configuration; //setting of parameters, which will the same for all configurations configuration.bound_broken = 2; configuration.length = 10;//10; //the individual settings are set before a new Testbench_Config is created. configuration.inner_bound_sim_dif = 1 * 0.906241; configuration.outter_bound_sim_dif = 2 * configuration.inner_bound_sim_dif; configuration.outter_bound_drift = float(3) * configuration.outter_bound_sim_dif; configuration.inner_bound_drift = configuration.outter_bound_sim_dif; Testbench_Config* cfg = new Testbench_Config(configuration); /*configuration.inner_bound_sim_dif = 0.0005; configuration.outter_bound_sim_dif = 0.002; configuration.outter_bound_drift = float(3) * configuration.outter_bound_sim_dif; configuration.inner_bound_drift = configuration.outter_bound_sim_dif; Testbench_Config* cfg2 = new Testbench_Config(configuration); configuration.inner_bound_sim_dif = 0.002; configuration.outter_bound_sim_dif = 0.01; configuration.outter_bound_drift = float(3) * configuration.outter_bound_sim_dif; configuration.inner_bound_drift = configuration.outter_bound_sim_dif; Testbench_Config* cfg3 = new Testbench_Config(configuration); configuration.inner_bound_sim_dif = 0.005; configuration.outter_bound_sim_dif = 0.01; configuration.outter_bound_drift = float(3) * configuration.outter_bound_sim_dif; configuration.inner_bound_drift = configuration.outter_bound_sim_dif; Testbench_Config* cfg4 = new Testbench_Config(configuration); cfg->print(); cfg2->print(); cfg3->print(); cfg4->print(); */ current_tb->register_testbench_config(cfg); /* current_tb->register_testbench_config(cfg2); current_tb->register_testbench_config(cfg3); current_tb->register_testbench_config(cfg4); */ } /* * creates all the agents used in the measurement * and stores them into the global vector */ void create_and_register_All_Agents() { cout << "Creating Agents" << endl; char* c_name_of_current_agent = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_agent, FIRST_MEASURED_DATA_NAME.c_str()); Agent* a_GA_oben_laengs = create_agent(c_name_of_current_agent); strcpy(c_name_of_current_agent, SECOND_MEASURED_DATA_NAME.c_str()); Agent* a_GA_oben_quer = create_agent(c_name_of_current_agent); strcpy(c_name_of_current_agent, THIRD_MEASURED_DATA_NAME.c_str()); Agent* a_GA_unten_laengs = create_agent(c_name_of_current_agent); strcpy(c_name_of_current_agent, FOURTH_MEASURED_DATA_NAME.c_str()); Agent* a_GA_unten_quer = create_agent(c_name_of_current_agent); strcpy(c_name_of_current_agent, FIFTH_MEASURED_DATA_NAME.c_str()); Agent* a_Symmetrie = create_agent(c_name_of_current_agent); strcpy(c_name_of_current_agent, VIABILITY_MONITOR.c_str()); Agent* a_viabilityMonitor = create_agent(c_name_of_current_agent); vec_of_Agents.push_back(a_GA_oben_laengs); vec_of_Agents.push_back(a_GA_oben_quer); vec_of_Agents.push_back(a_GA_unten_laengs); vec_of_Agents.push_back(a_GA_unten_quer); vec_of_Agents.push_back(a_Symmetrie); vec_of_Agents.push_back(a_viabilityMonitor); cout << vec_of_Agents.size() << " agents were created" << endl; delete c_name_of_current_agent; } /* * the working_cycle for all registered agents is set */ void set_working_cycle_of_All_Agents() { unsigned int working_Cyle = SAMPLING; unsigned int size_of_vec_of_Agents = 0; unsigned int index = 0; Agent* current_Agent; size_of_vec_of_Agents = vec_of_Agents.size(); for(index = 0; index < size_of_vec_of_Agents; index++) { current_Agent = vec_of_Agents[index]; setWorkingCycleOfAgent(current_Agent, working_Cyle); } } /* * all necessary sensors are created and registered */ void create_and_register_All_Sensors() { cout << "Creating Sensors" << endl; char* c_name_of_current_sensor = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_sensor, FIRST_MEASURED_DATA_NAME.c_str()); Sensor* s_GA_oben_laengs = create_sensor(c_name_of_current_sensor); strcpy(c_name_of_current_sensor, SECOND_MEASURED_DATA_NAME.c_str()); Sensor* s_GA_oben_quer = create_sensor(c_name_of_current_sensor); strcpy(c_name_of_current_sensor, THIRD_MEASURED_DATA_NAME.c_str()); Sensor* s_GA_unten_laengs = create_sensor(c_name_of_current_sensor); strcpy(c_name_of_current_sensor, FOURTH_MEASURED_DATA_NAME.c_str()); Sensor* s_GA_unten_quer = create_sensor(c_name_of_current_sensor); strcpy(c_name_of_current_sensor, FIFTH_MEASURED_DATA_NAME.c_str()); Sensor* s_Symmetrie = create_sensor(c_name_of_current_sensor); vec_of_Sensors.push_back(s_GA_oben_laengs); vec_of_Sensors.push_back(s_GA_oben_quer); vec_of_Sensors.push_back(s_GA_unten_laengs); vec_of_Sensors.push_back(s_GA_unten_quer); vec_of_Sensors.push_back(s_Symmetrie); cout << vec_of_Sensors.size() << " sensors were created." << endl; delete c_name_of_current_sensor; } /* * working cycle of all registered sensors is set */ void set_working_cycle_of_All_Sensors() { unsigned int working_Cyle = SAMPLING; unsigned int size_of_vec_of_Sensors = 0; unsigned int index = 0; Sensor* current_Sensor; size_of_vec_of_Sensors = vec_of_Sensors.size(); for(index = 0; index < size_of_vec_of_Sensors; index++) { current_Sensor = vec_of_Sensors[index]; setWorkingCycleOfSensor(current_Sensor, working_Cyle); } } /* * creating and registering all channels */ void create_and_register_channels() { create_and_register_channels_for_sensors(); create_and_register_channels_for_agents(); } /* * creating and registering the channels for the sensors. */ void create_and_register_channels_for_sensors() { cout << "Creating and registering channels for sensors" << endl; char* c_name_of_current_channel = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_channel, FIRST_MEASURED_CHANNEL_SENSOR_NAME.c_str()); Channel* c_sa_GA_oben_laengs = create_channel(c_name_of_current_channel, 0); strcpy(c_name_of_current_channel, SECOND_MEASURED_CHANNEL_SENSOR_NAME.c_str()); Channel* c_sa_GA_oben_quer = create_channel(c_name_of_current_channel, 0); strcpy(c_name_of_current_channel, THIRD_MEASURED_CHANNEL_SENSOR_NAME.c_str()); Channel* c_sa_GA_unten_laengs = create_channel(c_name_of_current_channel, 0); strcpy(c_name_of_current_channel, FOURTH_MEASURED_CHANNEL_SENSOR_NAME.c_str()); Channel* c_sa_GA_unten_quer = create_channel(c_name_of_current_channel, 0); strcpy(c_name_of_current_channel, FIFTH_MEASURED_CHANNEL_SENSOR_NAME.c_str()); Channel* c_sa_Symmetrie = create_channel(c_name_of_current_channel, 0); vec_of_Channels_for_Sensors.push_back(c_sa_GA_oben_laengs); vec_of_Channels_for_Sensors.push_back(c_sa_GA_oben_quer); vec_of_Channels_for_Sensors.push_back(c_sa_GA_unten_laengs); vec_of_Channels_for_Sensors.push_back(c_sa_GA_unten_quer); vec_of_Channels_for_Sensors.push_back(c_sa_Symmetrie); cout << vec_of_Channels_for_Sensors.size() << " channels for sensors were created" << endl; delete c_name_of_current_channel; } /* * creating and registering the channels for the agents */ void create_and_register_channels_for_agents() { cout << "Creating and registering channels for agents" << endl; char* c_name_of_current_channel = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_channel, FIRST_MEASURED_CHANNEL_AGENT_NAME.c_str()); Channel* c_aa_GA_oben_laengs = create_channel(c_name_of_current_channel, 0); strcpy(c_name_of_current_channel, SECOND_MEASURED_CHANNEL_AGENT_NAME.c_str()); Channel* c_aa_GA_oben_quer = create_channel(c_name_of_current_channel, 0); strcpy(c_name_of_current_channel, THIRD_MEASURED_CHANNEL_AGENT_NAME.c_str()); Channel* c_aa_GA_unten_laengs = create_channel(c_name_of_current_channel, 0); strcpy(c_name_of_current_channel, FOURTH_MEASURED_CHANNEL_AGENT_NAME.c_str()); Channel* c_aa_GA_unten_quer = create_channel(c_name_of_current_channel, 0); strcpy(c_name_of_current_channel, FIFTH_MEASURED_CHANNEL_AGENT_NAME.c_str()); Channel* c_aa_Symmetrie = create_channel(c_name_of_current_channel, 0); vec_of_Channels_for_Agents.push_back(c_aa_GA_oben_laengs); vec_of_Channels_for_Agents.push_back(c_aa_GA_oben_quer); vec_of_Channels_for_Agents.push_back(c_aa_GA_unten_laengs); vec_of_Channels_for_Agents.push_back(c_aa_GA_unten_quer); vec_of_Channels_for_Agents.push_back(c_aa_Symmetrie); cout << vec_of_Channels_for_Agents.size() << " channels for agents were created" << endl; delete c_name_of_current_channel; } void mount_sensors_in_agents() { Agent* current_agent; Sensor* current_sensor; Channel* current_sensor_channel; unsigned int size_of_vec_sensor = 0; unsigned int index = 0; size_of_vec_sensor = vec_of_Sensors.size(); cout << "mounting sensors in agents." << endl; //it is assumed that the corresponding sensors and agents and channels are always at the same //position in the different vectors, if not then you have to add an search algorithm for it. for(index = 0; index < size_of_vec_sensor; index++) { current_agent = vec_of_Agents[index]; current_sensor = vec_of_Sensors[index]; current_sensor_channel = vec_of_Channels_for_Sensors[index]; mount_sensorInAgent(current_agent, current_sensor, current_sensor_channel); } cout << size_of_vec_sensor << " sensors in agents were mounted" << endl; } void mount_agents_in_agents() { Agent* current_agent; Agent* viability_Monitor; Channel* current_agent_channel; unsigned int size_of_vec_agents = 0; unsigned int index = 0; size_of_vec_agents = vec_of_Agents.size(); //it is assumed that the viability agent is at the last postition in the vector viability_Monitor = vec_of_Agents[size_of_vec_agents-1]; //all agents and channels are registered to the viabilityMonitor agent //so you have to subtract the viabilityMonitor from the number of elements to register //it is assumed that all the corresponding channels and agents are placed at the same index for(index = 0; index < size_of_vec_agents -1; index++) { current_agent = vec_of_Agents[index]; current_agent_channel = vec_of_Channels_for_Agents[index]; //only register if the agent is not the viability_monitor, otherwise you would register the viability monitor to itself. if(current_agent != viability_Monitor) { mount_agentInAgent(viability_Monitor, current_agent, current_agent_channel); } } cout << size_of_vec_agents -1 << "agents were registered to the viability monitor" << endl; } /* * registers the channels for the data agents to the viability monitor */ void register_data_agents_in_agent_state_Handler() { Agent* viability_Monitor; Channel* current_agent_channel; unsigned int size_of_vec_channel_agents = 0; unsigned int index = 0; size_of_vec_channel_agents = vec_of_Channels_for_Agents.size(); //get the agent for the viabilityMonitor, it is assumed that it is at the last position viability_Monitor = vec_of_Agents[vec_of_Agents.size()-1]; //register all the channels to the viability monitor for(index = 0; index < size_of_vec_channel_agents; index++) { current_agent_channel = vec_of_Channels_for_Agents[index]; registerSlaveAgentAsInputVariableInStateHandler(viability_Monitor, current_agent_channel); registerSlaveAgentAsOutputVariableInStateHandler(viability_Monitor, current_agent_channel); } } /* * creates and register all the different linear function blocks */ void create_linear_function_blocks() { //don't change the sequence, because later it is assumed that the functions are //registered int the vector in this sequence //if you change it you have also to change the sequence in the function mount_function_blocks_to_viability_monitor create_same_state_deviation_function_block(); create_another_state_deviation_function_block(); create_state_time_function_block(); create_another_state_time_function_block(); create_valid_state_deviation_function_block(); create_invalid_state_deviation_function_block(); create_valid_state_time_function_block(); create_invalid_state_time_function_block(); create_confidence_state_drift_function_block(); create_confidence_broken_function_block(); } /* * creates and register the linear function block for same state deviation */ void create_same_state_deviation_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_SAME_STATE_DEV.c_str()); LinearFunctionBlock* confSim2StateDev = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* funcConfSim2StateDev1 = new LinearFunction(CONF_SIM2_STATE_DEV_1); funcConfSim2StateDev1->setDomain(false, true, (float)-OUTTER_BOUND_SIM_DIF); funcConfSim2StateDev1->setKandD((float)0, (float)0); confSim2StateDev->addLinearFunction(funcConfSim2StateDev1); LinearFunction* funcConfSim2StateDev2 = new LinearFunction(CONF_SIM2_STATE_DEV_2); funcConfSim2StateDev2->setDomain(true, (float)-OUTTER_BOUND_SIM_DIF, true, (float)-INNER_BOUND_SIM_DIF); funcConfSim2StateDev2->setKandD((float)-OUTTER_BOUND_SIM_DIF, (float)0, (float)-INNER_BOUND_SIM_DIF, (float)1); confSim2StateDev->addLinearFunction(funcConfSim2StateDev2); LinearFunction* funcConfSim2StateDev3 = new LinearFunction(CONF_SIM2_STATE_DEV_3); funcConfSim2StateDev3->setDomain(true, (float)-INNER_BOUND_SIM_DIF, true, (float)INNER_BOUND_SIM_DIF); funcConfSim2StateDev3->setKandD((float)0, (float)1); confSim2StateDev->addLinearFunction(funcConfSim2StateDev3); LinearFunction* funcConfSim2StateDev4 = new LinearFunction(CONF_SIM2_STATE_DEV_4); funcConfSim2StateDev4->setDomain(true, (float)INNER_BOUND_SIM_DIF, true, (float)OUTTER_BOUND_SIM_DIF); funcConfSim2StateDev4->setKandD((float)INNER_BOUND_SIM_DIF, (float)1, (float)OUTTER_BOUND_SIM_DIF, (float)0); confSim2StateDev->addLinearFunction(funcConfSim2StateDev4); LinearFunction* funcConfSim2StateDev5 = new LinearFunction(CONF_SIM2_STATE_DEV_5); funcConfSim2StateDev5->setDomain(true, (float)OUTTER_BOUND_SIM_DIF, false); funcConfSim2StateDev5->setKandD((float)0, (float)0); confSim2StateDev->addLinearFunction(funcConfSim2StateDev5); vec_of_linear_Function_Blocks.push_back(confSim2StateDev); delete c_name_of_current_func_block; } /* * creates and register another state deviation function block */ void create_another_state_deviation_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_ANOTHER_STATE_DEV.c_str()); LinearFunctionBlock* confDif2StateDev = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* funcConfDif2StateDev1 = new LinearFunction(CONF_DIF2_STATE_DEV_1); funcConfDif2StateDev1->setDomain(false, true, (float)-OUTTER_BOUND_SIM_DIF); funcConfDif2StateDev1->setKandD((float)0, (float)1); confDif2StateDev->addLinearFunction(funcConfDif2StateDev1); LinearFunction* funcConfDif2StateDev2 = new LinearFunction(CONF_DIF2_STATE_DEV_2); funcConfDif2StateDev2->setDomain(true, (float)-OUTTER_BOUND_SIM_DIF, true, (float)-INNER_BOUND_SIM_DIF); funcConfDif2StateDev2->setKandD((float)-OUTTER_BOUND_SIM_DIF, (float)1, (float)-INNER_BOUND_SIM_DIF, (float)0); confDif2StateDev->addLinearFunction(funcConfDif2StateDev2); LinearFunction* funcConfDif2StateDev3 = new LinearFunction(CONF_DIF2_STATE_DEV_3); funcConfDif2StateDev3->setDomain(true, (float)-INNER_BOUND_SIM_DIF, true, (float)INNER_BOUND_SIM_DIF); funcConfDif2StateDev3->setKandD((float)0, (float)0); confDif2StateDev->addLinearFunction(funcConfDif2StateDev3); LinearFunction* funcConfDif2StateDev4 = new LinearFunction(CONF_DIF2_STATE_DEV_4); funcConfDif2StateDev4->setDomain(true, (float)INNER_BOUND_SIM_DIF, true, (float)OUTTER_BOUND_SIM_DIF); funcConfDif2StateDev4->setKandD((float)INNER_BOUND_SIM_DIF, (float)0, (float)OUTTER_BOUND_SIM_DIF, (float)1); confDif2StateDev->addLinearFunction(funcConfDif2StateDev4); LinearFunction* funcConfDif2StateDev5 = new LinearFunction(CONF_DIF2_STATE_DEV_5); funcConfDif2StateDev5->setDomain(true, (float)OUTTER_BOUND_SIM_DIF, false); funcConfDif2StateDev5->setKandD((float)0, (float)1); confDif2StateDev->addLinearFunction(funcConfDif2StateDev5); vec_of_linear_Function_Blocks.push_back(confDif2StateDev); delete c_name_of_current_func_block; } void create_state_time_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_SAME_TIME.c_str()); LinearFunctionBlock* confSim2StateTime = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* funcConfSim2StateTime1 = new LinearFunction(CONF_SIM2_STATE_TIME_1); funcConfSim2StateTime1->setDomain(false, true, (float)0); funcConfSim2StateTime1->setKandD((float)0, (float)0); confSim2StateTime->addLinearFunction(funcConfSim2StateTime1); LinearFunction* funcConfSim2StateTime2 = new LinearFunction(CONF_SIM2_STATE_TIME_2); funcConfSim2StateTime2->setDomain(true, (float)0, true, (float)LENGTH); funcConfSim2StateTime2->setKandD((float)0, (float)0, (float)LENGTH, (float)1); confSim2StateTime->addLinearFunction(funcConfSim2StateTime2); LinearFunction* funcConfSim2StateTime3 = new LinearFunction(CONF_SIM2_STATE_TIME_3); funcConfSim2StateTime3->setDomain(true, (float)LENGTH, false); funcConfSim2StateTime3->setKandD((float)0, (float)1); confSim2StateTime->addLinearFunction(funcConfSim2StateTime3); vec_of_linear_Function_Blocks.push_back(confSim2StateTime); delete c_name_of_current_func_block; } void create_another_state_time_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_ANOTHER_STATE_TIME.c_str()); LinearFunctionBlock* confDif2StateTime = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* funcConfDif2StateTime1 = new LinearFunction(CONF_DIF2_STATE_TIME_1); funcConfDif2StateTime1->setDomain(false, true, (float)0); funcConfDif2StateTime1->setKandD((float)0, (float)1); confDif2StateTime->addLinearFunction(funcConfDif2StateTime1); LinearFunction* funcConfDif2StateTime2 = new LinearFunction(CONF_DIF2_STATE_TIME_2); funcConfDif2StateTime2->setDomain(true, (float)0, true, (float)LENGTH); funcConfDif2StateTime2->setKandD((float)0, (float)1, (float)LENGTH, (float)0); confDif2StateTime->addLinearFunction(funcConfDif2StateTime2); LinearFunction* funcConfDif2StateTime3 = new LinearFunction(CONF_DIF2_STATE_TIME_3); funcConfDif2StateTime3->setDomain(true, (float)LENGTH, false); funcConfDif2StateTime3->setKandD((float)0, (float)0); confDif2StateTime->addLinearFunction(funcConfDif2StateTime3); vec_of_linear_Function_Blocks.push_back(confDif2StateTime); delete c_name_of_current_func_block; } void create_valid_state_deviation_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_VAILD_STATE_DEV.c_str()); LinearFunctionBlock* confValidStateDev = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* funcConfValidStateDev1 = new LinearFunction(CONF_VALID_STATE_DEV_1); funcConfValidStateDev1->setDomain(false, true, (float)-OUTTER_BOUND_SIM_DIF); funcConfValidStateDev1->setKandD((float)0, (float)0); confValidStateDev->addLinearFunction(funcConfValidStateDev1); LinearFunction* funcConfValidStateDev2 = new LinearFunction(CONF_VALID_STATE_DEV_2); funcConfValidStateDev2->setDomain(true, (float)-OUTTER_BOUND_SIM_DIF, true, (float)-INNER_BOUND_SIM_DIF); funcConfValidStateDev2->setKandD((float)-OUTTER_BOUND_SIM_DIF, (float)0, (float)-INNER_BOUND_SIM_DIF, (float)1); confValidStateDev->addLinearFunction(funcConfValidStateDev2); LinearFunction* funcConfValidStateDev3 = new LinearFunction(CONF_VALID_STATE_DEV_3); funcConfValidStateDev3->setDomain(true, (float)-INNER_BOUND_SIM_DIF, true, (float)INNER_BOUND_SIM_DIF); funcConfValidStateDev3->setKandD((float)0, (float)1); confValidStateDev->addLinearFunction(funcConfValidStateDev3); LinearFunction* funcConfValidStateDev4 = new LinearFunction(CONF_VALID_STATE_DEV_4); funcConfValidStateDev4->setDomain(true, (float)INNER_BOUND_SIM_DIF, true, (float)OUTTER_BOUND_SIM_DIF); funcConfValidStateDev4->setKandD((float)INNER_BOUND_SIM_DIF, (float)1, (float)OUTTER_BOUND_SIM_DIF, (float)0); confValidStateDev->addLinearFunction(funcConfValidStateDev4); LinearFunction* funcConfValidStateDev5 = new LinearFunction(CONF_VALID_STATE_DEV_5); funcConfValidStateDev5->setDomain(true, (float)OUTTER_BOUND_SIM_DIF, false); funcConfValidStateDev5->setKandD((float)0, (float)0); confValidStateDev->addLinearFunction(funcConfValidStateDev5); vec_of_linear_Function_Blocks.push_back(confValidStateDev); delete c_name_of_current_func_block; } void create_invalid_state_deviation_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_INVALID_STATE_DEV.c_str()); LinearFunctionBlock* confInvalidStateDev = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* funcConfInvalidStateDev1 = new LinearFunction(CONF_INVALID_STATE_DEV_1); funcConfInvalidStateDev1->setDomain(false, true, (float)-OUTTER_BOUND_SIM_DIF); funcConfInvalidStateDev1->setKandD((float)0, (float)1); confInvalidStateDev->addLinearFunction(funcConfInvalidStateDev1); LinearFunction* funcConfInvalidStateDev2 = new LinearFunction(CONF_INVALID_STATE_DEV_2); funcConfInvalidStateDev2->setDomain(true, (float)-OUTTER_BOUND_SIM_DIF, true, (float)-INNER_BOUND_SIM_DIF); funcConfInvalidStateDev2->setKandD((float)-OUTTER_BOUND_SIM_DIF, (float)1, (float)-INNER_BOUND_SIM_DIF, (float)0); confInvalidStateDev->addLinearFunction(funcConfInvalidStateDev2); LinearFunction* funcConfInvalidStateDev3 = new LinearFunction(CONF_INVALID_STATE_DEV_3); funcConfInvalidStateDev3->setDomain(true, (float)-INNER_BOUND_SIM_DIF, true, (float)INNER_BOUND_SIM_DIF); funcConfInvalidStateDev3->setKandD((float)0, (float)0); confInvalidStateDev->addLinearFunction(funcConfInvalidStateDev3); LinearFunction* funcConfInvalidStateDev4 = new LinearFunction(CONF_INVALID_STATE_DEV_4); funcConfInvalidStateDev4->setDomain(true, (float)INNER_BOUND_SIM_DIF, true, (float)OUTTER_BOUND_SIM_DIF); funcConfInvalidStateDev4->setKandD((float)INNER_BOUND_SIM_DIF, (float)0, (float)OUTTER_BOUND_SIM_DIF, (float)1); confInvalidStateDev->addLinearFunction(funcConfInvalidStateDev4); LinearFunction* funcConfInvalidStateDev5 = new LinearFunction(CONF_INVALID_STATE_DEV_5); funcConfInvalidStateDev5->setDomain(true, (float)OUTTER_BOUND_SIM_DIF, false); funcConfInvalidStateDev5->setKandD((float)0, (float)1); confInvalidStateDev->addLinearFunction(funcConfInvalidStateDev5); vec_of_linear_Function_Blocks.push_back(confInvalidStateDev); delete c_name_of_current_func_block; } void create_valid_state_time_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_VALID_STATE_TIME.c_str()); LinearFunctionBlock* confValidStateTime = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* funcConfValidStateTime1 = new LinearFunction(VALID_STATE_TIME_1); funcConfValidStateTime1->setDomain(false, true, (float)0); funcConfValidStateTime1->setKandD((float)0, (float)0); confValidStateTime->addLinearFunction(funcConfValidStateTime1); LinearFunction* funcConfValidStateTime2 = new LinearFunction(VALID_STATE_TIME_2); funcConfValidStateTime2->setDomain(true, (float)0, true, (float)LENGTH); //10 funcConfValidStateTime2->setKandD((float)0, (float)0, (float)LENGTH, (float)1); confValidStateTime->addLinearFunction(funcConfValidStateTime2); LinearFunction* funcConfValidStateTime3 = new LinearFunction(VALID_STATE_TIME_3); funcConfValidStateTime3->setDomain(true, (float)LENGTH, false); funcConfValidStateTime3->setKandD((float)0, (float)1); confValidStateTime->addLinearFunction(funcConfValidStateTime3); vec_of_linear_Function_Blocks.push_back(confValidStateTime); delete c_name_of_current_func_block; } void create_invalid_state_time_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_INVALID_STATE_TIME.c_str()); LinearFunctionBlock* confInvalidStateTime = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* funcConfInvalidStateTime1 = new LinearFunction(INVALID_STATE_TIME_1); funcConfInvalidStateTime1->setDomain(false, true, (float)0); funcConfInvalidStateTime1->setKandD((float)0, (float)1); confInvalidStateTime->addLinearFunction(funcConfInvalidStateTime1); LinearFunction* funcConfInvalidStateTime2 = new LinearFunction(INVALID_STATE_TIME_2); funcConfInvalidStateTime2->setDomain(true, (float)0, true, (float)LENGTH); funcConfInvalidStateTime2->setKandD((float)0, (float)1, (float)LENGTH, (float)0); confInvalidStateTime->addLinearFunction(funcConfInvalidStateTime2); LinearFunction* funcConfInvalidStateTime3 = new LinearFunction(INVALID_STATE_TIME_3); funcConfInvalidStateTime3->setDomain(true, (float)LENGTH, false); funcConfInvalidStateTime3->setKandD((float)0, (float)0); confInvalidStateTime->addLinearFunction(funcConfInvalidStateTime3); vec_of_linear_Function_Blocks.push_back(confInvalidStateTime); delete c_name_of_current_func_block; } void create_confidence_state_drift_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_CONFIDENCE_STATE_DRIFTS.c_str()); LinearFunctionBlock* confStateDrifts = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* functionConfidenceDriftDeviation1 = new LinearFunction(CONFIDENCE_DRIFT_DEVIATION_1); functionConfidenceDriftDeviation1->setDomain(false, true, (float)-OUTTER_BOUND_DRIFT); functionConfidenceDriftDeviation1->setKandD((float)0, (float)1); confStateDrifts->addLinearFunction(functionConfidenceDriftDeviation1); LinearFunction* functionConfidenceDriftDeviation2 = new LinearFunction(CONFIDENCE_DRIFT_DEVIATION_2); functionConfidenceDriftDeviation2->setDomain(true, (float)-OUTTER_BOUND_DRIFT, true, (float)-INNER_BOUND_DRIFT); functionConfidenceDriftDeviation2->setKandD((float)-INNER_BOUND_DRIFT, (float)1, (float)-INNER_BOUND_DRIFT, (float)0); confStateDrifts->addLinearFunction(functionConfidenceDriftDeviation2); LinearFunction* functionConfidenceDriftDeviation3 = new LinearFunction(CONFIDENCE_DRIFT_DEVIATION_3); functionConfidenceDriftDeviation3->setDomain(true, (float)-INNER_BOUND_DRIFT, true, (float)INNER_BOUND_DRIFT); functionConfidenceDriftDeviation3->setKandD((float)0, (float)0); confStateDrifts->addLinearFunction(functionConfidenceDriftDeviation3); LinearFunction* functionConfidenceDriftDeviation4 = new LinearFunction(CONFIDENCE_DRIFT_DEVIATION_4); functionConfidenceDriftDeviation4->setDomain(true, (float)INNER_BOUND_DRIFT, true, (float)OUTTER_BOUND_DRIFT); functionConfidenceDriftDeviation4->setKandD((float)INNER_BOUND_DRIFT, (float)0, (float)OUTTER_BOUND_DRIFT, (float)1); confStateDrifts->addLinearFunction(functionConfidenceDriftDeviation4); LinearFunction* functionConfidenceDriftDeviation5 = new LinearFunction(CONFIDENCE_DRIFT_DEVIATION_5); functionConfidenceDriftDeviation5->setDomain(true, (float)OUTTER_BOUND_DRIFT, false); functionConfidenceDriftDeviation5->setKandD((float)0, (float)1); confStateDrifts->addLinearFunction(functionConfidenceDriftDeviation5); vec_of_linear_Function_Blocks.push_back(confStateDrifts); delete c_name_of_current_func_block; } void create_confidence_broken_function_block() { char* c_name_of_current_func_block = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_func_block, FUNC_BLOCK_NAME_CONFIDENCE_BROKEN.c_str()); LinearFunctionBlock* confBroken = new LinearFunctionBlock(c_name_of_current_func_block); LinearFunction* functionConfidenceBroken1 = new LinearFunction(CONFIDENCE_BROKEN_1); functionConfidenceBroken1->setDomain(false, true, (float)0); functionConfidenceBroken1->setKandD((float)0, (float)0); confBroken->addLinearFunction(functionConfidenceBroken1); LinearFunction* functionConfidenceBroken2 = new LinearFunction(CONFIDENCE_BROKEN_2); functionConfidenceBroken2->setDomain(true, (float)0, true, (float)BOUND_BROKEN); functionConfidenceBroken2->setKandD((float)0, (float)0, (float)BOUND_BROKEN, (float)1); confBroken->addLinearFunction(functionConfidenceBroken2); LinearFunction* functionConfidenceBroken3 = new LinearFunction(CONFIDENCE_BROKEN_3); functionConfidenceBroken3->setDomain(true, (float)BOUND_BROKEN, false); functionConfidenceBroken3->setKandD((float)0, (float)1); confBroken->addLinearFunction(functionConfidenceBroken3); vec_of_linear_Function_Blocks.push_back(confBroken); delete c_name_of_current_func_block; } /* * mount the different function blocks to the viability monitor agent */ void mount_function_blocks_to_viability_monitor() { Agent* viability_Monitor; LinearFunctionBlock* current_Linear_Function_Bock; unsigned int size_of_vec_lin_func_block = vec_of_linear_Function_Blocks.size(); unsigned int index = 0; //it is assumed that the viability monitor is at the last position of the vector of agents viability_Monitor = vec_of_Agents[vec_of_Agents.size()-1]; for(index = 0; index < size_of_vec_lin_func_block; index++) { current_Linear_Function_Bock = vec_of_linear_Function_Blocks[index]; //it is assumed that the function blocks are added into the vector in the following sequence switch(index) { case 0: viability_Monitor->get_stateHandler()->FuncBlockConfSim2StateDev = current_Linear_Function_Bock; break; case 1: viability_Monitor->get_stateHandler()->FuncBlockConfDif2StateDev = current_Linear_Function_Bock; break; case 2: viability_Monitor->get_stateHandler()->FuncBlockConfSim2StateTime = current_Linear_Function_Bock; break; case 3: viability_Monitor->get_stateHandler()->FuncBlockConfDif2StateTime = current_Linear_Function_Bock; break; case 4: viability_Monitor->get_stateHandler()->FuncBlockConfValStateDev = current_Linear_Function_Bock; break; case 5: viability_Monitor->get_stateHandler()->FuncBlockConfInvStateDev = current_Linear_Function_Bock; break; case 6: viability_Monitor->get_stateHandler()->FuncBlockConfValStateTime = current_Linear_Function_Bock; break; case 7: viability_Monitor->get_stateHandler()->FuncBlockConfInvStateTime = current_Linear_Function_Bock; break; case 8: viability_Monitor->get_stateHandler()->DriftDeviation = current_Linear_Function_Bock; break; case 9: viability_Monitor->get_stateHandler()->FuncBlockConfBrokenSamples = current_Linear_Function_Bock; break; } } } void create_all_testbenches() { char* c_name_of_current_testbench = new char[MAX_LENGTH_NAME]; strcpy(c_name_of_current_testbench, TEST_BENCH.c_str()); cout << "Creating test bench" << endl; Testbench* tb = create_testbench(c_name_of_current_testbench); create_and_register_all_Testbench_Configs(tb); vec_of_test_benches.push_back(tb); delete c_name_of_current_testbench; } void create_csvr_modules() { //sets the row in which the data starts, maybe row one contains the headers unsigned int row = 2; char* c_name_of_current_csv_module = new char[MAX_LENGTH_NAME]; string current_reader_path_and_file_name; //for entire data set offset has to be 1 int data_offset = -1; if (FILE_NAME_OF_ENTIRE_DATA == "Ga_all_Symmetrie_Combined_25000_to_30000.csv"){ data_offset = 2; } cout << "Creating CSV Reader Modules" << endl; current_reader_path_and_file_name = PATH_TO_CSV_DATA_FILES + PATH_TO_DATE_OF_MEASUREMENT + PATH_TO_AN_MEASURMENT + FILE_NAME_OF_ENTIRE_DATA; strcpy(c_name_of_current_csv_module, FIRST_MEASURED_DATA_CSV_NAME.c_str()); CSVreaderModule* csvr_GA_oben_laengs = create_CSVreaderModule(c_name_of_current_csv_module,current_reader_path_and_file_name.c_str(),1 + data_offset,row); current_reader_path_and_file_name = PATH_TO_CSV_DATA_FILES + PATH_TO_DATE_OF_MEASUREMENT + PATH_TO_AN_MEASURMENT + FILE_NAME_OF_ENTIRE_DATA; strcpy(c_name_of_current_csv_module, SECOND_MEASURED_DATA_CSV_NAME.c_str()); CSVreaderModule* csvr_GA_oben_quer = create_CSVreaderModule(c_name_of_current_csv_module,current_reader_path_and_file_name.c_str(),2 + data_offset,row); current_reader_path_and_file_name = PATH_TO_CSV_DATA_FILES + PATH_TO_DATE_OF_MEASUREMENT + PATH_TO_AN_MEASURMENT + FILE_NAME_OF_ENTIRE_DATA; strcpy(c_name_of_current_csv_module, THIRD_MEASURED_DATA_CSV_NAME.c_str()); CSVreaderModule* csvr_GA_unten_laengs = create_CSVreaderModule(c_name_of_current_csv_module,current_reader_path_and_file_name.c_str(),3 + data_offset,row); current_reader_path_and_file_name = PATH_TO_CSV_DATA_FILES + PATH_TO_DATE_OF_MEASUREMENT + PATH_TO_AN_MEASURMENT + FILE_NAME_OF_ENTIRE_DATA; strcpy(c_name_of_current_csv_module, FOURTH_MEASURED_DATA_CSV_NAME.c_str()); CSVreaderModule* csvr_GA_unten_quer = create_CSVreaderModule(c_name_of_current_csv_module,current_reader_path_and_file_name.c_str(),4 + data_offset,row); current_reader_path_and_file_name = PATH_TO_CSV_DATA_FILES + PATH_TO_DATE_OF_MEASUREMENT + PATH_TO_AN_MEASURMENT + FILE_NAME_OF_ENTIRE_DATA; strcpy(c_name_of_current_csv_module, FIFTH_MEASURED_DATA_CSV_NAME.c_str()); CSVreaderModule* csvr_Symmetrie = create_CSVreaderModule(c_name_of_current_csv_module,current_reader_path_and_file_name.c_str(),5 + data_offset,row); vec_of_csv_readers.push_back(csvr_GA_oben_laengs); vec_of_csv_readers.push_back(csvr_GA_oben_quer); vec_of_csv_readers.push_back(csvr_GA_unten_laengs); vec_of_csv_readers.push_back(csvr_GA_unten_quer); vec_of_csv_readers.push_back(csvr_Symmetrie); delete c_name_of_current_csv_module; } /* * all agents would be registered to all testbenches */ void register_agents_in_testbenches() { Testbench* current_tb; unsigned int size_of_vec_test_benches = vec_of_test_benches.size(); unsigned int index_tb = 0; Agent* current_ag; unsigned int size_of_vec_agents = vec_of_Agents.size(); unsigned int index_agents = 0; cout << "registering agents in testbenches" << endl; for(index_tb = 0; index_tb < size_of_vec_test_benches; index_tb++) { current_tb = vec_of_test_benches[index_tb]; for(index_agents = 0; index_agents < size_of_vec_agents; index_agents++) { current_ag = vec_of_Agents[index_agents]; register_agentInTestbench(current_tb, current_ag); } } cout << size_of_vec_agents << " agents were registered in every of the " << size_of_vec_test_benches << " testbenches" << endl; } /* * registering the sensors and the corresponding csv-readers in the testbenches * it is assumed that the csv readers and the sensors are at the same index position * in the vectors. */ void register_sensors_in_testbenches() { Testbench* current_tb; unsigned int size_of_vec_test_benches = vec_of_test_benches.size(); unsigned int index_tb = 0; Sensor* current_se; unsigned int size_of_vec_sensors = vec_of_Sensors.size(); unsigned int index_sensors = 0; CSVreaderModule* current_csv_reader; unsigned int size_of_vec_csv_reader = vec_of_csv_readers.size(); if(size_of_vec_csv_reader != size_of_vec_sensors) { cout << "Error, in sequence of data processing"; cout << "Number of csv-readers should be equal to number of sensors" << endl; } else { cout << "Registering sensors and their csv-readers in testbenches " << endl; for(index_tb = 0; index_tb < size_of_vec_test_benches; index_tb++) { current_tb = vec_of_test_benches[index_tb]; for(index_sensors = 0; index_sensors < size_of_vec_sensors; index_sensors++) { current_se = vec_of_Sensors[index_sensors]; //it is assumed that the sensor and the corresponding csv-reader is stored //at the same position in the two different vectors current_csv_reader = vec_of_csv_readers[index_sensors]; register_sensorInTestbench(current_tb, current_se, current_csv_reader); } } cout << size_of_vec_sensors << " Sensors and their csv-readers were registered to "; cout << "every of the " << size_of_vec_test_benches << " testbenches" << endl; } } void register_channels_in_testbenches() { register_channels_of_sensors_in_testbenches(); register_channels_of_actors_in_testbenches(); } void register_channels_of_sensors_in_testbenches() { Testbench* current_tb; unsigned int size_of_vec_test_benches = vec_of_test_benches.size(); unsigned int index_tb = 0; Channel* current_se_ch; unsigned int size_of_vec_se_channel = vec_of_Channels_for_Sensors.size(); unsigned int index_se_ch = 0; cout << "Registering channels of sensors in testbench" << endl; for(index_tb = 0; index_tb < size_of_vec_test_benches; index_tb++) { current_tb = vec_of_test_benches[index_tb]; for(index_se_ch = 0; index_se_ch < size_of_vec_se_channel; index_se_ch++) { current_se_ch = vec_of_Channels_for_Sensors[index_se_ch]; register_channelInTestbench(current_tb, current_se_ch); } } cout << size_of_vec_se_channel << " channels of sensors were registered in "; cout << size_of_vec_test_benches << " testbenches." << endl; } void register_channels_of_actors_in_testbenches() { Testbench* current_tb; unsigned int size_of_vec_test_benches = vec_of_test_benches.size(); unsigned int index_tb = 0; Channel* current_se_ch; unsigned int size_of_vec_ag_channel = vec_of_Channels_for_Agents.size(); unsigned int index_se_ch = 0; cout << "Registering channels of agents in testbench" << endl; for(index_tb = 0; index_tb < size_of_vec_test_benches; index_tb++) { current_tb = vec_of_test_benches[index_tb]; for(index_se_ch = 0; index_se_ch < size_of_vec_ag_channel; index_se_ch++) { current_se_ch = vec_of_Channels_for_Agents[index_se_ch]; register_channelInTestbench(current_tb, current_se_ch); } } cout << size_of_vec_ag_channel << " channels of agents were registered in "; cout << size_of_vec_test_benches << " testbenches." << endl; } void run_simulation_of_all_testbenches() { string pressed_key; Testbench* current_tb; vector vec_tb_configs; Testbench_Config* current_tb_config; unsigned int size_of_vec_test_benches = vec_of_test_benches.size(); unsigned int index_tb = 0; unsigned int size_of_vec_test_bench_config; unsigned int index_tb_cfg = 0; //the number of rows which will be read in from the files. unsigned int sim_rounds = 0; const int start_row = 1; if(FILE_NAME_OF_ENTIRE_DATA == "Ga_all_Symmetrie_Combined_25000_to_30000.csv"){ sim_rounds = 5000; } cout << "Press any key to start the simulation of all testbenches." << endl; getline(cin, pressed_key); for(index_tb = 0; index_tb < size_of_vec_test_benches; index_tb++){ current_tb = vec_of_test_benches[index_tb]; index_tb_cfg = 0; vec_tb_configs = current_tb->get_all_registered_testbench_configs(); size_of_vec_test_bench_config = vec_tb_configs.size(); for(index_tb_cfg = 0; index_tb_cfg < size_of_vec_test_bench_config; index_tb_cfg++){ current_tb_config = vec_tb_configs[index_tb_cfg]; current_tb->set_current_tb_config_index(index_tb_cfg); current_tb->set_CSV_Writer_parameter(); current_tb->set_config_values_in_linear_functions(); //have to open new file first! with the CSV-Writer, for every round > 0 current_tb->simulate(sim_rounds); if(index_tb_cfg < size_of_vec_test_bench_config - 1) { current_tb->set_CSV_Reader_row(start_row); current_tb->set_CSV_Reader_to_beginning(); current_tb->reset_States(); } } } cout << "Simulation of " << size_of_vec_test_benches << " testbenches successfully finished" << endl; } void close_file_pointers() { CSVreaderModule* current_csv_reader; unsigned int size_of_vec_csv_reader = vec_of_csv_readers.size(); unsigned int index_csv_reader; for(index_csv_reader = 0; index_csv_reader < size_of_vec_csv_reader; index_csv_reader++) { current_csv_reader = vec_of_csv_readers[index_csv_reader]; current_csv_reader->close_file(); } } void empty_static_vectors() { empty_vec_Agent(); empty_vec_Channel_Agent(); empty_vec_Channel_Sensor(); empty_vec_Sensors(); empty_vec_csv_raders(); empty_vec_linear_func_Blocks(); empty_vec_TestBench(); vec_of_Channels_for_Agents.clear(); vec_of_Channels_for_Sensors.clear(); vec_of_Sensors.clear(); vec_of_csv_readers.clear(); vec_of_linear_Function_Blocks.clear(); } void empty_vec_Agent() { Agent* cur_Agent; unsigned int size_of_vec_Agent = vec_of_Agents.size(); unsigned int index_Agent; for(index_Agent = 0; index_Agent < size_of_vec_Agent; index_Agent++){ cur_Agent = vec_of_Agents[index_Agent]; //delete cur_Agent; } vec_of_Agents.clear(); } void empty_vec_Channel_Agent() { Channel* cur_Channel; unsigned int size_of_vec_Chan_Agent = vec_of_Channels_for_Agents.size(); unsigned int index_Channel; for(index_Channel = 0; index_Channel < size_of_vec_Chan_Agent; index_Channel++){ cur_Channel = vec_of_Channels_for_Agents[index_Channel]; //delete cur_Channel; } vec_of_Channels_for_Agents.clear(); } void empty_vec_Channel_Sensor() { Channel* cur_Channel; unsigned int size_of_vec_Chan_Sensor = vec_of_Channels_for_Sensors.size(); unsigned int index_Channel; for(index_Channel = 0; index_Channel < size_of_vec_Chan_Sensor; index_Channel++){ cur_Channel = vec_of_Channels_for_Sensors[index_Channel]; //delete cur_Channel; } vec_of_Channels_for_Sensors.clear(); } void empty_vec_Sensors() { Sensor* cur_Sensor; unsigned int size_of_vec_Chan_Sensor = vec_of_Sensors.size(); unsigned int index_Sensor; for(index_Sensor = 0; index_Sensor < size_of_vec_Chan_Sensor; index_Sensor++){ cur_Sensor = vec_of_Sensors[index_Sensor]; //delete cur_Sensor; } vec_of_Sensors.clear(); } void empty_vec_csv_raders() { CSVreaderModule* cur_csv_reader; unsigned int size_of_vec_csv_reader = vec_of_csv_readers.size(); unsigned int index_csv_reader; for(index_csv_reader = 0; index_csv_reader < size_of_vec_csv_reader; index_csv_reader++){ cur_csv_reader = vec_of_csv_readers[index_csv_reader]; //delete cur_csv_reader; } vec_of_csv_readers.clear(); } void empty_vec_linear_func_Blocks() { LinearFunctionBlock* cur_lin_fun_block; unsigned int size_of_vec_lin_fun_block= vec_of_linear_Function_Blocks.size(); unsigned int index_lin_fun_block; for(index_lin_fun_block = 0; index_lin_fun_block < size_of_vec_lin_fun_block; index_lin_fun_block++){ cur_lin_fun_block = vec_of_linear_Function_Blocks[index_lin_fun_block]; //delete cur_lin_fun_block; } vec_of_linear_Function_Blocks.clear(); } void empty_vec_TestBench() { Testbench* current_tb; unsigned int size_of_vec_test_benches = vec_of_test_benches.size(); unsigned int index_tb = 0; for(index_tb = 0; index_tb < size_of_vec_test_benches; index_tb++){ current_tb = vec_of_test_benches[index_tb]; current_tb->free_resources(); delete current_tb; } vec_of_test_benches.clear(); }