-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSource.cpp
More file actions
77 lines (63 loc) · 1.26 KB
/
Source.cpp
File metadata and controls
77 lines (63 loc) · 1.26 KB
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
#include "Header.h"
Memebership::Memebership(double a, double b, double c, double d, string l)
{
this->a = a;
this->b = b;
this->c = c;
this->d = d;
label = l;
}
double Memebership::getMembershipValue(double x)
{
//leftShoulder
if (a== b)
{
if (x < c)return 1;
else if (x > c &&x < d)return (d - x) / (d - b);
}
//rightSHoudler
if (b == d)
{
if (x > b) return 1;
else if (x <b&&x>a)
{
return (d-x)/(d-b);
}
}
//triangle
if (b == c)
{
if (x > b)return x-a/b-a;
else if (x > b)return d - x / d - b;
}
//Trapeziod
else {
if (x > b && x < c) {
return 1;
}
else if (x < b && x > a) {
return (x - a) / (b - a);
;
}
else if (x > c && x < d) {
return (d - x / (d - c));
}
}
return 0;
}
Rule::Rule(Memebership*lfs, Memebership*lbs, Memebership*lv, Memebership *rv)
{
leftFrontSensor = lfs;
leftBackSensor = lbs;
leftVelocity = lv;
rightVelocity = rv;
}
double Rule::calcFiringStrength(double frontReading, double backReading)
{
double firingStrength = leftFrontSensor->getMembershipValue(frontReading)*leftBackSensor->getMembershipValue(backReading);
return firingStrength;
}
double Memebership::getCentriod()
{
return d+a/ 2;
}