RectangularTerm.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright 2010 Juan Rada-Vilela
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. /*
  13. * RectangularTerm.cpp
  14. *
  15. * Created on: Jan 7, 2010
  16. * Author: jcrada
  17. */
  18. #include "RectangularTerm.h"
  19. namespace fl {
  20. RectangularTerm::RectangularTerm() :
  21. LinguisticTerm() {
  22. }
  23. RectangularTerm::RectangularTerm(const std::string& name, flScalar minimum,
  24. flScalar maximum) :
  25. LinguisticTerm(name, minimum, maximum) {
  26. }
  27. RectangularTerm::RectangularTerm(const FuzzyOperator& fuzzy_op,
  28. const std::string& name, flScalar minimum, flScalar maximum) :
  29. LinguisticTerm(fuzzy_op, name, minimum, maximum) {
  30. }
  31. RectangularTerm::~RectangularTerm() {
  32. }
  33. RectangularTerm* RectangularTerm::clone() const {
  34. return new RectangularTerm(*this);
  35. }
  36. flScalar RectangularTerm::membership(flScalar crisp) const {
  37. if (crisp > maximum() || crisp < minimum()) {
  38. return flScalar(0.0);
  39. }
  40. return fuzzyOperator().modulation().execute(1.0, modulation());
  41. }
  42. LinguisticTerm::eMembershipFunction RectangularTerm::type() const {
  43. return MF_RECTANGULAR;
  44. }
  45. std::string RectangularTerm::toString() const {
  46. std::stringstream ss;
  47. ss << LinguisticTerm::toString();
  48. ss << "Rectangular (" << minimum() << " " << maximum() << ")";
  49. return ss.str();
  50. }
  51. } // namespace fl