home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 02 Useful Techniques / 08 Zarozinski / src / ffllapi / COGDefuzzVarObj.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-13  |  3.6 KB  |  119 lines

  1. //
  2. // File:    COGDefuzzVarObj.h
  3. //
  4. // Purpose:    Center of Gravity Defuzzification Method 
  5. //
  6. // Copyright ⌐ 1999-2001 Louder Than A Bomb! Software
  7. //
  8. // This file is part of the FFLL (Free Fuzzy Logic Library) project (http://ffll.sourceforge.net)
  9. // It is released under the BSD license, see http://ffll.sourceforge.net/license.txt for the full text.
  10. //
  11.  
  12. #if !defined(AFX_COGDEFUZZVAROBJ_H__23D883BE_7100_4E65_BA78_7CAA820A6B69__INCLUDED_)
  13. #define AFX_COGDEFUZZVAROBJ_H__23D883BE_7100_4E65_BA78_7CAA820A6B69__INCLUDED_
  14.   
  15.  
  16. #include "DefuzzVarObj.h"
  17.  
  18. class FuzzyOutVariable;
  19. class COGDefuzzSetObj;
  20.  
  21. // 
  22. // Class:    COGDefuzzVarObj
  23. //
  24. // Variable object for Center of Gravity Defuzzification Method
  25. // a.k.a. Center of Mass, Centroid
  26. //
  27. // To calulate this we treat each output set as a point mass. We then calculate
  28. // the center of gravity for those point masses distributed along the 'x' axis.
  29. //
  30. //
  31. // So the standard view of sets we have:
  32. //
  33. //            
  34. //           /\           /\           /\       
  35. //          /  \         /  \         /  \      
  36. //         /    \       /    \       /    \     
  37. //        /      \     /      \     /      \    
  38. //    ---/--------\---/--------\---/--------\---
  39. //           |            |            |
  40. //           m1           m2           m3
  41. //
  42. //    Can be represented as point masses as:
  43. //
  44. //   --------O------------O------------O------
  45. //             |            |            |
  46. //             m1           m2           m3
  47. //
  48. // We then find the center of gravity of the 3 point masses using the formula:
  49. //
  50. //      Sum of the Moments
  51. //      ------------------
  52. //      Sum of the Masses
  53. //
  54. //    - OR - 
  55. //
  56. //         n
  57. //          ---
  58. //          \     m   x
  59. //        /      i   i
  60. //        ---
  61. //        i=0
  62. //      -------------------
  63. //         n
  64. //          ---
  65. //          \     m    
  66. //        /      i    
  67. //        ---
  68. //        i=0
  69. //
  70. // NOTE: That in the COG classes we refer to "mass" as "area"... it seems
  71. // to be a bit more understandable to use the term "area" as we're dealing
  72. // with stuff on a computer where there is no reall mass.  So in our case:  MASS = AREA.
  73. //
  74. // The "moment" is simply the mass times the distance from the origin.  According
  75. // to Archimedes and the "law of the lever" equilibrium in a system is achieved when the
  76. // algebraic sum of the moments is zero.  
  77. //
  78. // You'll often read about this method (especially when it's refered to
  79. // as the centroid method) being the point at which the set would balance
  80. // in 2 Dimensions on the point of a pencil (think of balancing a piece of
  81. // glass shaped like a triangle on the tip of a pencil).  
  82. // The method we are using reduces everything to point masses, effectively
  83. // making it a 1D problem.
  84. //
  85. // All these forumulas are from my Calc 1 textbook:  Calculus by James F. Hurley, 
  86. // Wadsworth Publishing Company 1987
  87. //
  88.  
  89. class COGDefuzzVarObj : public DefuzzVarObj  
  90. {
  91.     ////////////////////////////////////////
  92.     ////////// Member Functions ////////////
  93.     ////////////////////////////////////////
  94.  
  95.     public:
  96.         // constructor/destructor funcs
  97.         COGDefuzzVarObj();// No function body for this. Explicitly disallow auto-creation of it by the compiler
  98.         COGDefuzzVarObj(FuzzyOutVariable* _parent);
  99.         virtual ~COGDefuzzVarObj();
  100.  
  101.         // get method
  102.         int get_defuzz_type() const ;
  103.  
  104.         // misc functions
  105.         RealType calc_value(DOMType* out_set_dom_arr );
  106.  
  107.     protected:
  108.  
  109.         // get functions
  110.         COGDefuzzSetObj* get_set_defuzz_obj(int set_idx) const;  
  111.  
  112. }; // end class COGDefuzzVarObj
  113.  
  114. #else
  115.  
  116. class COGDefuzzVarObj;
  117.  
  118. #endif // !defined(AFX_COGDEFUZZVAROBJ_H__23D883BE_7100_4E65_BA78_7CAA820A6B69__INCLUDED_)
  119.