/Users/jamian/Desktop/qecode/OptVar.hh

Go to the documentation of this file.
00001 /****   , [ OptVar.hh ], 
00002 Copyright (c) 2008 Universite d'Orleans - Jeremie Vautard 
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021  *************************************************************************/
00022 #ifndef __QECODE_OPTVAR__
00023 #define __QECODE_OPTVAR__
00024 
00025 #include "Strategy.hh"
00026 #include <vector>
00027 
00033 class QECODE_VTABLE_EXPORT Aggregator {
00034 public:
00035     virtual int eval(vector<int> values)=0;
00036     virtual ~Aggregator() {}
00037 };
00038 
00043 class QECODE_VTABLE_EXPORT AggregatorSum : public Aggregator{
00044 public:
00045     QECODE_EXPORT virtual int eval(vector<int> values) {
00046         int cpt=0;
00047         for (int i=0;i<values.size();i++) 
00048             cpt += values[i];
00049         return cpt;
00050     }
00051     virtual ~AggregatorSum() {}
00052 };
00053 
00058 class QECODE_VTABLE_EXPORT AggregatorMean : public Aggregator{
00059 public:
00060     QECODE_EXPORT virtual int eval(vector<int> values) {
00061         int size=values.size();
00062         if (size == 0) return 0;
00063         int cpt=0;
00064         for (int i=0;i<size; i++)
00065             cpt += values[i];
00066         cpt = cpt / size;
00067         return cpt;
00068     }
00069     virtual ~AggregatorMean() {}
00070 };
00071 
00076 class QECODE_VTABLE_EXPORT OptVar {
00077 public:
00078     QECODE_EXPORT virtual int getVal(Strategy s)=0; 
00079     QECODE_EXPORT virtual int getScope()=0; 
00080     virtual ~OptVar() {}
00081 };
00082 
00087 class QECODE_VTABLE_EXPORT ExistOptVar : public OptVar {
00088 private:
00089     int varId;
00090     int scopeId;
00091 public:
00092     QECODE_EXPORT ExistOptVar(int var,int scope);
00093     QECODE_EXPORT virtual int getVal(Strategy s);
00094     QECODE_EXPORT virtual int getScope();
00095     virtual ~ExistOptVar() {}
00096 };
00097 
00103 class QECODE_VTABLE_EXPORT UnivOptVar : public OptVar {
00104 private:
00105     int scopeId;
00106     OptVar* var;
00107     Aggregator* fct;
00108 public:
00117     QECODE_EXPORT UnivOptVar(int scope,OptVar* zevar,Aggregator* agg);
00118     QECODE_EXPORT virtual int getVal(Strategy s);
00119     QECODE_EXPORT virtual int getScope();
00120     virtual ~UnivOptVar() {delete fct;}
00121 };
00122     
00123 #endif

Generated on Tue Jun 10 18:31:30 2008 for qecode by  doxygen 1.5.2