Variable.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_VARIABLE_H
  19. #define FL_VARIABLE_H
  20. #include "fl/fuzzylite.h"
  21. #include <string>
  22. #include <vector>
  23. namespace fl {
  24. class Term;
  25. class FL_API Variable {
  26. private:
  27. void copyFrom(const Variable& source);
  28. protected:
  29. std::string _name;
  30. std::vector<Term*> _terms;
  31. scalar _minimum, _maximum;
  32. bool _enabled;
  33. public:
  34. Variable(const std::string& name = "",
  35. scalar minimum = -fl::inf,
  36. scalar maximum = fl::inf);
  37. Variable(const Variable& other);
  38. Variable& operator=(const Variable& other);
  39. virtual ~Variable();
  40. FL_DEFAULT_MOVE(Variable)
  41. virtual void setName(const std::string& name);
  42. virtual std::string getName() const;
  43. virtual void setRange(scalar minimum, scalar maximum);
  44. virtual scalar range() const;
  45. virtual void setMinimum(scalar minimum);
  46. virtual scalar getMinimum() const;
  47. virtual void setMaximum(scalar maximum);
  48. virtual scalar getMaximum() const;
  49. virtual void setEnabled(bool enabled);
  50. virtual bool isEnabled() const;
  51. virtual std::string fuzzify(scalar x) const;
  52. virtual Term* highestMembership(scalar x, scalar* yhighest = fl::null) const;
  53. virtual std::string toString() const;
  54. /**
  55. * Operations for iterable datatype _terms
  56. */
  57. virtual void sort();
  58. virtual void addTerm(Term* term);
  59. virtual void insertTerm(Term* term, int index);
  60. virtual Term* getTerm(int index) const;
  61. virtual Term* getTerm(const std::string& name) const;
  62. virtual bool hasTerm(const std::string& name) const;
  63. virtual Term* removeTerm(int index);
  64. virtual int numberOfTerms() const;
  65. virtual void setTerms(const std::vector<Term*>& terms);
  66. virtual const std::vector<Term*>& terms() const;
  67. virtual std::vector<Term*>& terms();
  68. };
  69. }
  70. #endif /* FL_VARIABLE_H */