I’ve only recently jumped into the world of iphone development and objective-c, so I’m still a bit lost as to how I might implement something like this.
I have a float, and I have a list of ranges that float can fall within and the corresponding value I should return, eg:
10.0 - 14.5 : 1.0
14.5 - 17.0 : 2.0
17.0 - 23.0 : 2.5
23.0 - 32.4 : 4.0
So if my float is, say, 15.12, I want to return 2.0.
The part that makes this tricky is that the range list is quite long, and I have several such range lists that I need to choose from, any of which might need to be changed later. Simply writing a few hundred or thousand if statements seems like an ugly solution to say the least.
Essentially what you are describing is Fuzzy Logic.
I wrote you a fuzzy logic rules class which should handle what you are wanting to do.
Features:
methodand get a string result (ornilif it matches no rules).Add a new rule:
Sample output (from the code below):
Here is the code implementation…..
In your Main:
FuzzyLogic.h:
FuzzyLogic.m: