Fuzzy libray for embedded targets developed by zerokol. Read more on: http://zerokol.com/product/51e93616e84c5571b7000018/2/en edit by Bruno Alfano - corrected deallocation of FuzzyOutput
Fuzzy library by Zerokol. Read more on: http://zerokol.com/product/51e93616e84c5571b7000018/2/en
edit by Bruno Alfano - corrected deallocation bug for FuzzyOutput
Diff: FuzzyIO.cpp
- Revision:
- 0:66cd67db4f1b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FuzzyIO.cpp Wed Jun 24 06:30:39 2015 +0000 @@ -0,0 +1,79 @@ +/* + * Robotic Research Group (RRG) + * State University of Piaui (UESPI), Brazil - Piauí - Teresina + * + * FuzzyIO.cpp + * + * Author: Msc. Marvin Lemos <marvinlemos@gmail.com> + * AJ Alves <aj.alves@zerokol.com> + * Co authors: Douglas S. Kridi <douglaskridi@gmail.com> + * Kannya Leal <kannyal@hotmail.com> + */ +#include "FuzzyIO.h" + +// CONSTRUTORES +FuzzyIO::FuzzyIO(){ +} + +FuzzyIO::FuzzyIO(int index){ + this->index = index; + // Iniciando os ponteiros como nulo + this->fuzzySets = NULL; + this->fuzzySetsCursor = NULL; +} + +// DESTRUTOR +FuzzyIO::~FuzzyIO(){ + this->cleanFuzzySets(this->fuzzySets); +} + +// MÉTODOS PÚBLICOS +int FuzzyIO::getIndex(){ + return this->index; +} + +void FuzzyIO::setCrispInput(float crispInput){ + this->crispInput = crispInput; +} + +float FuzzyIO::getCrispInput(){ + return this->crispInput; +} + +bool FuzzyIO::addFuzzySet(FuzzySet* fuzzySet){ + fuzzySetArray *aux; + // Alocando espaço na memória + if((aux = (fuzzySetArray *) malloc(sizeof(fuzzySetArray))) == NULL){ + return false; + } + aux->fuzzySet = fuzzySet; + aux->next = NULL; + + if(this->fuzzySets == NULL){ + this->fuzzySets = aux; + this->fuzzySetsCursor = aux; + }else{ + this->fuzzySetsCursor->next = aux; + this->fuzzySetsCursor = aux; + } + return true; +} + +void FuzzyIO::resetFuzzySets(){ + fuzzySetArray* fuzzySetsAux; + fuzzySetsAux = this->fuzzySets; + // Calculando as pertinências de totos os FuzzyInputs + while(fuzzySetsAux != NULL){ + fuzzySetsAux->fuzzySet->reset(); + fuzzySetsAux = fuzzySetsAux->next; + } +} + +// MÉTODOS PROTEGIDOS +void FuzzyIO::cleanFuzzySets(fuzzySetArray *aux){ + if(aux != NULL){ + // Esvaziando a memória alocada + this->cleanFuzzySets(aux->next); + free(aux); + } +} \ No newline at end of file