summaryrefslogtreecommitdiff
path: root/examples/takagi-sugeno/octave/linear_tip_calculator.fcl
blob: d326b2e334da0a9ab536aa547ed9fbd83f348441 (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
FUNCTION_BLOCK Linear-Tip-Calculator

VAR_INPUT
  FoodQuality: REAL;
  Service: REAL;
END_VAR

VAR_OUTPUT
  Tip: REAL;
END_VAR

FUZZIFY FoodQuality
  RANGE := (1.000 .. 10.000);
  TERM Bad := Trapezoid 0.000 1.000 3.000 7.000;
  TERM Good := Trapezoid 3.000 7.000 10.000 11.000;
END_FUZZIFY

FUZZIFY Service
  RANGE := (1.000 .. 10.000);
  TERM Bad := Trapezoid 0.000 1.000 3.000 7.000;
  TERM Good := Trapezoid 3.000 7.000 10.000 11.000;
END_FUZZIFY

DEFUZZIFY Tip
  RANGE := (10.000 .. 20.000);
  TERM TenPercent := Linear 0.000 0.000 10.000;
  TERM FifteenPercent := Linear 0.000 0.000 15.000;
  TERM TwentyPercent := Linear 0.000 0.000 20.000;
  METHOD : COGS;
  DEFAULT := nan;
END_DEFUZZIFY

RULEBLOCK 
  AND : MIN;
  RULE 1 : if FoodQuality is Bad and Service is Bad then Tip is TenPercent
  RULE 2 : if FoodQuality is Bad and Service is Good then Tip is FifteenPercent
  RULE 3 : if FoodQuality is Good and Service is Bad then Tip is FifteenPercent
  RULE 4 : if FoodQuality is Good and Service is Good then Tip is TwentyPercent
END_RULEBLOCK

END_FUNCTION_BLOCK