Discrete.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_DISCRETE_H
  19. #define FL_DISCRETE_H
  20. #include "fl/term/Term.h"
  21. #include <vector>
  22. #include <utility>
  23. namespace fl {
  24. class FL_API Discrete : public Term {
  25. public:
  26. typedef std::pair<scalar, scalar> Pair;
  27. protected:
  28. std::vector<Pair> _xy;
  29. public:
  30. Discrete(const std::string& name = "",
  31. const std::vector<Pair>& xy = std::vector<Pair>(),
  32. scalar height = 1.0);
  33. virtual ~Discrete() FL_IOVERRIDE;
  34. FL_DEFAULT_COPY_AND_MOVE(Discrete)
  35. virtual std::string className() const FL_IOVERRIDE;
  36. virtual std::string parameters() const FL_IOVERRIDE;
  37. virtual void configure(const std::string& parameters) FL_IOVERRIDE;
  38. //Warning: this method is unsafe. Make sure you use it correctly.
  39. template <typename T>
  40. static Discrete* create(const std::string& name, int argc,
  41. T x1, T y1, ...); // throw (fl::Exception);
  42. virtual scalar membership(scalar x) const FL_IOVERRIDE;
  43. virtual void setXY(const std::vector<Pair>& pairs);
  44. virtual const std::vector<Pair>& xy() const;
  45. virtual std::vector<Pair>& xy();
  46. virtual const Pair& xy(int index) const;
  47. virtual Pair& xy(int index);
  48. static std::vector<scalar> toVector(const std::vector<Pair>& xy);
  49. static std::vector<Pair> toPairs(const std::vector<scalar>& xy);
  50. static std::vector<Pair> toPairs(const std::vector<scalar>& xy,
  51. scalar missingValue) FL_INOEXCEPT;
  52. static std::string formatXY(const std::vector<Pair>& xy,
  53. const std::string& prefix = "(", const std::string& innerSeparator = ",",
  54. const std::string& postfix = ")", const std::string& outerSeparator = " ");
  55. virtual Discrete* clone() const FL_IOVERRIDE;
  56. static Term* constructor();
  57. };
  58. }
  59. #endif /* FL_DISCRETE_H */