SingletonTerm.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * SingletonTerm.cpp
  14. *
  15. * Created on: Jan 7, 2010
  16. * Author: jcrada
  17. */
  18. #include "SingletonTerm.h"
  19. namespace fl {
  20. SingletonTerm::SingletonTerm() :
  21. LinguisticTerm() {
  22. }
  23. SingletonTerm::SingletonTerm(const std::string& name, flScalar value) :
  24. LinguisticTerm(name, value - 5 * FL_EPSILON, value + 5 * FL_EPSILON), _value(value) {
  25. }
  26. SingletonTerm::SingletonTerm(const FuzzyOperator& fuzzy_op, const std::string& name,
  27. flScalar value) :
  28. LinguisticTerm(fuzzy_op, name, value - 5 * FL_EPSILON, value + 5 * FL_EPSILON), _value(
  29. value) {
  30. }
  31. SingletonTerm::~SingletonTerm() {
  32. }
  33. void SingletonTerm::setValue(flScalar value) {
  34. this->_value = value;
  35. setMinimum(value - 5 * FL_EPSILON);
  36. setMaximum(value + 5 * FL_EPSILON);
  37. }
  38. flScalar SingletonTerm::value() const {
  39. return this->_value;
  40. }
  41. SingletonTerm* SingletonTerm::clone() const {
  42. return new SingletonTerm(*this);
  43. }
  44. flScalar SingletonTerm::membership(flScalar crisp) const {
  45. return fuzzyOperator().modulation().execute(modulation(), FuzzyOperation::IsEq(crisp, value())
  46. ? flScalar(1.0) : flScalar(0.0));
  47. }
  48. LinguisticTerm::eMembershipFunction SingletonTerm::type() const {
  49. return MF_SINGLETON;
  50. }
  51. std::string SingletonTerm::toString() const {
  52. std::stringstream ss;
  53. ss << LinguisticTerm::toString();
  54. ss << "Singleton (" << value() << ")";
  55. return ss.str();
  56. }
  57. } // namespace fl