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
FuzzyRuleConsequent.cpp@2:460b409e26e8, 2015-06-24 (annotated)
- Committer:
- astaff15
- Date:
- Wed Jun 24 15:08:13 2015 +0000
- Revision:
- 2:460b409e26e8
- Parent:
- 0:66cd67db4f1b
Corrected FuzzyOutput destructor bug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
astaff15 | 0:66cd67db4f1b | 1 | /* |
astaff15 | 0:66cd67db4f1b | 2 | * Robotic Research Group (RRG) |
astaff15 | 0:66cd67db4f1b | 3 | * State University of Piaui (UESPI), Brazil - Piauí - Teresina |
astaff15 | 0:66cd67db4f1b | 4 | * |
astaff15 | 0:66cd67db4f1b | 5 | * FuzzyRuleConsequent.cpp |
astaff15 | 0:66cd67db4f1b | 6 | * |
astaff15 | 0:66cd67db4f1b | 7 | * Author: Msc. Marvin Lemos <marvinlemos@gmail.com> |
astaff15 | 0:66cd67db4f1b | 8 | * AJ Alves <aj.alves@zerokol.com> |
astaff15 | 0:66cd67db4f1b | 9 | * Co authors: Douglas S. Kridi <douglaskridi@gmail.com> |
astaff15 | 0:66cd67db4f1b | 10 | * Kannya Leal <kannyal@hotmail.com> |
astaff15 | 0:66cd67db4f1b | 11 | */ |
astaff15 | 0:66cd67db4f1b | 12 | #include "FuzzyRuleConsequent.h" |
astaff15 | 0:66cd67db4f1b | 13 | |
astaff15 | 0:66cd67db4f1b | 14 | // CONSTRUTORES |
astaff15 | 0:66cd67db4f1b | 15 | FuzzyRuleConsequent::FuzzyRuleConsequent(){ |
astaff15 | 0:66cd67db4f1b | 16 | this->fuzzySetOutputs = NULL; |
astaff15 | 0:66cd67db4f1b | 17 | this->fuzzySetOutputsCursor = NULL; |
astaff15 | 0:66cd67db4f1b | 18 | } |
astaff15 | 0:66cd67db4f1b | 19 | |
astaff15 | 0:66cd67db4f1b | 20 | // DESTRUTOR |
astaff15 | 0:66cd67db4f1b | 21 | FuzzyRuleConsequent::~FuzzyRuleConsequent(){ |
astaff15 | 0:66cd67db4f1b | 22 | this->cleanFuzzySets(this->fuzzySetOutputs); |
astaff15 | 0:66cd67db4f1b | 23 | } |
astaff15 | 0:66cd67db4f1b | 24 | |
astaff15 | 0:66cd67db4f1b | 25 | // MÉTODOS PÚBLICOS |
astaff15 | 0:66cd67db4f1b | 26 | bool FuzzyRuleConsequent::addOutput(FuzzySet* fuzzySet){ |
astaff15 | 0:66cd67db4f1b | 27 | fuzzySetOutputArray *aux; |
astaff15 | 0:66cd67db4f1b | 28 | // Alocando espaço na memória |
astaff15 | 0:66cd67db4f1b | 29 | if((aux = (fuzzySetOutputArray *) malloc(sizeof(fuzzySetOutputArray))) == NULL){ |
astaff15 | 0:66cd67db4f1b | 30 | return false; |
astaff15 | 0:66cd67db4f1b | 31 | } |
astaff15 | 0:66cd67db4f1b | 32 | aux->fuzzySet = fuzzySet; |
astaff15 | 0:66cd67db4f1b | 33 | aux->next = NULL; |
astaff15 | 0:66cd67db4f1b | 34 | |
astaff15 | 0:66cd67db4f1b | 35 | if(this->fuzzySetOutputs == NULL){ |
astaff15 | 0:66cd67db4f1b | 36 | this->fuzzySetOutputs = aux; |
astaff15 | 0:66cd67db4f1b | 37 | this->fuzzySetOutputsCursor = aux; |
astaff15 | 0:66cd67db4f1b | 38 | }else{ |
astaff15 | 0:66cd67db4f1b | 39 | this->fuzzySetOutputsCursor->next = aux; |
astaff15 | 0:66cd67db4f1b | 40 | this->fuzzySetOutputsCursor = aux; |
astaff15 | 0:66cd67db4f1b | 41 | } |
astaff15 | 0:66cd67db4f1b | 42 | return true; |
astaff15 | 0:66cd67db4f1b | 43 | } |
astaff15 | 0:66cd67db4f1b | 44 | |
astaff15 | 0:66cd67db4f1b | 45 | bool FuzzyRuleConsequent::evaluate(float power){ |
astaff15 | 0:66cd67db4f1b | 46 | fuzzySetOutputArray *aux; |
astaff15 | 0:66cd67db4f1b | 47 | aux = this->fuzzySetOutputs; |
astaff15 | 0:66cd67db4f1b | 48 | while(aux != NULL){ |
astaff15 | 0:66cd67db4f1b | 49 | aux->fuzzySet->setPertinence(power); |
astaff15 | 0:66cd67db4f1b | 50 | aux = aux->next; |
astaff15 | 0:66cd67db4f1b | 51 | } |
astaff15 | 0:66cd67db4f1b | 52 | return true; |
astaff15 | 0:66cd67db4f1b | 53 | } |
astaff15 | 0:66cd67db4f1b | 54 | |
astaff15 | 0:66cd67db4f1b | 55 | // MÉTODOS PRIVADOS |
astaff15 | 0:66cd67db4f1b | 56 | void FuzzyRuleConsequent::cleanFuzzySets(fuzzySetOutputArray* aux){ |
astaff15 | 0:66cd67db4f1b | 57 | if(aux != NULL){ |
astaff15 | 0:66cd67db4f1b | 58 | // Esvaziando a memória alocada |
astaff15 | 0:66cd67db4f1b | 59 | this->cleanFuzzySets(aux->next); |
astaff15 | 0:66cd67db4f1b | 60 | free(aux); |
astaff15 | 0:66cd67db4f1b | 61 | } |
astaff15 | 0:66cd67db4f1b | 62 | } |