// // Defuzzification of center of gravity // // There can be many methods for defuzzification in a // fuzzy logic system. In Fuzz-C there are three macros // that must be defined for each Defuzzification method // supported. // // fv_DeFuzzMethod(@CONSNAME) Scratch variables that are needed. // // fi_DeFuzzMethod(@CONSNAME) Variable initialization. Called // from fuzzy function. // // fm_DeFuzzMethod Code to be executed each time a // consequence function is called // // fd_DeFuzzMethod Defuzz to Crisp routine called once // after all of the rules have been // executed. // // // For each consequence function the Fuzz-C preprocessor // can generate a crisp number for a specific degree of // membership and value for the area below the degree of // membership. // // @CONSPOINT // Single point crisp result // @CONSVOL // Volume under the degree of membership // // fv // Scratch variables int fa_@CONSNAME, fc_@CONSNAME; ;; fi // Variable initialization. Called from fuzzy function. fa_@CONSNAME = 0; fc_@CONSNAME = 0; ;; fm // Code to be executed each time a consequence function is called fc_@CONSNAME += @CONSVOL; fa_@CONSNAME += (@CONSVOL * (@CONSPOINT)); ;; fd // Defuzz to crisp routine called once after rules are executed. if (fc_@CONSNAME == 0) @CONSNAME = 0; else @CONSNAME = fa_@CONSNAME / fc_@CONSNAME; ;;