-
Notifications
You must be signed in to change notification settings - Fork 93
/
FuzzyRule.cpp
executable file
·56 lines (50 loc) · 1.68 KB
/
FuzzyRule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Robotic Research Group (RRG)
* State University of Piauí (UESPI), Brazil - Piauí - Teresina
*
* FuzzyOutput.cpp
*
* Author: AJ Alves <aj.alves@zerokol.com>
* Co authors: Dr. Ricardo Lira <ricardor_usp@yahoo.com.br>
* Msc. Marvin Lemos <marvinlemos@gmail.com>
* Douglas S. Kridi <douglaskridi@gmail.com>
* Kannya Leal <kannyal@hotmail.com>
*/
#include "FuzzyRule.h"
// CONTRUCTORS
FuzzyRule::FuzzyRule()
{
}
FuzzyRule::FuzzyRule(int index, FuzzyRuleAntecedent *fuzzyRuleAntecedent, FuzzyRuleConsequent *fuzzyRuleConsequent)
{
this->index = index;
this->fired = false;
this->fuzzyRuleAntecedent = fuzzyRuleAntecedent;
this->fuzzyRuleConsequent = fuzzyRuleConsequent;
}
// PUBLIC METHODS
// Method to get the value of index
int FuzzyRule::getIndex()
{
return this->index;
}
// Method to evaluate the total expression
bool FuzzyRule::evaluateExpression()
{
// check if the FuzzyRuleAntecedent and FuzzyRuleConsequent are valid
if (this->fuzzyRuleAntecedent != NULL && this->fuzzyRuleConsequent != NULL)
{
// call the evaluator in the FuzzyRuleAntecedent
float powerOfAntecedent = this->fuzzyRuleAntecedent->evaluate();
// if the power of FuzzyRuleAntecedent is bigget the 0.0, this rule was fired, else, no
(powerOfAntecedent > 0.0) ? (this->fired = true) : (this->fired = false);
// pass the power of FuzzyRuleAntecedent to FuzzyRuleConsequent by its evaluator
this->fuzzyRuleConsequent->evaluate(powerOfAntecedent);
}
return this->fired;
}
// Method to get the value of fired
bool FuzzyRule::isFired()
{
return this->fired;
}