home Forums # Technical Support Mamdani or Larsen

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1094
    Avatarmcanonic
    Participant

    Hi,
    I’m wondering which method I’m using in my controller by using fuzzylite.

    I’ve used the example proposed an I have made my own model (see below for source code) where the rules are added by this kind of instruction:

    block->addRule(new fl::MamdaniRule(“if Cres is FINE and Rgain is LOW then Cvar is UP”, engine));

    Is this enough to say that, with fuzzylite, I’m using Mamdani max-min?

    How can I use Larsen method (if it is possible)?

    M

    
    #include "fzyCtrlModel.h"
    //#include <fuzzylite/FuzzyLite.h>
    //#include <fuzzylite/FunctionTerm.h>
    #include <fl/fuzzylite.h>
    #include <fl/term/Term.h>
    #include <limits>
    #include <fstream>
    
    using namespace std;
    
    namespace fl {
    void fzyCtrlModel::webServerCtrl(double RgainScalar, double CresScalar, double* CvarScalar, double x, double y) {
    
    	fl::Engine* engine = new fl::Engine("webserver");
           
    	fl::InputVariable* Cres = new fl::InputVariable;
    	Cres->setName("Cres");
     	Cres->setRange(0.0, 1.0);
    	
    	Cres->addTerm(new fl::Ramp("LOW", 0.15, 0.1));
     	Cres->addTerm(new fl::Triangle("FINE", 0.10, 0.15, 0.20));
     	Cres->addTerm(new fl::Ramp("HIGH", 0.15, 0.20));
     	engine->addInputVariable(Cres);
    
    	//*****************SECOND INPUT VALUE************************
    	fl::InputVariable* Rgain = new fl::InputVariable;
    	Rgain->setName("Rgain");
     	Rgain->setRange(0.0, 1.0);
    	
    	Rgain->addTerm(new fl::Ramp("LOW", 0.15, x));
     	Rgain->addTerm(new fl::Triangle("FINE", 0.10, 0.15, 0.20));
     	Rgain->addTerm(new fl::Ramp("HIGH", 0.15, y));
     	engine->addInputVariable(Rgain);
    
    	//*****************OUTPUT VALUE************************
    	fl::OutputVariable* Cvar = new fl::OutputVariable;
    	Cvar->setName("Cvar");
     	Cvar->setRange(-0.30, 0.30);
     	Cvar->setDefaultValue(0);
    
    	Cvar->addTerm(new fl::Ramp("BDW", -0.10, -0.2));
    	Cvar->addTerm(new fl::Triangle("DWN", -0.20, -0.1, -0.05));
    	Cvar->addTerm(new fl::Triangle("STY", -0.10, 0, 0.10));
    	Cvar->addTerm(new fl::Triangle("UP", 0.05, 0.1, 0.20));
    	Cvar->addTerm(new fl::Ramp("BUP", 0.1, 0.20));
    
            engine->addOutputVariable(Cvar);
    	
    	//***********************RULES*************************
    	fl::RuleBlock* ruleblock = new fl::RuleBlock;
    
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is LOW and Rgain is LOW then Cvar is BUP", engine));	
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is LOW and Rgain is FINE then Cvar is UP", engine));	
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is LOW and Rgain is HIGH then Cvar is STY", engine));	
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is FINE and Rgain is LOW then Cvar is UP", engine));	
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is FINE and Rgain is FINE then Cvar is STY", engine));	
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is FINE and Rgain is HIGH then Cvar is DWN", engine));	
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is HIGH and Rgain is LOW then Cvar is STY", engine));	
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is HIGH and Rgain is FINE then Cvar is DWN", engine));	
    	ruleblock->addRule(fl::MamdaniRule::parse("if Cres is HIGH and Rgain is HIGH then Cvar is BDW", engine));	
    
            engine->addRuleBlock(ruleblock);
    
    	engine->configure("Minimum", "Maximum", "AlgebraicProduct", "AlgebraicSum", "Centroid");
    	
    	fl::scalar inputCres=CresScalar;
    	fl::scalar inputRgain=RgainScalar;
    
    	//set input
    	Cres->setInput(inputCres);
    	Rgain->setInput(inputRgain);
    
           	engine->process();
    
     	//fl::scalar outputCvar = Cvar->output().defuzzify();
     	fl::scalar outputCvar = Cvar->defuzzify();
    
           	//(void)outMaxClient; //Just to avoid warning when building
           	//(void)outputCvar; //Just to avoid warning when building
    			
        	//FL_LOG("Cres\tRgain\t ---> Cvar");
           	//cout<<"Cres\tRgain\t ---> Cvar"<<endl;
    
           	//FL_LOG(inputCres<<"\t"<<inputRgain<<"\t ---> "<< outputCvar);
           	//cout<<inputCres<<"\t"<<inputRgain<<"\t ---> "<< outputCvar<<endl;
    
    	(*CvarScalar)=outputCvar;
    
    	ofstream fzyLogFile;
    	fzyLogFile.open("fzy.log",ios::app);
    
    	/*	
     	cout<<"---------VERBOSE FUZZY ----------"<<endl;
    	cout<<"Cres = " << inputCres<<endl;
      	cout<<"\tCres is " << Cres->fuzzify(inputCres)<<endl;
    
    	cout<<"Rgain = " << inputRgain<<endl;
     	cout<<"\tRgain is " << Rgain->fuzzify(inputRgain)<<endl;
    
     	cout<<"Cvar = " << outputCvar<<endl;
          	cout<<"\tCvar is " << Cvar->fuzzify(outputCvar)<<endl;
           	cout<<"----------------------------------"<<endl; 
    	*/
    
    	fzyLogFile<<"Cres = " << inputCres<<endl;
      	fzyLogFile<<"\tCres is " << Cres->fuzzify(inputCres)<<endl;
    
    	fzyLogFile<<"Rgain = " << inputRgain<<endl;
     	fzyLogFile<<"\tRgain is " << Rgain->fuzzify(inputRgain)<<endl;
    
     	fzyLogFile<<"Cvar = " << outputCvar<<endl;
          	fzyLogFile<<"\tCvar is " << Cvar->fuzzify(outputCvar)<<endl;
           	fzyLogFile<<"----------------------------------"<<endl; 
    
    	fzyLogFile.close();
    }
    }
    
    #1097

    Hi Massimo,

    The Larsen controller is just like a Mamdani but the Activation operator is the Algebraic Product.

    Cheers,

    Juan

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.