//Code automatically generated with fuzzylite 6.0.

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
