-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathFuzzySet.cpp
executable file
·132 lines (121 loc) · 3.3 KB
/
FuzzySet.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Robotic Research Group (RRG)
* State University of Piauí (UESPI), Brazil - Piauí - Teresina
*
* FuzzySet.cpp
*
* Author: AJ Alves <[email protected]>
* Co authors: Dr. Ricardo Lira <[email protected]>
* Msc. Marvin Lemos <[email protected]>
* Douglas S. Kridi <[email protected]>
* Kannya Leal <[email protected]>
*/
#include "FuzzySet.h"
// CONTRUCTORS
FuzzySet::FuzzySet()
{
}
FuzzySet::FuzzySet(float a, float b, float c, float d)
{
this->a = a;
this->b = b;
this->c = c;
this->d = d;
this->pertinence = 0.0;
}
// PUBLIC METHODS
// Method to get the value of point A
float FuzzySet::getPointA()
{
return this->a;
}
// Method to get the value of point B
float FuzzySet::getPointB()
{
return this->b;
}
// Method to get the value of point C
float FuzzySet::getPointC()
{
return this->c;
}
// Method to get the value of point D
float FuzzySet::getPointD()
{
return this->d;
}
// Method to calculate the pertinence of the FuzzySet, according with the crispValue
bool FuzzySet::calculatePertinence(float crispValue)
{
// check the crispValue is small then A
if (crispValue < this->a)
{
// check if this FuzzySet represents "everithing small is true"
if (this->a == this->b && this->b != this->c && this->c != this->d)
{
// if so, the pertinence is 1
this->pertinence = 1.0;
}
else
{
// else, pertinence is 0
this->pertinence = 0.0;
}
}
// check if the crispValue is between A and B
else if (crispValue >= this->a && crispValue < this->b)
{
// calculate a slope
float slope = 1.0 / (this->b - this->a);
// calculate the value of pertinence
this->pertinence = slope * (crispValue - this->b) + 1.0;
}
// check if the pertinence is between B and C
else if (crispValue >= this->b && crispValue <= this->c)
{
this->pertinence = 1.0;
}
// check if the pertinence is between C and D
else if (crispValue > this->c && crispValue <= this->d)
{
// calculate a slope
float slope = 1.0 / (this->c - this->d);
// calculate the value of pertinence
this->pertinence = slope * (crispValue - this->c) + 1.0;
}
// check the crispValue is bigger then D
else if (crispValue > this->d)
{
// check if this FuzzySet represents "everithing bigger is true"
if (this->c == this->d && this->c != this->b && this->b != this->a)
{
// if so, the pertinence is 1
this->pertinence = 1.0;
}
else
{
// else, pertinence is 0
this->pertinence = 0.0;
}
}
return true;
}
// Method to set the value of pertinence
void FuzzySet::setPertinence(float pertinence)
{
// check if the new pertinence is bigger then the current value because it can be called more then once by different FuzzyRuleConsequent
if (this->pertinence < pertinence)
{
this->pertinence = pertinence;
}
}
// Method to get the value of pertinence
float FuzzySet::getPertinence()
{
return this->pertinence;
}
// Method to reset the value of pertinence
void FuzzySet::reset()
{
this->pertinence = 0.0;
}