Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef ALGORITHMSELECTOR_H
00027 #define ALGORITHMSELECTOR_H
00028
00029 #include <string>
00030 #include <vector>
00031
00032 #include "AlgorithmEval.h"
00033 #include "Signature.h"
00034 #ifdef LOGFILE
00035 #include "LogFile.h"
00036 #define STD_LOGFILENAME "AlgActions.log"
00037 #endif
00038
00040 #include <ANN/ANN.h>
00041
00045 typedef double Probability_1D_t;
00046
00047
00048 namespace cop
00049 {
00050
00051 typedef std::vector<std::pair<RelPose*, Probability_1D_t> > PossibleLocations_t;
00052 typedef std::vector<std::pair<RelPose*, Signature*> > SignatureLocations_t;
00053
00054
00055
00056 #define XML_NODE_ALGORITHMSELECTOR "AlgorithmSelector"
00057
00061 template<typename T>
00062 class AlgorithmSelector : public Evaluator
00063 {
00064 public:
00065
00066
00070 AlgorithmSelector(
00071 #ifdef LOGFILE
00072 LogFile& log
00073 #endif
00074 ) :
00075 m_tree(NULL),
00076 m_paLength(0),
00077 m_paAllocatedLength(0),
00078 m_paDim(4)
00079 #ifdef LOGFILE
00080 ,m_logfile(log)
00081 #endif
00082 {
00083 m_mutexAlgEval = new boost::mutex();
00084 }
00085 AlgorithmSelector (XMLTag* node
00086 #ifdef LOGFILE
00087 , LogFile& log
00088 #endif
00089 );
00093 ~AlgorithmSelector ( ){delete m_mutexAlgEval;}
00102 int AddAlgorithm(Algorithm<T>* alg, int nType, double dEval, double dTime);
00103
00109 XMLTag* Save(std::string name = "");
00118 virtual Algorithm<T>* BestAlgorithm(int type, const Signature& sig, const std::vector<Sensor*> &sensors);
00127 std::vector<Algorithm<T>*> BestAlgorithmList(int type, const Signature &sig, const std::vector<Sensor*> &sensors);
00128
00132 int CountAlgorithms(){return m_algorithmlist.size();}
00136 const std::vector<AlgorithmEval<T> >& GetAlgorithmList() const {return m_algorithmlist;};
00140 virtual void EvalAlgorithm(Evaluable* alg, double eval, double time, Signature* relatedElemg);
00145 void ReevaluatePose(Algorithm<T>* alg, RelPose*& pose);
00146
00147
00148 protected:
00152 int InsertInList(AlgorithmEval<T> eval);
00153
00157 bool CheckTypeCompatibility(int listedType, int askedType);
00158
00160 double ReEvalKernel(double val);
00161
00162
00166 std::vector<AlgorithmEval<T> >& GetAlgorithmList(std::vector<AlgorithmEval<T> >* eval = NULL) ;
00167
00172 Algorithm<T>* getAlgorithm(int index);
00173
00174 private:
00178 std::vector<AlgorithmEval<T> > m_algorithmlist;
00179
00183 ANNkd_tree *m_tree;
00184 ANNpointArray m_pointArray;
00185 double *m_pointEval;
00186 int m_paLength;
00187 int m_paAllocatedLength;
00188 int m_paDim;
00189
00190 typedef boost::mutex::scoped_lock lock;
00191 boost::mutex *m_mutexAlgEval;
00192
00196 public:
00197 #ifdef LOGFILE
00198 LogFile& m_logfile;
00199 #endif
00200 };
00201 }
00202 #endif // ALGORITHMSELECTOR_H