aGrUM  0.14.2
scheduleCombination_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 
28 # include <agrum/agrum.h>
29 
30 namespace gum {
31 
33  template < typename GUM_SCALAR >
36  GUM_CONSTRUCTOR(ScheduleCombination);
37  }
38 
40  template < typename GUM_SCALAR >
42  const ScheduleCombination< GUM_SCALAR >& from) {
44  GUM_CONS_CPY(ScheduleCombination);
45  }
46 
48  template < typename GUM_SCALAR >
51  GUM_DESTRUCTOR(ScheduleCombination);
52  }
53 
54  // adds to a given schedule the operations necessary to perform a combination
55  template < typename GUM_SCALAR >
56  ScheduleMultiDim< GUM_SCALAR > ScheduleCombination< GUM_SCALAR >::combine(
57  const Set< const MultiDimImplementation< GUM_SCALAR >* >& set,
58  Schedule< GUM_SCALAR >& schedule) {
59  // first wrap the multidimimplementations into ScheduleMultiDims
60  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
61 
62  for (const auto pot : set)
63  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*pot));
64 
65  // perform the combination
66  const ScheduleMultiDim< GUM_SCALAR >& res = combine(sched_set, schedule);
67 
68  // deallocate the wrappers we just constructed
69  for (const auto sched : sched_set)
70  delete sched;
71 
72  return res;
73  }
74 
75  // adds to a given schedule the operations necessary to perform a combination
76  template < typename GUM_SCALAR >
77  template < template < typename > class TABLE >
78  ScheduleMultiDim< GUM_SCALAR > ScheduleCombination< GUM_SCALAR >::combine(
79  const Set< const TABLE< GUM_SCALAR >* >& set,
80  Schedule< GUM_SCALAR >& schedule) {
81  // first wrap the TABLES into ScheduleMultiDims
82  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
83 
84  for (const auto tab : set)
85  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*tab->content()));
86 
87  // perform the combination
88  const ScheduleMultiDim< GUM_SCALAR >& res = combine(sched_set, schedule);
89 
90  // deallocate the wrappers we just constructed
91  for (const auto sched : sched_set)
92  delete sched;
93 
94  return res;
95  }
96 
99  template < typename GUM_SCALAR >
101  const Set< const MultiDimImplementation< GUM_SCALAR >* >& set,
102  const Schedule< GUM_SCALAR >& schedule) {
103  // first wrap the multidimimplementations into ScheduleMultiDims
104  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
105 
106  for (const auto pot : set)
107  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*pot));
108 
109  // perform the combination
110  float res = nbOperations(sched_set, schedule);
111 
112  // deallocate the wrappers we just constructed
113  for (const auto sched : sched_set)
114  delete sched;
115 
116  return res;
117  }
118 
121  template < typename GUM_SCALAR >
122  template < template < typename > class TABLE >
124  const Set< const TABLE< GUM_SCALAR >* >& set,
125  const Schedule< GUM_SCALAR >& schedule) {
126  // first wrap the TABLES into ScheduleMultiDims
127  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
128 
129  for (const auto tab : set)
130  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*tab->content()));
131 
132  // perform the combination
133  float res = nbOperations(sched_set, schedule);
134 
135  // deallocate the wrappers we just constructed
136  for (const auto sched : sched_set)
137  delete sched;
138 
139  return res;
140  }
141 
143  template < typename GUM_SCALAR >
144  std::pair< long, long > ScheduleCombination< GUM_SCALAR >::memoryUsage(
145  const Set< const MultiDimImplementation< GUM_SCALAR >* >& set,
146  const Schedule< GUM_SCALAR >& schedule) {
147  // first wrap the multidimimplementations into ScheduleMultiDims
148  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
149 
150  for (const auto pot : set)
151  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*pot));
152 
153  // compute the memory consumption of the combination
154  std::pair< long, long > res = memoryUsage(sched_set, schedule);
155 
156  // deallocate the wrappers we just constructed
157  for (const auto sched : sched_set)
158  delete sched;
159 
160  return res;
161  }
162 
165  template < typename GUM_SCALAR >
166  template < template < typename > class TABLE >
167  std::pair< long, long > ScheduleCombination< GUM_SCALAR >::memoryUsage(
168  const Set< const TABLE< GUM_SCALAR >* >& set,
169  const Schedule< GUM_SCALAR >& schedule) {
170  // first wrap the TABLES into ScheduleMultiDims
171  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
172 
173  for (const auto tab : set)
174  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*tab->content()));
175 
176  // compute the memory consumption of the combination
177  std::pair< long, long > res = memoryUsage(sched_set, schedule);
178 
179  // deallocate the wrappers we just constructed
180  for (const auto sched : sched_set)
181  delete sched;
182 
183  return res;
184  }
185 
186 } /* namespace gum */
187 
188 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
virtual float nbOperations(const Set< const ScheduleMultiDim< GUM_SCALAR > * > &set, const Schedule< GUM_SCALAR > &schedule)=0
returns a rough estimate of the number of operations that will be performed to compute the combinatio...
ScheduleCombination()
default constructor
virtual std::pair< long, long > memoryUsage(const Set< const ScheduleMultiDim< GUM_SCALAR > * > &set, const Schedule< GUM_SCALAR > &schedule)=0
returns the memory consumption used during the combination
virtual ScheduleMultiDim< GUM_SCALAR > combine(const Set< const ScheduleMultiDim< GUM_SCALAR > * > &set, Schedule< GUM_SCALAR > &schedule)=0
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual ~ScheduleCombination()
destructor