diff options
Diffstat (limited to 'fuzzylite/fl/rule')
-rw-r--r-- | fuzzylite/fl/rule/Antecedent.h | 77 | ||||
-rw-r--r-- | fuzzylite/fl/rule/Consequent.h | 68 | ||||
-rw-r--r-- | fuzzylite/fl/rule/Expression.h | 84 | ||||
-rw-r--r-- | fuzzylite/fl/rule/Rule.h | 121 | ||||
-rw-r--r-- | fuzzylite/fl/rule/RuleBlock.h | 97 |
5 files changed, 447 insertions, 0 deletions
diff --git a/fuzzylite/fl/rule/Antecedent.h b/fuzzylite/fl/rule/Antecedent.h new file mode 100644 index 0000000..02724e5 --- /dev/null +++ b/fuzzylite/fl/rule/Antecedent.h @@ -0,0 +1,77 @@ +/* + Author: Juan Rada-Vilela, Ph.D. + Copyright (C) 2010-2014 FuzzyLite Limited + All rights reserved + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + fuzzylite 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 Lesser General Public License + for more details. + + You should have received a copy of the GNU Lesser General Public License + along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. + + fuzzylite™ is a trademark of FuzzyLite Limited. + + */ + +#ifndef FL_ANTECEDENT_H +#define FL_ANTECEDENT_H + +#include "fl/fuzzylite.h" + +#include <string> + +namespace fl { + class Engine; + class Rule; + class TNorm; + class SNorm; + class Expression; + + class FL_API Antecedent { + protected: + std::string _text; + Expression* _expression; + + public: + Antecedent(); + virtual ~Antecedent(); + + virtual void setText(const std::string& text); + virtual std::string getText() const; + + virtual Expression* getExpression() const; + + virtual bool isLoaded() const; + + virtual void unload(); + virtual void load(Rule* rule, const Engine* engine); + virtual void load(const std::string& antecedent, Rule* rule, const Engine* engine); + + virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction, + const Expression* node) const; + + virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction) const; + + virtual std::string toString() const; + + virtual std::string toPrefix(const Expression* node = fl::null) const; + virtual std::string toInfix(const Expression* node = fl::null) const; + virtual std::string toPostfix(const Expression* node = fl::null) const; + + + private: + FL_DISABLE_COPY(Antecedent) + }; + +} + +#endif /* FL_ANTECEDENT_H */ diff --git a/fuzzylite/fl/rule/Consequent.h b/fuzzylite/fl/rule/Consequent.h new file mode 100644 index 0000000..5394dc0 --- /dev/null +++ b/fuzzylite/fl/rule/Consequent.h @@ -0,0 +1,68 @@ +/* + Author: Juan Rada-Vilela, Ph.D. + Copyright (C) 2010-2014 FuzzyLite Limited + All rights reserved + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + fuzzylite 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 Lesser General Public License + for more details. + + You should have received a copy of the GNU Lesser General Public License + along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. + + fuzzylite™ is a trademark of FuzzyLite Limited. + + */ + +#ifndef FL_CONSEQUENT_H +#define FL_CONSEQUENT_H + +#include "fl/fuzzylite.h" + +#include <string> +#include <vector> + +namespace fl { + class Engine; + class Rule; + class Proposition; + class TNorm; + + class FL_API Consequent { + protected: + std::string _text; + std::vector<Proposition*> _conclusions; + + public: + Consequent(); + virtual ~Consequent(); + + virtual void setText(const std::string& text); + virtual std::string getText() const; + + virtual const std::vector<Proposition*>& conclusions() const; + + virtual bool isLoaded(); + virtual void unload(); + virtual void load(Rule* rule, const Engine* engine); + virtual void load(const std::string& consequent, Rule* rule, const Engine* engine); + + virtual void modify(scalar activationDegree, const TNorm* activation); + + virtual std::string toString() const; + + private: + FL_DISABLE_COPY(Consequent) + }; + +} + +#endif /* FL_CONSEQUENT_H */ diff --git a/fuzzylite/fl/rule/Expression.h b/fuzzylite/fl/rule/Expression.h new file mode 100644 index 0000000..cb48355 --- /dev/null +++ b/fuzzylite/fl/rule/Expression.h @@ -0,0 +1,84 @@ +/* + Author: Juan Rada-Vilela, Ph.D. + Copyright (C) 2010-2014 FuzzyLite Limited + All rights reserved + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + fuzzylite 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 Lesser General Public License + for more details. + + You should have received a copy of the GNU Lesser General Public License + along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. + + fuzzylite™ is a trademark of FuzzyLite Limited. + + */ + +#ifndef FL_EXPRESSION_H +#define FL_EXPRESSION_H + +#include "fl/fuzzylite.h" + +#include <string> +#include <vector> + + + +namespace fl { + class Variable; + class Hedge; + class Term; + + class FL_API Expression { + public: + + Expression(); + virtual ~Expression(); + + virtual std::string toString() const = 0; + + private: + FL_DISABLE_COPY(Expression) + }; + + class FL_API Proposition : public Expression { + public: + Variable* variable; + std::vector<Hedge*> hedges; + Term* term; + + Proposition(); + virtual ~Proposition() FL_IOVERRIDE; + + virtual std::string toString() const FL_IOVERRIDE; + + private: + FL_DISABLE_COPY(Proposition) + }; + + class FL_API Operator : public Expression { + public: + std::string name; + Expression* left; + Expression* right; + + Operator(); + virtual ~Operator() FL_IOVERRIDE; + + virtual std::string toString() const FL_IOVERRIDE; + + private: + FL_DISABLE_COPY(Operator) + + }; + +} +#endif /* FL_FUZZYEXPRESSION_H */ diff --git a/fuzzylite/fl/rule/Rule.h b/fuzzylite/fl/rule/Rule.h new file mode 100644 index 0000000..20d39fb --- /dev/null +++ b/fuzzylite/fl/rule/Rule.h @@ -0,0 +1,121 @@ +/* + Author: Juan Rada-Vilela, Ph.D. + Copyright (C) 2010-2014 FuzzyLite Limited + All rights reserved + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + fuzzylite 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 Lesser General Public License + for more details. + + You should have received a copy of the GNU Lesser General Public License + along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. + + fuzzylite™ is a trademark of FuzzyLite Limited. + + */ + +#ifndef FL_RULE_H +#define FL_RULE_H + +#include "fl/fuzzylite.h" + +#include <map> +#include <string> + + +namespace fl { + class Engine; + class Antecedent; + class Consequent; + class Hedge; + class TNorm; + class SNorm; + + class FL_API Rule { + protected: + std::string _text; + scalar _weight; + FL_unique_ptr<Antecedent> _antecedent; + FL_unique_ptr<Consequent> _consequent; + std::map<std::string, Hedge*> _hedges; + + public: + explicit Rule(const std::string& text = "", scalar weight = 1.0); + Rule(const Rule& other); + Rule& operator=(const Rule& other); + virtual ~Rule(); + FL_DEFAULT_MOVE(Rule) + + virtual void setText(const std::string& text); + virtual std::string getText() const; + + virtual void setWeight(scalar weight); + virtual scalar getWeight() const; + + virtual void setAntecedent(Antecedent* antecedent); + virtual Antecedent* getAntecedent() const; + + virtual void setConsequent(Consequent* consequent); + virtual Consequent* getConsequent() const; + + virtual void addHedge(Hedge* hedge); + virtual Hedge* getHedge(const std::string& name) const; + virtual Hedge* removeHedge(const std::string& hedge); + virtual bool hasHedge(const std::string& name) const; + virtual int numberOfHedges() const; + virtual void setHedges(const std::map<std::string, Hedge*>& hedges); + virtual const std::map<std::string, Hedge*>& hedges() const; + virtual std::map<std::string, Hedge*>& hedges(); + + virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction) const; + virtual void activate(scalar degree, const TNorm* activation) const; + + virtual std::string toString() const; + + virtual bool isLoaded() const; + virtual void unload(); + virtual void load(const Engine* engine); + virtual void load(const std::string& rule, const Engine* engine); + + virtual Rule* clone() const; + + static Rule* parse(const std::string& rule, const Engine* engine); + + static std::string ifKeyword() { + return "if"; + } + + static std::string isKeyword() { + return "is"; + } + + static std::string thenKeyword() { + return "then"; + } + + static std::string andKeyword() { + return "and"; + } + + static std::string orKeyword() { + return "or"; + } + + static std::string withKeyword() { + return "with"; + } + + }; + +} + + +#endif /* FL_RULE_H */ diff --git a/fuzzylite/fl/rule/RuleBlock.h b/fuzzylite/fl/rule/RuleBlock.h new file mode 100644 index 0000000..35fe62e --- /dev/null +++ b/fuzzylite/fl/rule/RuleBlock.h @@ -0,0 +1,97 @@ +/* + Author: Juan Rada-Vilela, Ph.D. + Copyright (C) 2010-2014 FuzzyLite Limited + All rights reserved + + This file is part of fuzzylite. + + fuzzylite is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + fuzzylite 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 Lesser General Public License + for more details. + + You should have received a copy of the GNU Lesser General Public License + along with fuzzylite. If not, see <http://www.gnu.org/licenses/>. + + fuzzylite™ is a trademark of FuzzyLite Limited. + + */ + +#ifndef FL_RULEBLOCK_H +#define FL_RULEBLOCK_H + +#include "fl/fuzzylite.h" + +#include <string> +#include <vector> + + +namespace fl { + + class Engine; + class Rule; + class TNorm; + class SNorm; + + class FL_API RuleBlock { + private: + void copyFrom(const RuleBlock& source); + protected: + std::string _name; + std::vector<Rule*> _rules; + FL_unique_ptr<TNorm> _conjunction; + FL_unique_ptr<SNorm> _disjunction; + FL_unique_ptr<TNorm> _activation; + bool _enabled; + + public: + explicit RuleBlock(const std::string& name = ""); + RuleBlock(const RuleBlock& other); + RuleBlock& operator=(const RuleBlock& other); + virtual ~RuleBlock(); + FL_DEFAULT_MOVE(RuleBlock) + + virtual void activate(); + + virtual void setName(std::string name); + virtual std::string getName() const; + + virtual void setConjunction(TNorm* conjunction); + virtual TNorm* getConjunction() const; + + virtual void setDisjunction(SNorm* disjunction); + virtual SNorm* getDisjunction() const; + + virtual void setActivation(TNorm* activation); + virtual TNorm* getActivation() const; + + virtual void setEnabled(bool enabled); + virtual bool isEnabled() const; + + virtual void unloadRules() const; + virtual void loadRules(const Engine* engine); + virtual void reloadRules(const Engine* engine); + + virtual std::string toString() const; + + /** + * Operations for iterable datatype _rules + */ + virtual void addRule(Rule* rule); + virtual void insertRule(Rule* rule, int index); + virtual Rule* getRule(int index) const; + virtual Rule* removeRule(int index); + virtual int numberOfRules() const; + virtual void setRules(const std::vector<Rule*>& rules); + virtual const std::vector<Rule*>& rules() const; + virtual std::vector<Rule*>& rules(); + + }; + +} +#endif /* RULEBLOCK_H */ |