Rule.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. Author: Juan Rada-Vilela, Ph.D.
  3. Copyright (C) 2010-2014 FuzzyLite Limited
  4. All rights reserved
  5. This file is part of fuzzylite.
  6. fuzzylite is free software: you can redistribute it and/or modify it under
  7. the terms of the GNU Lesser General Public License as published by the Free
  8. Software Foundation, either version 3 of the License, or (at your option)
  9. any later version.
  10. fuzzylite is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  13. for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with fuzzylite. If not, see <http://www.gnu.org/licenses/>.
  16. fuzzylite™ is a trademark of FuzzyLite Limited.
  17. */
  18. #ifndef FL_RULE_H
  19. #define FL_RULE_H
  20. #include "fl/fuzzylite.h"
  21. #include <map>
  22. #include <string>
  23. namespace fl {
  24. class Engine;
  25. class Antecedent;
  26. class Consequent;
  27. class Hedge;
  28. class TNorm;
  29. class SNorm;
  30. class FL_API Rule {
  31. protected:
  32. std::string _text;
  33. scalar _weight;
  34. FL_unique_ptr<Antecedent> _antecedent;
  35. FL_unique_ptr<Consequent> _consequent;
  36. std::map<std::string, Hedge*> _hedges;
  37. public:
  38. Rule(const std::string& text = "", scalar weight = 1.0);
  39. Rule(const Rule& other);
  40. Rule& operator=(const Rule& other);
  41. virtual ~Rule();
  42. FL_DEFAULT_MOVE(Rule)
  43. virtual void setText(const std::string& text);
  44. virtual std::string getText() const;
  45. virtual void setWeight(scalar weight);
  46. virtual scalar getWeight() const;
  47. virtual void setAntecedent(Antecedent* antecedent);
  48. virtual Antecedent* getAntecedent() const;
  49. virtual void setConsequent(Consequent* consequent);
  50. virtual Consequent* getConsequent() const;
  51. virtual void addHedge(Hedge* hedge);
  52. virtual Hedge* getHedge(const std::string& name) const;
  53. virtual Hedge* removeHedge(const std::string& hedge);
  54. virtual bool hasHedge(const std::string& name) const;
  55. virtual int numberOfHedges() const;
  56. virtual void setHedges(const std::map<std::string, Hedge*>& hedges);
  57. virtual const std::map<std::string, Hedge*>& hedges() const;
  58. virtual std::map<std::string, Hedge*>& hedges();
  59. virtual scalar activationDegree(const TNorm* conjunction, const SNorm* disjunction) const;
  60. virtual void activate(scalar degree, const TNorm* activation) const;
  61. virtual std::string toString() const;
  62. virtual bool isLoaded() const;
  63. virtual void unload();
  64. virtual void load(const Engine* engine);
  65. virtual void load(const std::string& rule, const Engine* engine);
  66. static Rule* parse(const std::string& rule, const Engine* engine);
  67. static std::string ifKeyword() {
  68. return "if";
  69. }
  70. static std::string isKeyword() {
  71. return "is";
  72. }
  73. static std::string thenKeyword() {
  74. return "then";
  75. }
  76. static std::string andKeyword() {
  77. return "and";
  78. }
  79. static std::string orKeyword() {
  80. return "or";
  81. }
  82. static std::string withKeyword() {
  83. return "with";
  84. }
  85. };
  86. }
  87. #endif /* FL_RULE_H */