Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RandomTrans.h

Go 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 a specified weight (defaults to 1.0)
00025   virtual void addDestination(StateNode* destination, float const weight);
00026 
00027   // This is redundant but needed to shadow Transition::addDestination
00028   virtual void addDestination(StateNode* destination) { addDestination(destination, 1); }
00029 
00030   //! Firing this type of transition activates one destination node at random, instead of all destinations.
00031   virtual void fire();
00032   using Transition::fire;
00033 
00034 protected:
00035   //! constructor, only to be called by subclasses (which need to specify their own @a classname)
00036   RandomTrans(const std::string &classname, const std::string &instancename, 
00037       StateNode* destination, float weight=1);
00038 
00039 private:
00040   std::vector<float> weights; //!< the probably of selection for each source
00041   void addWeight(float weight); //!< adds a weight entry to the back of the queue
00042 };
00043 
00044 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:49 2016 by Doxygen 1.6.3