AlgorithmEval.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 by Ulrich Friedrich Klank <klank@in.tum.de>
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #ifndef ALGORITHMEVAL_H
00020 #define ALGORITHMEVAL_H
00021 
00022 #include "Algorithm.h"
00023 #include "LocateAlgorithm.h"
00024 #include "RefineAlgorithm.h"
00025 #include "ProveAlgorithm.h"
00026 #include "AttentionAlgorithm.h"
00027 #include "Signature.h"
00028 
00029 #define XML_NODE_ALGORITHMEVAL "AlgorithmEval"
00030 #define XML_NODE_EVAL "Eval"
00031 #define XML_NODE_ALGTYPE "AlgType"
00032 #define XML_NODE_AVGTIME "AvgTime"
00033 
00034 #define XML_NODE_OBJECTEVALMAP "ObjEvalMap"
00035 
00036 
00037 #define ALGORITHMTYPE_LOCATE            0x000
00038 #define ALGORITHMTYPE_TRACK             0x010
00039 #define ALGORITHMTYPE_2OBJS             0x200
00040 
00041 #define ALGORITHMTYPE_REFINE            0x100
00042 #define ALGORITHMTYPE_RPOVE             0x400
00043 
00044 #define ALGORITHMTYPE_STOPTRACK         0x800
00045 
00046 
00047 #define ALGORITHMTYPE_STARTATTEND       0x1000
00048 #define ALGORITHMTYPE_STOPATTEND        0x2000
00049 
00050 
00051 #define ALGORITHMTYPE_LOOKUP            0x6400
00052 #define ALGORITHMTYPE_LOOKUPDB          0x6401
00053 #define ALGORITHMTYPE_LOOKUPALL         0x6402
00054 
00055 #define ALGORITHMSPEC_ONETARGET         0
00056 #define ALGORITHMSPEC_SEVERALTARGET     1
00057 
00058 namespace cop
00059 {
00064   template<typename T> class AlgorithmEval
00065   {
00066   public:
00067     AlgorithmEval(Algorithm<T>* alg, int type, double eval, double m_avgRunTime) :
00068       m_algorithm(alg),
00069       m_algorithmType(type),
00070       m_eval(eval),
00071       m_avgRunTime(m_avgRunTime)
00072     {
00073       if(alg == NULL)
00074         printf("Empty Algorithm\n");
00075     }
00076 
00077 
00078     /******************************************************************************
00079     * Constructor Algorithm Eval                                                 */
00080     /******************************************************************************
00081     * @param tag Contains data to load the Evaluation Algorithm.
00082     * Evaluates a tag of the following structure:
00083     * Parent XML_NODE_ALGORITHMEVAL:
00084     *          Child index0: Algorithm<T>      containt any Algorithm  that is loadable by the plugin to load a specific algorithm type
00085     *          XML_NODE_ALGTYPE                one of ALGORITHMTYPE_LOCATE, ALGORITHMTYPE_REFINE and ALGORITHMTYPE_RPOVE (+ALGORITHMSPEC_SEVERALTARGET|ALGORITHMTYPE_TRACK)
00086     *          XML_NODE_EVAL                   double value representing the overall Method score
00087     *          XML_NODE_AVGTIME                double value representing the average running time of the Method
00088     *          XML_NODE_OBJECTEVALMAP[optional] map of int -> double, ulong pair representing specific object<->method relation
00089     *
00090     * @throw char* with an error message in case of failure
00091     *******************************************************************************/
00092     AlgorithmEval(XMLTag* tag);
00093 
00094     std::pair<double, int> GetEval(ObjectID_t id) const 
00095     {
00096       std::map<ObjectID_t, std::pair<double, int> >::const_iterator it;
00097       if((it = m_objectEval.find(id)) != m_objectEval.end())
00098       {
00099         return (*it).second;
00100       }
00101       else
00102       {
00103          std::pair<double, int> p;
00104          p.first = 0.0;
00105          p.second = 0;
00106          return p;
00107       }
00108     }
00109 
00110     void SetEval(ObjectID_t id, double eval)
00111     {
00112       if(m_objectEval.find(id) != m_objectEval.end())
00113       {
00114         m_objectEval[id].first += eval;
00115         m_objectEval[id].second++;
00116       }
00117       else
00118       {
00119         m_objectEval[id].first = eval;
00120         m_objectEval[id].second = 1;
00121       }
00122     }
00123     
00124     size_t MapLength() const{return m_objectEval.size();}
00125     const std::map<ObjectID_t, std::pair<double, int> > GetMap() const {return m_objectEval;}
00126 
00127     /******************************************************************************
00128     * Save                                                                       */
00129     /******************************************************************************
00130     *  @brief Saves all elemens to a serializeable XMLTag
00131     *  @param name [optional]
00132     *  @remarks return value must be deleted
00133     *******************************************************************************/
00134     XMLTag* Save(std::string name = "");
00135 
00136     Algorithm<T>*                                  m_algorithm;
00137     int                                            m_algorithmType;
00138     double                                         m_eval;
00139     double                                         m_avgRunTime;
00140   private:
00141     std::map<ObjectID_t, std::pair<double, int> >  m_objectEval;
00142 
00143   };
00144 
00145   class Evaluator
00146   {
00147   public:
00151     virtual void EvalAlgorithm(Evaluable* alg, double eval, double time, Signature* relatedElemg) = 0;
00155     std::string GetName(){return caller_name;}
00156     void SetName(std::string name){caller_name = name;}
00157 
00158 
00159     std::string caller_name;
00160   };
00161 
00162 }
00163 #endif /*ALGORITHMEVAL_H*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


cognitive_perception
Author(s): Ulrich F Klank
autogenerated on Thu May 23 2013 07:38:34