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

  1.  
  2. //
  3. // File:    FuzzyVariableBase.h
  4. //
  5. // Purpose:    The FuzzyVariableBase class is the ancestor of all Fuzzy Variable classes
  6. //
  7. // Copyright ⌐ 1999-2001 Louder Than A Bomb! Software
  8. //
  9. // This file is part of the FFLL (Free Fuzzy Logic Library) project (http://ffll.sourceforge.net)
  10. // It is released under the BSD license, see http://ffll.sourceforge.net/license.txt for the full text.
  11. //
  12.  
  13. #if !defined(AFX_FUZZYVARIABLEBASE_H__F5CADA07_27CC_11D3_B77E_B09059C10001__INCLUDED_)
  14. #define AFX_FUZZYVARIABLEBASE_H__F5CADA07_27CC_11D3_B77E_B09059C10001__INCLUDED_
  15.  
  16. #include "FFLLBase.h"
  17.  
  18. class FuzzySetBase;
  19. class FuzzyModelBase;
  20. class FuzzyRuleIPC;
  21.  
  22.  
  23. // 
  24. // Class:    FuzzyVariableBase
  25. //
  26. // Class that has the variable information. Each variable has a list of 
  27. // sets that define the membership functions for the variable.
  28. //
  29.  
  30. class FFLL_API FuzzyVariableBase :  virtual public FFLLBase  
  31. {
  32.     ////////////////////////////////////////
  33.     ////////// Member Functions ////////////
  34.     ////////////////////////////////////////
  35.  
  36.      public:
  37.  
  38.         // constructor/destructor funcs
  39.         FuzzyVariableBase(FuzzyModelBase* _parent);
  40.         FuzzyVariableBase(); // No function body for this. Explicitly disallow auto-creation of it by the compiler
  41.         virtual ~FuzzyVariableBase();
  42.         virtual int init(const wchar_t* _id, RealType _left_x, RealType _right_x, bool create_unique_id = true);
  43.         virtual int init(const wchar_t* _id, bool create_unique_id = true);
  44.  
  45.         // set functions
  46.         static int set_x_array_count(int _count);
  47.         static int set_dom_array_count(int _count);
  48.         void set_rule_index(int _rule_index, int set_idx = -1);
  49.         virtual int set_left_x(RealType value);
  50.         virtual int set_right_x(RealType value);
  51.         virtual int set_id(const char* _id, int set_idx = -1);
  52.         virtual void set_ramp(int left_right_ind, int hi_lo_ind, int set_idx  );
  53.         int set_id(const wchar_t* _id, int set_idx = -1);
  54.         FFLL_INLINE void set_index(int idx);
  55.           
  56.         // get functions
  57.         static ValuesArrCountType get_x_array_count();
  58.         static ValuesArrCountType get_x_array_max_idx();
  59.         static DOMType get_dom_array_count();
  60.         static DOMType get_dom_array_max_idx();
  61.          RealType get_left_x() const ;
  62.         RealType get_right_x() const ;
  63.         RealType get_idx_multiplier() const;
  64.         virtual DOMType get_dom(int set_idx, int x_position = -1) const ;
  65.          std::string get_model_name() const;
  66.         int get_rule_index(int _set_idx = -1) const ;
  67.         int get_num_of_sets(void) const ;
  68.          FFLL_INLINE short get_index() const;
  69.         FuzzySetBase* get_set(int idx) const;  
  70.           FuzzyModelBase* get_parent(void) const;
  71.          const wchar_t* get_id(int set_idx = -1) const;
  72.           static const char* get_fcl_block_start() ;
  73.         static const char* get_fcl_block_end() ;
  74.  
  75.         // set object functions
  76.         virtual FuzzySetBase* new_set(); 
  77.         virtual FuzzySetBase* new_set(wchar_t* n, int start_x, FuzzyVariableBase* par, short index, int term_width, int type);
  78.  
  79.         // save/load functions
  80.         void save_var_to_fcl_file(std::ofstream& file_contents);
  81.         void save_sets_to_fcl_file(std::ofstream& file_contents);
  82.         int load_sets_from_fcl_file(std::ifstream& file_contents);
  83.  
  84.         // misc functions
  85.         virtual RealType convert_idx_to_value(int idx) const;
  86.         ValuesArrCountType convert_value_to_idx(RealType value) const;
  87.         void calc_idx_multiplier(); // NOTE: there is not 'set' for the multiplier - it's always calculated
  88.          virtual bool is_output(void) const;
  89.           bool is_set_id_unique(const wchar_t* set_id, int set_idx) const;
  90.          virtual void move_node(int set_idx, int idx, _point pt);
  91.         virtual void move_node(int set_idx, int idx, int x, int y);
  92.         virtual void move(int set_idx, int node_idx, int new_x);
  93.         void calc(int set_idx = -1);
  94.          virtual int delete_set(int _set_idx);
  95.          virtual int add_set(const FuzzySetBase* _new_set);
  96.  
  97.     protected:
  98.  
  99.         void delete_all_sets();
  100.   
  101.     private:
  102.  
  103.          static ValuesArrCountType x_array_count;    // how many elements are in the values[] array for the terms
  104.          static ValuesArrCountType x_array_max_idx;  // max index for values[] array (seperate var so we don't have to remember to subtract one each time we want that value)
  105.         static DOMType dom_array_count;            // how many 'gradations' are in the 'y' direction for the degree                        // of membership.  NOTE:  This can NOT be larger than a the largest
  106.                                                 // of membership.  NOTE:  This can NOT be larger than a the largest
  107.                                                 // value that can be stored in a datatype of type DOMType!!!
  108.         static DOMType dom_array_max_idx;        // max index for max_dom
  109.          FuzzySetBase**    sets;                    // Array of the sets (dynamically allocated).  There are "num_of_sets" minus one elements in the array
  110.                                                 // This is a simple array rather than incurring the overhead of a list or some other STL container
  111.         int                num_of_sets;            // How many sets in this variable
  112.         short            index;                    // index for this variable in the model
  113.  
  114.         std::wstring    id ;                    // idendifier for the set wich is unique for the variable its part of.  
  115.         RealType        left_x;                    // minimum value on the 'x' axis
  116.         RealType        right_x;                // maximum value on the 'x' axis
  117.         RealType        idx_multiplier;            // pre-calculated value of (FuzzyVariableBase::x_array_count/(max_value - min_value). This
  118.                                                 // is how many 'x' values are in each element in the values[] array (part of the MemberFuncBase 
  119.                                                 // object).
  120.         int                rule_index;                // this is the starting offset into memory for this variable.
  121.                                                 // It's used to speed access to the rules.
  122.                                                 // *** For an in-depth explaination, see the rule_index var in FuzzySetBase ***
  123.  
  124. }; // end class FuzzyVariableBase  
  125.  
  126. #else
  127.  
  128. class FuzzyVariableBase; // already defined
  129.  
  130. #endif // !defined(AFX_FUZZYVARIABLEBASE_H__F5CADA07_27CC_11D3_B77E_B09059C10001__INCLUDED_)
  131.