forked from alvesoaj/eFLL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFuzzyOutput.cpp
executable file
·185 lines (152 loc) · 6.04 KB
/
FuzzyOutput.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Robotic Research Group (RRG)
* State University of Piaui (UESPI), Brazil - Piauí - Teresina
*
* FuzzyOutput.cpp
*
* Author: Msc. Marvin Lemos <[email protected]>
* AJ Alves <[email protected]>
* Co authors: Douglas S. Kridi <[email protected]>
* Kannya Leal <[email protected]>
*/
#include "FuzzyOutput.h"
// CONSTRUTORES
FuzzyOutput::FuzzyOutput() : FuzzyIO(){
}
FuzzyOutput::FuzzyOutput(int index) : FuzzyIO(index){
}
// DESTRUTOR
FuzzyOutput::~FuzzyOutput(){
this->fuzzyComposition.empty();
}
// MÉTODOS PÚBLICOS
bool FuzzyOutput::truncate(){
// esvaziando a composição
this->fuzzyComposition.empty();
fuzzySetArray *aux;
aux = this->fuzzySets;
while(aux != NULL){
if(aux->fuzzySet->getPertinence() > 0.0){
if(this->fuzzyComposition.checkPoint(aux->fuzzySet->getPointA(), 0.0) == false){
this->fuzzyComposition.addPoint(aux->fuzzySet->getPointA(), 0.0);
}
if(aux->fuzzySet->getPointB() == aux->fuzzySet->getPointC() && aux->fuzzySet->getPointA() != aux->fuzzySet->getPointD()){
// se trinagulo
if(aux->fuzzySet->getPertinence() == 1.0){
if(this->fuzzyComposition.checkPoint(aux->fuzzySet->getPointB(), aux->fuzzySet->getPertinence()) == false){
this->fuzzyComposition.addPoint(aux->fuzzySet->getPointB(), aux->fuzzySet->getPertinence());
}
}else{
float newPointB = aux->fuzzySet->getPointB();
float newPertinenceB = aux->fuzzySet->getPertinence();
rebuild(aux->fuzzySet->getPointA(), 0.0, aux->fuzzySet->getPointB(), 1.0, aux->fuzzySet->getPointA(), aux->fuzzySet->getPertinence(), aux->fuzzySet->getPointD(), aux->fuzzySet->getPertinence(), &newPointB, &newPertinenceB);
if(this->fuzzyComposition.checkPoint(newPointB, newPertinenceB) == false){
this->fuzzyComposition.addPoint(newPointB, newPertinenceB);
}
float newPointC = aux->fuzzySet->getPointB();
float newPertinenceC = aux->fuzzySet->getPertinence();
rebuild(aux->fuzzySet->getPointC(), 1.0, aux->fuzzySet->getPointD(), 0.0, aux->fuzzySet->getPointA(), aux->fuzzySet->getPertinence(), aux->fuzzySet->getPointD(), aux->fuzzySet->getPertinence(), &newPointC, &newPertinenceC);
if(this->fuzzyComposition.checkPoint(newPointC, newPertinenceC) == false){
this->fuzzyComposition.addPoint(newPointC, newPertinenceC);
}
}
}else if(aux->fuzzySet->getPointB() != aux->fuzzySet->getPointC()){
// se trapezio
if(aux->fuzzySet->getPertinence() == 1.0){
if(this->fuzzyComposition.checkPoint(aux->fuzzySet->getPointB(), aux->fuzzySet->getPertinence()) == false){
this->fuzzyComposition.addPoint(aux->fuzzySet->getPointB(), aux->fuzzySet->getPertinence());
}
if(this->fuzzyComposition.checkPoint(aux->fuzzySet->getPointC(), aux->fuzzySet->getPertinence()) == false){
this->fuzzyComposition.addPoint(aux->fuzzySet->getPointC(), aux->fuzzySet->getPertinence());
}
}else{
float newPointB = aux->fuzzySet->getPointB();
float newPertinenceB = aux->fuzzySet->getPertinence();
rebuild(aux->fuzzySet->getPointA(), 0.0, aux->fuzzySet->getPointB(), 1.0, aux->fuzzySet->getPointA(), aux->fuzzySet->getPertinence(), aux->fuzzySet->getPointD(), aux->fuzzySet->getPertinence(), &newPointB, &newPertinenceB);
if(this->fuzzyComposition.checkPoint(newPointB, newPertinenceB) == false){
this->fuzzyComposition.addPoint(newPointB, newPertinenceB);
}
float newPointC = aux->fuzzySet->getPointB();
float newPertinenceC = aux->fuzzySet->getPertinence();
rebuild(aux->fuzzySet->getPointC(), 1.0, aux->fuzzySet->getPointD(), 0.0, aux->fuzzySet->getPointA(), aux->fuzzySet->getPertinence(), aux->fuzzySet->getPointD(), aux->fuzzySet->getPertinence(), &newPointC, &newPertinenceC);
if(this->fuzzyComposition.checkPoint(newPointC, newPertinenceC) == false){
this->fuzzyComposition.addPoint(newPointC, newPertinenceC);
}
}
}else{
//senao singleton
if(this->fuzzyComposition.checkPoint(aux->fuzzySet->getPointB(), aux->fuzzySet->getPertinence()) == false){
this->fuzzyComposition.addPoint(aux->fuzzySet->getPointB(), aux->fuzzySet->getPertinence());
}
}
if(this->fuzzyComposition.checkPoint(aux->fuzzySet->getPointD(), 0.0) == false || aux->fuzzySet->getPointD() == aux->fuzzySet->getPointA()){
this->fuzzyComposition.addPoint(aux->fuzzySet->getPointD(), 0.0);
}
}
aux = aux->next;
}
this->fuzzyComposition.build();
return true;
}
float FuzzyOutput::getCrispOutput(){
return this->fuzzyComposition.avaliate();
}
// Um simples Bubble Sort
bool FuzzyOutput::order(){
fuzzySetArray *aux1;
fuzzySetArray *aux2;
aux1 = this->fuzzySets;
aux2 = this->fuzzySets;
while(aux1 != NULL){
while(aux2 != NULL){
if(aux2->next != NULL){
if(aux2->fuzzySet->getPointA() > aux2->next->fuzzySet->getPointA()){
this->swap(aux2, aux2->next);
}
}
aux2 = aux2->next;
}
aux2 = this->fuzzySets;
aux1 = aux1->next;
}
return true;
}
// MÉTODOS PRIVADOS
bool FuzzyOutput::swap(fuzzySetArray* fuzzySetA, fuzzySetArray* fuzzySetB){
FuzzySet* aux;
aux = fuzzySetA->fuzzySet;
fuzzySetA->fuzzySet = fuzzySetB->fuzzySet;
fuzzySetB->fuzzySet = aux;
return true;
}
bool FuzzyOutput::rebuild(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float* point, float* pertinence){
float denom, numera, numerb;
float mua, mub;
denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
numera = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
numerb = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
if(denom < 0.0){
denom *= -1.0;
}
if(numera < 0.0){
numera *= -1.0;
}
if(numerb < 0.0){
numerb *= -1.0;
}
// Se os seguimentos forem paralelos, retornar falso
if(denom < EPS){
return false;
}
// Verificar se há interseção ao longo do seguimento
mua = numera / denom;
mub = numerb / denom;
if(mua < 0.0 || mua > 1.0 || mub < 0.0 || mub > 1.0){
return false;
}else{
// Calculando o ponto e a pertinencia do novo elemento
*point = x1 + mua * (x2 - x1);
*pertinence = y1 + mua * (y2 - y1);
return true;
}
}