1 /* 2 fuzzylite (R), a fuzzy logic control library in C++. 3 Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved. 4 Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com> 5 6 This file is part of fuzzylite. 7 8 fuzzylite is free software: you can redistribute it and/or modify it under 9 the terms of the FuzzyLite License included with the software. 10 11 You should have received a copy of the FuzzyLite License along with 12 fuzzylite. If not, see <http://www.fuzzylite.com/license/>. 13 14 fuzzylite is a registered trademark of FuzzyLite Limited. 15 */ 16 17 #include "fl/activation/General.h" 18 19 #include "fl/rule/RuleBlock.h" 20 #include "fl/rule/Rule.h" 21 #include "fl/Operation.h" 22 23 namespace fl { 24 General()25 General::General() : Activation() { } 26 ~General()27 General::~General() { } 28 className() const29 std::string General::className() const { 30 return "General"; 31 } 32 parameters() const33 std::string General::parameters() const { 34 return ""; 35 } 36 configure(const std::string & parameters)37 void General::configure(const std::string& parameters) { 38 FL_IUNUSED(parameters); 39 } 40 complexity(const RuleBlock * ruleBlock) const41 Complexity General::complexity(const RuleBlock* ruleBlock) const { 42 Complexity result; 43 for (std::size_t i = 0; i < ruleBlock->numberOfRules(); ++i) { 44 result.comparison(1); 45 result += ruleBlock->getRule(i)->complexity( 46 ruleBlock->getConjunction(), ruleBlock->getDisjunction(), 47 ruleBlock->getImplication()); 48 } 49 return result; 50 } 51 activate(RuleBlock * ruleBlock)52 void General::activate(RuleBlock* ruleBlock) { 53 FL_DBG("Activation: " << className() << " " << parameters()); 54 const TNorm* conjunction = ruleBlock->getConjunction(); 55 const SNorm* disjunction = ruleBlock->getDisjunction(); 56 const TNorm* implication = ruleBlock->getImplication(); 57 58 const std::size_t numberOfRules = ruleBlock->numberOfRules(); 59 for (std::size_t i = 0; i < numberOfRules; ++i) { 60 Rule* rule = ruleBlock->getRule(i); 61 rule->deactivate(); 62 if (rule->isLoaded()) { 63 rule->activateWith(conjunction, disjunction); 64 rule->trigger(implication); 65 } 66 } 67 } 68 clone() const69 General* General::clone() const { 70 return new General(*this); 71 } 72 constructor()73 Activation* General::constructor() { 74 return new General; 75 } 76 77 } 78