this repo has no description
1/**** , [ OptVar.hh ],
2Copyright (c) 2008 Universite d'Orleans - Jeremie Vautard
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21 *************************************************************************/
22#ifndef __QECODE_OPTVAR__
23#define __QECODE_OPTVAR__
24
25#include "Strategy.hh"
26#include <vector>
27
28/** \brief Abstract class for an Aggregator
29*
30* An aggregator is defined as a function Multiset_of_int -> int. From an implementation
31* point of view, this multiset is a vector of int.
32*/
33class QECODE_VTABLE_EXPORT Aggregator {
34public:
35 virtual int eval(vector<int> values)=0;
36 virtual ~Aggregator() {}
37};
38
39/** \brief Sum aggregator
40*
41* This aggregator computes the sum of all elements of the multiset
42*/
43class QECODE_VTABLE_EXPORT AggregatorSum : public Aggregator{
44public:
45 QECODE_EXPORT virtual int eval(vector<int> values) {
46 int cpt=0;
47 for (int i=0;i<values.size();i++)
48 cpt += values[i];
49 return cpt;
50 }
51 virtual ~AggregatorSum() {}
52};
53
54/** \brief Mean aggregator
55*
56* This aggregator computes the mean of all elements of the multiset
57*/
58class QECODE_VTABLE_EXPORT AggregatorMean : public Aggregator{
59public:
60 QECODE_EXPORT virtual int eval(vector<int> values) {
61 int size=values.size();
62 if (size == 0) return 0;
63 int cpt=0;
64 for (int i=0;i<size; i++)
65 cpt += values[i];
66 cpt = cpt / size;
67 return cpt;
68 }
69 virtual ~AggregatorMean() {}
70};
71
72/** \brief Abstract class for an optimization variable
73*
74* This class defines the interface of an optimization variable, which can be either an existential variable, of the result of an aggregator function
75*/
76class QECODE_VTABLE_EXPORT OptVar {
77public:
78 QECODE_EXPORT virtual int getVal(Strategy s)=0; ///< returns value of this optimization variable in the substrategy s
79 QECODE_EXPORT virtual int getScope()=0; ///< returns the scope where this optimization variable belong
80 virtual ~OptVar() {}
81};
82
83/** \brief Existential optimization variable
84*
85* This class defines an existential optimization variable. This variabe is just an other point of view for an existential variable of the problem.
86*/
87class QECODE_VTABLE_EXPORT ExistOptVar : public OptVar {
88private:
89 int varId;
90 int scopeId;
91public:
92 QECODE_EXPORT ExistOptVar(int var,int scope);
93 QECODE_EXPORT virtual int getVal(Strategy s);
94 QECODE_EXPORT virtual int getScope();
95 virtual ~ExistOptVar() {}
96};
97
98/** \brief Universal optimization variable (aggregator result)
99*
100* This class defines a universal optimization variable. Such a variable represents the result of an aggregator on the set of values that an inner
101* optimization variable takes in every sub-strategy of the current scope.
102*/
103class QECODE_VTABLE_EXPORT UnivOptVar : public OptVar {
104private:
105 int scopeId;
106 OptVar* var;
107 Aggregator* fct;
108public:
109 /** \brief constructor for an universal optimization variable
110 *
111 * Builds a universal optimzation variable at a given (universal) scope, that will represent the result of the agg aggregator on the set of all values
112 * taken by the optimization variable zevar in each substrategy below the current point.
113 * @param scope the scope where this optimization variable belong
114 * @param zevar the inner optimization variable that will be aggregated
115 * @param agg the aggregator function to be used
116 */
117 QECODE_EXPORT UnivOptVar(int scope,OptVar* zevar,Aggregator* agg);
118 QECODE_EXPORT virtual int getVal(Strategy s);
119 QECODE_EXPORT virtual int getScope();
120 virtual ~UnivOptVar() {delete fct;}
121};
122
123#endif
124