//(to prevent divide by zero errors below)
if ( (isEqual(m_dRightOffset, 0.0) && (isEqual(m_dPeakPoint, val))) ||
(isEqual(m_dLeftOffset, 0.0) && (isEqual(m_dPeakPoint, val))) )
{
return 1.0;
}
//find DOM if left of center
if ( (val <= m_dPeakPoint) && (val >= (m_dPeakPoint - m_dLeftOffset)) )
{
double grad = 1.0 / m_dLeftOffset;
return grad * (val - (m_dPeakPoint - m_dLeftOffset));
}
//find DOM if right of center
else if ( (val > m_dPeakPoint) && (val < (m_dPeakPoint + m_dRightOffset)) )
{
double grad = 1.0 / -m_dRightOffset;
return grad * (val - m_dPeakPoint) + 1.0;
}
//out of range of this FLV, return zero
else
{
return 0.0;
}
}
The Right Shoulder Fuzzy Set Class
A right-shouldered fuzzy set is also parameterized by three values: a peak
point, a left offset, and a right offset. See Figure 10.25.
Once again the class definition is straightforward:
class FuzzySet_RightShoulder : public FuzzySet
{
private:
Fuzzy Logic
| 441
From Theory to Application: Coding a Fuzzy Logic Module
Figure 10.25. A right shoulder membership function
//the values that define the shape of this FLV
double m_dPeakPoint;
double m_dLeftOffset;
double m_dRightOffset;
public:
FuzzySet_RightShoulder(double peak,
double LeftOffset,
double RightOffset):
FuzzySet( ((peak + RightOffset) + peak) / 2),
m_dPeakPoint(peak),
m_dLeftOffset(LeftOffset),
m_dRightOffset(RightOffset)
{}
//this method calculates the degree of membership for a particular value
double CalculateDOM(double val)const;
};
This time the representative value is the midpoint of the plateau of the
shoulder.
The
CalculateDOM method is also slightly different.
double FuzzySet_RightShoulder::CalculateDOM(double val)const
{
//check for case where the offset may be zero
if (isEqual(0, m_dLeftOffset) && isEqual(val,m_dMidPoint))
{
return 1.0;
}
//find DOM if left of center
if ( (val <= m_dMidPoint) && (val > (m_dMidPoint - m_dLeftOffset)) )
{
double grad = 1.0 / m_dLeftOffset;
return grad * (val - (m_dMidPoint - m_dLeftOffset));
}
//find DOM if right of center
else if (val > m_dMidPoint)
{
return 1.0;
}
//out of range of this FLV, return zero
else
{
return 0.0;
}
}
442 | Chapter 10
From Theory to Application: Coding a Fuzzy Logic Module

Get Programming Game AI by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.