Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
RandomTrans.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_RandomTrans_h_ 00003 #define INCLUDED_RandomTrans_h_ 00004 00005 #include "Behaviors/Transitions/NullTrans.h" 00006 #include "Events/EventRouter.h" 00007 00008 //! A transition that fires immediately, randomly choosing one destination node to activate. 00009 00010 /*! This class should be extended in the following way: 00011 * 00012 * setHistoryLength(int n) to maintain a history of recent choices that are 00013 * not to be reused, i.e., drawing without replacement 00014 */ 00015 00016 class RandomTrans : public NullTrans { 00017 public: 00018 //! constructor 00019 RandomTrans(StateNode* destination, float weight=1); 00020 00021 //! constructor 00022 RandomTrans(const std::string& name, StateNode* destination, float weight=1); 00023 00024 //! Add a destination node with weight==1 (see addDestination(StateNode* dest, float weight) to specify a different weight) 00025 virtual void addDestination(StateNode* destination) { 00026 addDestination(destination,1); 00027 } 00028 00029 //! Add a destination node with an specified weight (other version of addDestination() assumes weight==1) 00030 void addDestination(StateNode* destination, float weight); 00031 00032 //! Firing this type of transition activates one destination node at random, 00033 //! instead of all nodes. 00034 virtual void fire(); 00035 00036 protected: 00037 //! constructor, only to be called by subclasses (which need to specify their own @a classname) 00038 RandomTrans(const std::string &classname, const std::string &instancename, 00039 StateNode* destination, float weight=1); 00040 00041 private: 00042 std::vector<float> weights; //!< the probably of selection for each source 00043 void addWeight(float weight); //!< adds a weight entry to the back of the queue 00044 }; 00045 00046 #endif |
Tekkotsu v4.0 |
Generated Thu Nov 22 00:54:55 2007 by Doxygen 1.5.4 |