aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
scheduleOperation.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 >* >& multiDimArgs() const = 0;
101 
102  /// returns the set of multidims that should be the result of the operation
103  virtual const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >& multiDimResults() const = 0;
104 
105  /// executes the operation
106  virtual void execute() = 0;
107 
108  /** @brief returns an estimation of the number of elementary operations
109  * needed to perform the ScheduleOperation */
110  virtual float nbOperations() const = 0;
111 
112  /// returns the memory consumption used during the operation
113  /** Actually, this function does not return a precise account of the memory
114  * used by the ScheduleOperation but a rough estimate based on the sizes
115  * of the tables involved in the operation.
116  * @return a pair of memory consumption: the first one is the maximum
117  * amount of memory used during the operation and the second one is the
118  * amount of memory still used at the end of the function ( the memory used
119  * by
120  * the resulting table ) */
121  virtual std::pair< long, long > memoryUsage() const = 0;
122 
123  /// displays the content of the operation
124  virtual std::string toString() const = 0;
125 
126  /// @}
127 
128  protected:
129  /// default constructor
130  explicit ScheduleOperation(Type t);
131 
132  /// copy constructor
133  ScheduleOperation(const ScheduleOperation< GUM_SCALAR >& from);
134 
135  /// copy operator
136  ScheduleOperation< GUM_SCALAR >& operator=(const ScheduleOperation< GUM_SCALAR >&);
137 
138  private:
139  /// the name of the operation to perform
141 
142  /// the id corresponding to the operation
144 
145  /// returns a new distinct ID for each operation
146  static Idx _newId_();
147  };
148 
149 } /* namespace gum */
150 
151 // always include the template implementation
152 #include <agrum/tools/graphicalModels/inference/scheduler/scheduleOperation_tpl.h>
153 
154 #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:643
Idx _id_
the id corresponding to the operation
ScheduleOperation(const ScheduleOperation< GUM_SCALAR > &from)
copy constructor
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 !=
Type _type_
the name of the operation to perform
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
static Idx _newId_()
returns a new distinct ID for each operation
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