/tags/rel-0-5-1/FreeSpeech/FuzzyEngine/include/FuzzySet.h

# · C Header · 122 lines · 56 code · 44 blank · 22 comment · 3 complexity · 0a004a95a99d33cae56c53165267502e MD5 · raw file

  1. // Copyright (C) 2000 Dominic Letourneau (doumdi@yahoo.com)
  2. // FuzzySet.h: interface for the FuzzySet class.
  3. //
  4. //////////////////////////////////////////////////////////////////////
  5. #ifndef _FUZZY_SET_H_
  6. #define _FUZZY_SET_H_
  7. #include <string>
  8. #include <vector>
  9. #include <map>
  10. #include "FuzzyFunction.h"
  11. #include "TrapezoidalFunction.h"
  12. #include "TriangularFunction.h"
  13. #include "BufferedNode.h"
  14. using namespace std;
  15. class FuzzySet : public BufferedNode, public Object {
  16. public:
  17. //returns the index of the function in the set
  18. int find_function_by_index(const string &name);
  19. //returns the pointer of the function of a given name
  20. FuzzyFunction *find_function_by_name (const string &name);
  21. //adds a triangular function to the set
  22. void add_triangular_function (const string &name, float a, float b, float c);
  23. //adds a trapezoidal function to the set
  24. void add_trapezoidal_function (const string &name, float a, float b, float c, float d);
  25. //constructor with a name
  26. FuzzySet(const string &name);
  27. FuzzySet(string nodeName, ParameterSet params);
  28. FuzzySet();
  29. FuzzySet(istream &in);
  30. //destructor
  31. virtual ~FuzzySet();
  32. //evaluation of all the membership function at once
  33. vector<float> & get_all_membership_evaluation(float x);
  34. //get the evaluation of the membership function of a given name
  35. float get_membership_evaluation(const string &name, float x);
  36. //accessor for the name
  37. const string& get_name(){return m_name;}
  38. //reset all functions inference stacks
  39. void reset() {for (int i = 0 ; i < m_functions.size(); i++) m_functions[i]->reset_inference_values();}
  40. //retuns the internal vector of fuzzy functions
  41. vector<FuzzyFunction*> & get_member_functions() {return m_functions;}
  42. //returns the number of function in the set
  43. int get_function_count() {return m_functions.size();}
  44. //print the membership functions
  45. void print_functions(ostream &out);
  46. virtual void calculate(int output_id, int count, Buffer &out);
  47. FuzzySet* clone();
  48. virtual void printOn(ostream &out);
  49. virtual void readFrom(istream &in=cin);
  50. private:
  51. //the set name
  52. string m_name;
  53. //the vector of fuzzy functions
  54. vector<FuzzyFunction*> m_functions;
  55. //the evaluation vector (results of the evaluation of functions)
  56. vector<float> m_evaluation;
  57. //the inputID
  58. int m_functionID;
  59. //the outputID
  60. int m_setID;
  61. };
  62. inline void Vector<FuzzySet*>::printOn(ostream &out) const {
  63. cerr<<"PrintOn called (Vector<FuzzySet*>)"<<endl;
  64. for (int i = 0; i < size(); i++) {
  65. cerr<<"calling printon"<<endl;
  66. operator[](i)->printOn(out);
  67. }
  68. }
  69. inline void Vector<FuzzySet*>::readFrom(istream &in) {
  70. }
  71. inline void Vector<FuzzySet*>::destroy() {
  72. for (Vector<FuzzySet*>::iterator iter = this->begin();
  73. iter != this->end(); iter++) {
  74. delete (*iter);
  75. }
  76. delete this;
  77. }
  78. #endif