//Code automatically generated with fuzzylite 6.0.

FUNCTION_BLOCK sugeno_tip_calculator

VAR_INPUT
  FoodQuality: REAL;
  Service: REAL;
END_VAR

VAR_OUTPUT
  CheapTip: REAL;
  AverageTip: REAL;
  GenerousTip: 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 CheapTip
  RANGE := (5.000 .. 25.000);
  TERM Low := 10.000;
  TERM Medium := 15.000;
  TERM High := 20.000;
  METHOD : COGS;
  DEFAULT := nan;
END_DEFUZZIFY

DEFUZZIFY AverageTip
  RANGE := (5.000 .. 25.000);
  TERM Low := 10.000;
  TERM Medium := 15.000;
  TERM High := 20.000;
  METHOD : COGS;
  DEFAULT := nan;
END_DEFUZZIFY

DEFUZZIFY GenerousTip
  RANGE := (5.000 .. 25.000);
  TERM Low := 10.000;
  TERM Medium := 15.000;
  TERM High := 20.000;
  METHOD : COGS;
  DEFAULT := nan;
END_DEFUZZIFY

RULEBLOCK 
  AND : EPROD;
  RULE 1 : if FoodQuality is extremely Bad and Service is extremely Bad then CheapTip is extremely Low and AverageTip is very Low and GenerousTip is Low
  RULE 2 : if FoodQuality is Good and Service is extremely Bad then CheapTip is Low and AverageTip is Low and GenerousTip is Medium
  RULE 3 : if FoodQuality is very Good and Service is very Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is High
  RULE 4 : if FoodQuality is Bad and Service is Bad then CheapTip is Low and AverageTip is Low and GenerousTip is Medium
  RULE 5 : if FoodQuality is Good and Service is Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is High
  RULE 6 : if FoodQuality is extremely Good and Service is Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is very High
  RULE 7 : if FoodQuality is Bad and Service is Good then CheapTip is Low and AverageTip is Medium and GenerousTip is High
  RULE 8 : if FoodQuality is Good and Service is Good then CheapTip is Medium and AverageTip is Medium and GenerousTip is very High
  RULE 9 : if FoodQuality is very Bad and Service is very Good then CheapTip is Low and AverageTip is Medium and GenerousTip is High
  RULE 10 : if FoodQuality is very very Good and Service is very very Good then CheapTip is High and AverageTip is very High and GenerousTip is extremely High
END_RULEBLOCK

END_FUNCTION_BLOCK
