aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
O3ClassFactory.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 /**
23  * @file
24  * @brief Headers for the O3ClassFactory class.
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  * @author Lionel TORTI
28  */
29 
30 #include <algorithm>
31 #include <memory>
32 #include <string>
33 
34 #include <agrum/PRM/PRM.h>
35 #include <agrum/PRM/PRMFactory.h>
36 #include <agrum/PRM/o3prm/O3NameSolver.h>
37 #include <agrum/PRM/o3prm/O3prm.h>
38 #include <agrum/tools/core/hashTable.h>
39 #include <agrum/tools/core/set.h>
40 
41 #ifndef GUM_PRM_O3PRM_O3CLASS_FACTORY_H
42 # define GUM_PRM_O3PRM_O3CLASS_FACTORY_H
43 
44 namespace gum {
45  namespace prm {
46  namespace o3prm {
47 
48  /**
49  * @class O3ClassFactory
50  * @headerfile O3ClassFactory.h <agrum/PRM/o3prm/O3ClassFactory.h>
51  * @ingroup o3prm_group
52  *
53  * @brief Builds gum::prm::Class from gum::prm::o3prm::O3Class.
54  *
55  * @tparam GUM_SCALAR The scalar type used by the gum::prm:PRM.
56  */
57  template < typename GUM_SCALAR >
59  public:
60  O3ClassFactory(PRM< GUM_SCALAR >& prm,
61  O3PRM& o3_prm,
62  O3NameSolver< GUM_SCALAR >& solver,
63  ErrorsContainer& errors);
64  O3ClassFactory(const O3ClassFactory< GUM_SCALAR >& src);
65  O3ClassFactory(O3ClassFactory< GUM_SCALAR >&& src);
66  ~O3ClassFactory();
67  O3ClassFactory< GUM_SCALAR >&
68  operator=(const O3ClassFactory< GUM_SCALAR >& src);
69  O3ClassFactory< GUM_SCALAR >&
70  operator=(O3ClassFactory< GUM_SCALAR >&& src);
71 
72  void buildClasses();
73 
74  void buildImplementations();
75 
76  void buildParameters();
77 
78  void buildReferenceSlots();
79 
80  void declareAggregates();
81 
82  void completeAggregates();
83 
84  void declareAttributes();
85 
86  void completeAttributes();
87 
88 
89  private:
94 
100 
101  /// @name Checking classes
102  /// @{
104 
106 
107  bool checkAndAddArcsToDag__();
108 
109  bool checkO3Classes__();
110  /// @}
111 
112  /// @name Checking Implementations
113  /// @{
114  bool checkImplementation__(O3Class& c);
115 
117  O3Class& c,
118  O3Label& i,
119  HashTable< std::string, O3Attribute* >& attrMap,
120  HashTable< std::string, O3Aggregate* >& aggMap,
121  HashTable< std::string, O3ReferenceSlot* >& refMap);
122 
123  bool checkImplementation__(O3Label& o3_type, const PRMType& type);
124 
126  O3Label& o3_type,
127  const PRMClassElementContainer< GUM_SCALAR >& type);
128  /// @}
129 
130  /// @name Checking and Adding Paramteters
131  /// @{
132  void addParameters__(PRMFactory< GUM_SCALAR >& factory, O3Class& c);
133 
134  /// @}
135 
136  /// @name Checking and adding Reference Slots
137  /// @{
138  void addReferenceSlots__(O3Class& c);
139 
140 
141  bool checkReferenceSlot__(O3Class& c, O3ReferenceSlot& ref);
142  /// @}
143 
144  /// @name Checking and adding Attributes
145  /// @{
146  void declareAttribute__(O3Class& c);
147 
148  bool checkAttributeForDeclaration__(O3Class& o3_c, O3Attribute& attr);
149 
150  void completeAttribute__(PRMFactory< GUM_SCALAR >& factory, O3Class& c);
151 
152  bool checkAttributeForCompletion__(const O3Class& o3_c, O3Attribute& attr);
153 
154  bool checkParent__(const PRMClass< GUM_SCALAR >& c, const O3Label& prnt);
155 
156  bool checkLocalParent__(const PRMClass< GUM_SCALAR >& c,
157  const O3Label& prnt);
158 
159  bool checkRemoteParent__(const PRMClassElementContainer< GUM_SCALAR >& c,
160  const O3Label& prnt);
161 
162  bool checkRawCPT__(const PRMClass< GUM_SCALAR >& c, O3RawCPT& attr);
163 
164  bool checkRuleCPT__(const PRMClass< GUM_SCALAR >& c, O3RuleCPT& attr);
165 
166  bool checkLabelsNumber__(const O3RuleCPT& attr,
167  const O3RuleCPT::O3Rule& rule);
168 
169  bool checkLabelsValues__(const PRMClass< GUM_SCALAR >& c,
170  const O3RuleCPT& attr,
171  const O3RuleCPT::O3Rule& rule);
172 
173  void addParamsToForms__(
174  const HashTable< std::string, const PRMParameter< GUM_SCALAR >* >&
175  scope,
176  O3RuleCPT::O3Rule& rule);
177 
178  bool checkRuleCPTSumsTo1__(const PRMClass< GUM_SCALAR >& c,
179  const O3RuleCPT& attr,
180  const O3RuleCPT::O3Rule& rule);
181 
182  /// @}
183 
184  /// @name Utility methods
185  /// @{
186  const PRMClassElement< GUM_SCALAR >*
188  const O3Label& chain);
189 
190  bool checkSlotChainLink__(const PRMClassElementContainer< GUM_SCALAR >& c,
191  const O3Label& chain,
192  const std::string& s);
193  /// @}
194 
195  /// @name Checking and adding Aggregates
196  /// @{
197  void declareAggregates__(O3Class& c);
198  void completeAggregates__(PRMFactory< GUM_SCALAR >& factory, O3Class& c);
199 
200  bool checkAggregateForDeclaration__(O3Class& o3class, O3Aggregate& agg);
201  bool checkAggregateForCompletion__(O3Class& o3class, O3Aggregate& agg);
202 
204 
205  bool checkAggTypeLegality__(O3Class& o3class, O3Aggregate& agg);
206 
207 
208  bool checkAggParameters__(O3Class& o3class,
209  O3Aggregate& agg,
210  const PRMType* t);
211 
212  bool checkParametersNumber__(O3Aggregate& agg, Size n);
213 
214  bool checkParameterValue__(O3Aggregate& agg, const gum::prm::PRMType& t);
215 
216  // @}
217  };
218 
219  } // namespace o3prm
220  } // namespace prm
221 } // namespace gum
222 
223 // always include the implementation of the templates
224 # include <agrum/PRM/o3prm/O3ClassFactory_tpl.h>
225 
226 
227 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
228 extern template class gum::prm::o3prm::O3ClassFactory< double >;
229 # endif
230 
231 
232 #endif // GUM_PRM_O3PRM_O3CLASS_FACTORY_H
bool checkAggregateForDeclaration__(O3Class &o3class, O3Aggregate &agg)
O3ClassFactory< GUM_SCALAR > & operator=(O3ClassFactory< GUM_SCALAR > &&src)
bool checkParameterValue__(O3Aggregate &agg, const gum::prm::PRMType &t)
bool checkParametersNumber__(O3Aggregate &agg, Size n)
bool checkAggregateForCompletion__(O3Class &o3class, O3Aggregate &agg)
void completeAggregates__(PRMFactory< GUM_SCALAR > &factory, O3Class &c)
bool checkImplementation__(O3Class &c, O3Label &i, HashTable< std::string, O3Attribute * > &attrMap, HashTable< std::string, O3Aggregate * > &aggMap, HashTable< std::string, O3ReferenceSlot * > &refMap)
O3NameSolver< GUM_SCALAR > * solver__
bool checkSlotChainLink__(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain, const std::string &s)
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
bool checkAttributeForCompletion__(const O3Class &o3_c, O3Attribute &attr)
O3ClassFactory(O3ClassFactory< GUM_SCALAR > &&src)
std::vector< O3Class *> o3Classes__
HashTable< std::string, gum::NodeId > nameMap__
bool checkAggParameters__(O3Class &o3class, O3Aggregate &agg, const PRMType *t)
bool checkLocalParent__(const PRMClass< GUM_SCALAR > &c, const O3Label &prnt)
HashTable< std::string, O3Class *> classMap__
bool checkRuleCPTSumsTo1__(const PRMClass< GUM_SCALAR > &c, const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)
void addParameters__(PRMFactory< GUM_SCALAR > &factory, O3Class &c)
bool checkImplementation__(O3Label &o3_type, const PRMClassElementContainer< GUM_SCALAR > &type)
const PRMClassElement< GUM_SCALAR > * resolveSlotChain__(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain)
void addParamsToForms__(const HashTable< std::string, const PRMParameter< GUM_SCALAR > * > &scope, O3RuleCPT::O3Rule &rule)
O3ClassFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
bool checkParent__(const PRMClass< GUM_SCALAR > &c, const O3Label &prnt)
bool checkAggTypeLegality__(O3Class &o3class, O3Aggregate &agg)
const PRMType * checkAggParents__(O3Class &o3class, O3Aggregate &agg)
bool checkAttributeForDeclaration__(O3Class &o3_c, O3Attribute &attr)
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
void completeAttribute__(PRMFactory< GUM_SCALAR > &factory, O3Class &c)
bool checkRuleCPT__(const PRMClass< GUM_SCALAR > &c, O3RuleCPT &attr)
O3ClassFactory(const O3ClassFactory< GUM_SCALAR > &src)
Builds gum::prm::Class from gum::prm::o3prm::O3Class.
bool checkRemoteParent__(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &prnt)
HashTable< NodeId, O3Class *> nodeMap__
bool checkRawCPT__(const PRMClass< GUM_SCALAR > &c, O3RawCPT &attr)
O3ClassFactory< GUM_SCALAR > & operator=(const O3ClassFactory< GUM_SCALAR > &src)
bool checkLabelsValues__(const PRMClass< GUM_SCALAR > &c, const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)
bool checkLabelsNumber__(const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)
bool checkReferenceSlot__(O3Class &c, O3ReferenceSlot &ref)