| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
fuzzy Class DescriptionI created a small class called fuzzy to encompass the basics of fuzzy logic. To read about fuzzy logic, read the Generation5 essay on it.
Class HeaderThe class header file is as follows:
// These are only defined here to avoid conflict
// with Microsoft Windows libraries and the STL.
#define fuzmin(a, b) (((a) < (b)) ? (a) : (b))
#define fuzmax(a, b) (((a) > (b)) ? (a) : (b))
class fuzzy {
public:
fuzzy() {};
fuzzy(float f) : m_fNum(f) {}
fuzzy operator|(float f)
{ return fuzzy(fuzmax(m_fNum, f)); }
fuzzy operator&(float f)
{ return fuzzy(fuzmin(m_fNum, f)); }
fuzzy operator!() { return fuzzy(1 - m_fNum); }
fuzzy operator+(float f) { return fuzzy(m_fNum+f); }
fuzzy operator-(float f) { return fuzzy(m_fNum-f); }
fuzzy operator*(float f) { return fuzzy(m_fNum*f); }
fuzzy operator/(float f) { return fuzzy(m_fNum/f); }
void operator|=(float f)
{ m_fNum = fuzmax(m_fNum, f); }
void operator&=(float f)
{ m_fNum = fuzmin(m_fNum, f); }
operator float() { return m_fNum; }
bool contained(float f) { return (m_fNum <= f); }
protected:
float m_fNum;
};
To clarify the comments for the min and max macros. The Windows SDK defines a min and max that will clash with the STL versions of the the function. Therefore, Microsoft supply other macros to use instead, but since portability was an issue when I programmed this, I created my own macros.
BreakdownThe class is very simple, with all the functions being inline in the header file. Note that the operators that return type fuzzy do so so that other fuzzy operations can be performed upon the result. The operator float() will provide the necessary assignment operator to convert from a fuzzy to a float. Its perhaps overly-complicated, and not the most efficient way - but it works.
Submitted: 20/12/1999 Article content copyright © James Matthews, 1999.
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -