aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
scheduleOperation.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief the base operation class used to schedule inferences
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #ifndef GUM_SCHEDULE_OPERATION_H
28 #define GUM_SCHEDULE_OPERATION_H
29 
30 #include <string>
31 #include <utility>
32 
33 #include <agrum/agrum.h>
34 
35 #include <agrum/tools/core/sequence.h>
36 #include <agrum/tools/graphicalModels/inference/scheduler/scheduleMultiDim.h>
37 
38 namespace gum {
39 
40  template < typename GUM_SCALAR >
42  public:
43  /// the currently supported types of operations
44  enum class Type : char
45  {
46  /// combine 2 ScheduleMultiDims
48  /// project a ScheduleMultiDim over a subset of its variables
50  /// delete a MultiDim from memory
52  /// store a Multidim into a clique
54  /// store a multidim into a separator
56  };
57 
58  // ############################################################################
59  /// @name Constructors / Destructors
60  // ############################################################################
61  /// @{
62 
63  /// virtual copy constructor: creates a clone of the operation
64  virtual ScheduleOperation< GUM_SCALAR >* newFactory() const = 0;
65 
66  /// destructor
67  virtual ~ScheduleOperation();
68 
69  /// @}
70 
71  // ############################################################################
72  /// @name Operators
73  // ############################################################################
74  /// @{
75 
76  /// operator ==
77  /** Two operations are identical if and only if they have the same
78  * arguments and their types are identical (combine, project, etc) */
79  virtual bool operator==(const ScheduleOperation< GUM_SCALAR >&) const = 0;
80 
81  /// operator !=
82  /** Two operations are identical if and only if they have the same
83  * arguments and their types are identical (combine, project, etc) */
84  virtual bool operator!=(const ScheduleOperation< GUM_SCALAR >&) const = 0;
85 
86  /// @}
87 
88  // ############################################################################
89  /// @name Accessors/Modifiers
90  // ############################################################################
91  /// @{
92 
93  /// returns the name of the operation
94  Type type() const;
95 
96  /// returns the id of the operation
97  Idx id() const;
98 
99  /// returns the set of multidims passed in argument to the operation
100  virtual const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >&
101  multiDimArgs() const = 0;
102 
103  /// returns the set of multidims that should be the result of the operation
104  virtual const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >&
105  multiDimResults() const = 0;
106 
107  /// executes the operation
108  virtual void execute() = 0;
109 
110  /** @brief returns an estimation of the number of elementary operations
111  * needed to perform the ScheduleOperation */
112  virtual float nbOperations() const = 0;
113 
114  /// returns the memory consumption used during the operation
115  /** Actually, this function does not return a precise account of the memory
116  * used by the ScheduleOperation but a rough estimate based on the sizes
117  * of the tables involved in the operation.
118  * @return a pair of memory consumption: the first one is the maximum
119  * amount of memory used during the operation and the second one is the
120  * amount of memory still used at the end of the function ( the memory used
121  * by
122  * the resulting table ) */
123  virtual std::pair< long, long > memoryUsage() const = 0;
124 
125  /// displays the content of the operation
126  virtual std::string toString() const = 0;
127 
128  /// @}
129 
130  protected:
131  /// default constructor
132  explicit ScheduleOperation(Type t);
133 
134  /// copy constructor
135  ScheduleOperation(const ScheduleOperation< GUM_SCALAR >& from);
136 
137  /// copy operator
138  ScheduleOperation< GUM_SCALAR >&
139  operator=(const ScheduleOperation< GUM_SCALAR >&);
140 
141  private:
142  /// the name of the operation to perform
144 
145  /// the id corresponding to the operation
147 
148  /// returns a new distinct ID for each operation
149  static Idx newId__();
150  };
151 
152 } /* namespace gum */
153 
154 // always include the template implementation
155 #include <agrum/tools/graphicalModels/inference/scheduler/scheduleOperation_tpl.h>
156 
157 #endif /* GUM_SCHEDULE_OPERATION_H */
virtual const Sequence< const ScheduleMultiDim< GUM_SCALAR > *> & multiDimResults() const =0
returns the set of multidims that should be the result of the operation
project a ScheduleMultiDim over a subset of its variables
virtual float nbOperations() const =0
returns an estimation of the number of elementary operations needed to perform the ScheduleOperation ...
Type type() const
returns the name of the operation
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
ScheduleOperation(const ScheduleOperation< GUM_SCALAR > &from)
copy constructor
Idx id__
the id corresponding to the operation
Type type__
the name of the operation to perform
virtual const Sequence< const ScheduleMultiDim< GUM_SCALAR > *> & multiDimArgs() const =0
returns the set of multidims passed in argument to the operation
virtual bool operator!=(const ScheduleOperation< GUM_SCALAR > &) const =0
operator !=
Idx id() const
returns the id of the operation
virtual bool operator==(const ScheduleOperation< GUM_SCALAR > &) const =0
operator ==
virtual void execute()=0
executes the operation
Type
the currently supported types of operations
ScheduleOperation(Type t)
default constructor
virtual std::string toString() const =0
displays the content of the operation
virtual ~ScheduleOperation()
destructor
ScheduleOperation< GUM_SCALAR > & operator=(const ScheduleOperation< GUM_SCALAR > &)
copy operator
virtual ScheduleOperation< GUM_SCALAR > * newFactory() const =0
virtual copy constructor: creates a clone of the operation
virtual std::pair< long, long > memoryUsage() const =0
returns the memory consumption used during the operation
delete a MultiDim from memory
static Idx newId__()
returns a new distinct ID for each operation