summaryrefslogtreecommitdiff
path: root/examples/hybrid/tipper.fcl
blob: 299dbb88472c8f48fd5ed94615b47412a798ba5e (plain)
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
//Code automatically generated with fuzzylite 6.0.

FUNCTION_BLOCK tipper

VAR_INPUT
  service: REAL;
  food: REAL;
END_VAR

VAR_OUTPUT
  mTip: REAL;
  tsTip: REAL;
END_VAR

FUZZIFY service
  RANGE := (0.000 .. 10.000);
  TERM poor := Trapezoid 0.000 0.000 2.500 5.000;
  TERM good := Triangle 2.500 5.000 7.500;
  TERM excellent := Trapezoid 5.000 7.500 10.000 10.000;
END_FUZZIFY

FUZZIFY food
  RANGE := (0.000 .. 10.000);
  TERM rancid := Trapezoid 0.000 0.000 2.500 7.500;
  TERM delicious := Trapezoid 2.500 7.500 10.000 10.000;
END_FUZZIFY

DEFUZZIFY mTip
  RANGE := (0.000 .. 30.000);
  TERM cheap := Triangle 0.000 5.000 10.000;
  TERM average := Triangle 10.000 15.000 20.000;
  TERM generous := Triangle 20.000 25.000 30.000;
  METHOD : COG;
  ACCU : MAX;
  DEFAULT := nan;
END_DEFUZZIFY

DEFUZZIFY tsTip
  RANGE := (0.000 .. 30.000);
  TERM cheap := 5.000;
  TERM average := 15.000;
  TERM generous := 25.000;
  METHOD : COGS;
  DEFAULT := nan;
END_DEFUZZIFY

RULEBLOCK mamdani
  AND : PROD;
  OR : ASUM;
  ACT : MIN;
  RULE 1 : if service is poor or food is rancid then mTip is cheap
  RULE 2 : if service is good then mTip is average
  RULE 3 : if service is excellent or food is delicious then mTip is generous with 0.5
  RULE 4 : if service is excellent and food is delicious then mTip is generous with 1.0
END_RULEBLOCK

RULEBLOCK takagiSugeno
  AND : PROD;
  OR : ASUM;
  RULE 1 : if service is poor or food is rancid then tsTip is cheap
  RULE 2 : if service is good then tsTip is average
  RULE 3 : if service is excellent or food is delicious then tsTip is generous with 0.5
  RULE 4 : if service is excellent and food is delicious then tsTip is generous with 1.0
END_RULEBLOCK

END_FUNCTION_BLOCK