Fuzzy logic algorithm