//Code automatically generated with fuzzylite 6.0.

FUNCTION_BLOCK mamdani_tip_calculator

VAR_INPUT
  FoodQuality: REAL;
  Service: REAL;
END_VAR

VAR_OUTPUT
  Tip: REAL;
  CheckPlusTip: 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 := (0.000 .. 30.000);
  TERM AboutTenPercent := Gaussian 10.000 2.000;
  TERM AboutFifteenPercent := Gaussian 15.000 2.000;
  TERM AboutTwentyPercent := Gaussian 20.000 2.000;
  METHOD : COG;
  ACCU : ASUM;
  DEFAULT := nan;
END_DEFUZZIFY

DEFUZZIFY CheckPlusTip
  RANGE := (1.000 .. 1.300);
  TERM PlusAboutTenPercent := Gaussian 1.100 0.020;
  TERM PlusAboutFifteenPercent := Gaussian 1.150 0.020;
  TERM PlusAboutTwentyPercent := Gaussian 1.200 0.020;
  METHOD : COG;
  ACCU : ASUM;
  DEFAULT := nan;
END_DEFUZZIFY

RULEBLOCK 
  AND : PROD;
  OR : MAX;
  ACT : MIN;
  RULE 1 : if FoodQuality is Bad and Service is Bad then Tip is AboutTenPercent and CheckPlusTip is PlusAboutTenPercent
  RULE 2 : if FoodQuality is Bad and Service is Good then Tip is AboutFifteenPercent and CheckPlusTip is PlusAboutFifteenPercent
  RULE 3 : if FoodQuality is Good and Service is Bad then Tip is AboutFifteenPercent and CheckPlusTip is PlusAboutFifteenPercent
  RULE 4 : if FoodQuality is Good and Service is Good then Tip is AboutTwentyPercent and CheckPlusTip is PlusAboutTwentyPercent
END_RULEBLOCK

END_FUNCTION_BLOCK
