//+------------------------------------------------------------------+ //| sugenovariable.mqh | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ //| Implementation of Fuzzy library in MetaQuotes Language 5 | //| | //| The features of the library include: | //| - Create Mamdani fuzzy model | //| - Create Sugeno fuzzy model | //| - Normal membership function | //| - Triangular membership function | //| - Trapezoidal membership function | //| - Constant membership function | //| - Defuzzification method of center of gravity (COG) | //| - Defuzzification method of bisector of area (BOA) | //| - Defuzzification method of mean of maxima (MeOM) | //| | //| This file is free software; you can redistribute it and/or | //| modify it under the terms of the GNU General Public License as | //| published by the Free Software Foundation (www.fsf.org); either | //| version 2 of the License, or (at your option) any later version. | //| | //| This program is distributed in the hope that it will be useful, | //| but WITHOUT ANY WARRANTY; without even the implied warranty of | //| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | //| GNU General Public License for more details. | //+------------------------------------------------------------------+ #include #include "FuzzyVariable.mqh" #include "Dictionary.mqh" //+------------------------------------------------------------------+ //| Purpose: creating Sugeno variable. | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| The base class for Linear Sugeno Function | //+------------------------------------------------------------------+ class ISugenoFunction : public CNamedValueImpl { public: //--- method to check type virtual bool IsTypeOf(EnType type) { return(type==TYPE_CLASS_ISugenoFunction); } }; //+------------------------------------------------------------------+ //| Lenear function for Sugeno Fuzzy System | //+------------------------------------------------------------------+ class CLinearSugenoFunction : public ISugenoFunction { private: CList *m_input; // List of input variables CList *m_coeffs; // The dictionary which stores variables and their coefficients double m_const_value; // The constant term of the linear equation public: CLinearSugenoFunction(const string name,CList *in); CLinearSugenoFunction(const string name,CList *in,CList *coeffs,const double constValue); CLinearSugenoFunction(const string name,CList *in,const double &coeffs[]); ~CLinearSugenoFunction(void); //--- method to check type virtual bool IsTypeOf(EnType type) { return(type==TYPE_CLASS_LinearSugenoFunction); } //--- methods gets or sets constant coefficient double ConstValue() { return(m_const_value); } void ConstValue(const double value) { m_const_value=value; } //--- methods gets or sets coefficient by fuzzy variable double GetCoefficient(CFuzzyVariable *var); void SetCoefficient(CFuzzyVariable *var,const double coeff); //--- calculate double Evaluate(CList *inputValues); }; //+------------------------------------------------------------------+ //| First constructor with parameters | //+------------------------------------------------------------------+ CLinearSugenoFunction::CLinearSugenoFunction(const string name,CList *in) { m_coeffs=new CList; CNamedValueImpl::Name(name); m_input=in; } //+------------------------------------------------------------------+ //| Second constructor with parameters | //+------------------------------------------------------------------+ CLinearSugenoFunction::CLinearSugenoFunction(const string name,CList *in,CList *coeffs,const double constValue) { CNamedValueImpl::Name(name); m_input=in; //--- Check that all coeffecients are related to the variable from input for(int i=0; i