//+------------------------------------------------------------------+ //| sugenofuzzysystem.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 "GenericFuzzySystem.mqh" #include "InferenceMethod.mqh" #include "RuleParser.mqh" #include "FuzzyRule.mqh" #include "SugenoVariable.mqh" //+------------------------------------------------------------------+ //| Purpose: Creating Sugeno fuzzy system | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Sugeno fuzzy inference system | //+------------------------------------------------------------------+ class CSugenoFuzzySystem : public CGenericFuzzySystem { private: CList *m_output; // List of Sugeno variable CList *m_rules; // List of Sugeno fuzzy rule public: CSugenoFuzzySystem(void); ~CSugenoFuzzySystem(void); //--- method gets the output linguistic variables CList* Output(void) { return(m_output); } //--- method gets the fuzzy rule CList* Rules(void) { return(m_rules); } //--- maethod gets the variable by name CSugenoVariable* OutputByName(const string name); //--- method create new linear function CLinearSugenoFunction* CreateSugenoFunction(const string name,CList *coeffs,const double constValue); CLinearSugenoFunction* CreateSugenoFunction(const string name,const double &coeffs[]); //--- method create a new rule CSugenoFuzzyRule* EmptyRule(void); //--- method for calculate result CSugenoFuzzyRule* ParseRule(const string rule); CList* EvaluateConditions(CList *fuzzifiedInput); CList* EvaluateFunctions(CList *inputValues); CList* CombineResult(CList *ruleWeights,CList *functionResults); CList* Calculate(CList *inputValues); }; //+------------------------------------------------------------------+ //| Constructor without parameters | //+------------------------------------------------------------------+ CSugenoFuzzySystem::CSugenoFuzzySystem(void) { m_output=new CList; m_rules=new CList; } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CSugenoFuzzySystem::~CSugenoFuzzySystem(void) { delete m_output; delete m_rules; } //+------------------------------------------------------------------+ //| Get the output variable of the system by name | //+------------------------------------------------------------------+ CSugenoVariable *CSugenoFuzzySystem::OutputByName(const string name) { for(int i=0; i