aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
O3ClassFactory.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 /**
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 >& operator=(const O3ClassFactory< GUM_SCALAR >& src);
68  O3ClassFactory< GUM_SCALAR >& operator=(O3ClassFactory< GUM_SCALAR >&& src);
69 
70  void buildClasses();
71 
72  void buildImplementations();
73 
74  void buildParameters();
75 
76  void buildReferenceSlots();
77 
78  void declareAggregates();
79 
80  void completeAggregates();
81 
82  void declareAttributes();
83 
84  void completeAttributes();
85 
86 
87  private:
92 
98 
99  /// @name Checking classes
100  /// @{
102 
104 
105  bool _checkAndAddArcsToDag_();
106 
107  bool _checkO3Classes_();
108  /// @}
109 
110  /// @name Checking Implementations
111  /// @{
112  bool _checkImplementation_(O3Class& c);
113 
114  bool _checkImplementation_(O3Class& c,
115  O3Label& i,
116  HashTable< std::string, O3Attribute* >& attrMap,
117  HashTable< std::string, O3Aggregate* >& aggMap,
118  HashTable< std::string, O3ReferenceSlot* >& refMap);
119 
120  bool _checkImplementation_(O3Label& o3_type, const PRMType& type);
121 
122  bool _checkImplementation_(O3Label& o3_type,
123  const PRMClassElementContainer< GUM_SCALAR >& type);
124  /// @}
125 
126  /// @name Checking and Adding Paramteters
127  /// @{
128  void _addParameters_(PRMFactory< GUM_SCALAR >& factory, O3Class& c);
129 
130  /// @}
131 
132  /// @name Checking and adding Reference Slots
133  /// @{
134  void _addReferenceSlots_(O3Class& c);
135 
136 
137  bool _checkReferenceSlot_(O3Class& c, O3ReferenceSlot& ref);
138  /// @}
139 
140  /// @name Checking and adding Attributes
141  /// @{
142  void _declareAttribute_(O3Class& c);
143 
144  bool _checkAttributeForDeclaration_(O3Class& o3_c, O3Attribute& attr);
145 
146  void _completeAttribute_(PRMFactory< GUM_SCALAR >& factory, O3Class& c);
147 
148  bool _checkAttributeForCompletion_(const O3Class& o3_c, O3Attribute& attr);
149 
150  bool _checkParent_(const PRMClass< GUM_SCALAR >& c, const O3Label& prnt);
151 
152  bool _checkLocalParent_(const PRMClass< GUM_SCALAR >& c, const O3Label& prnt);
153 
154  bool _checkRemoteParent_(const PRMClassElementContainer< GUM_SCALAR >& c,
155  const O3Label& prnt);
156 
157  bool _checkRawCPT_(const PRMClass< GUM_SCALAR >& c, O3RawCPT& attr);
158 
159  bool _checkRuleCPT_(const PRMClass< GUM_SCALAR >& c, O3RuleCPT& attr);
160 
161  bool _checkLabelsNumber_(const O3RuleCPT& attr, const O3RuleCPT::O3Rule& rule);
162 
163  bool _checkLabelsValues_(const PRMClass< GUM_SCALAR >& c,
164  const O3RuleCPT& attr,
165  const O3RuleCPT::O3Rule& rule);
166 
167  void _addParamsToForms_(
168  const HashTable< std::string, const PRMParameter< GUM_SCALAR >* >& scope,
169  O3RuleCPT::O3Rule& rule);
170 
171  bool _checkRuleCPTSumsTo1_(const PRMClass< GUM_SCALAR >& c,
172  const O3RuleCPT& attr,
173  const O3RuleCPT::O3Rule& rule);
174 
175  /// @}
176 
177  /// @name Utility methods
178  /// @{
179  const PRMClassElement< GUM_SCALAR >*
181  const O3Label& chain);
182 
183  bool _checkSlotChainLink_(const PRMClassElementContainer< GUM_SCALAR >& c,
184  const O3Label& chain,
185  const std::string& s);
186  /// @}
187 
188  /// @name Checking and adding Aggregates
189  /// @{
190  void _declareAggregates_(O3Class& c);
191  void _completeAggregates_(PRMFactory< GUM_SCALAR >& factory, O3Class& c);
192 
193  bool _checkAggregateForDeclaration_(O3Class& o3class, O3Aggregate& agg);
194  bool _checkAggregateForCompletion_(O3Class& o3class, O3Aggregate& agg);
195 
197 
198  bool _checkAggTypeLegality_(O3Class& o3class, O3Aggregate& agg);
199 
200 
201  bool _checkAggParameters_(O3Class& o3class, O3Aggregate& agg, const PRMType* t);
202 
203  bool _checkParametersNumber_(O3Aggregate& agg, Size n);
204 
205  bool _checkParameterValue_(O3Aggregate& agg, const gum::prm::PRMType& t);
206 
207  // @}
208  };
209 
210  } // namespace o3prm
211  } // namespace prm
212 } // namespace gum
213 
214 // always include the implementation of the templates
215 # include <agrum/PRM/o3prm/O3ClassFactory_tpl.h>
216 
217 
218 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
219 extern template class gum::prm::o3prm::O3ClassFactory< double >;
220 # endif
221 
222 
223 #endif // GUM_PRM_O3PRM_O3CLASS_FACTORY_H
bool _checkLabelsValues_(const PRMClass< GUM_SCALAR > &c, const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)
bool _checkLabelsNumber_(const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)
void _completeAttribute_(PRMFactory< GUM_SCALAR > &factory, O3Class &c)
bool _checkReferenceSlot_(O3Class &c, O3ReferenceSlot &ref)
const PRMType * _checkAggParents_(O3Class &o3class, O3Aggregate &agg)
O3ClassFactory< GUM_SCALAR > & operator=(O3ClassFactory< GUM_SCALAR > &&src)
void _addParamsToForms_(const HashTable< std::string, const PRMParameter< GUM_SCALAR > * > &scope, O3RuleCPT::O3Rule &rule)
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
bool _checkRuleCPT_(const PRMClass< GUM_SCALAR > &c, O3RuleCPT &attr)
bool _checkParent_(const PRMClass< GUM_SCALAR > &c, const O3Label &prnt)
std::vector< O3Class *> _o3Classes_
O3ClassFactory(O3ClassFactory< GUM_SCALAR > &&src)
const PRMClassElement< GUM_SCALAR > * _resolveSlotChain_(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain)
bool _checkAttributeForDeclaration_(O3Class &o3_c, O3Attribute &attr)
HashTable< NodeId, O3Class *> _nodeMap_
bool _checkParametersNumber_(O3Aggregate &agg, Size n)
bool _checkSlotChainLink_(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &chain, const std::string &s)
O3NameSolver< GUM_SCALAR > * _solver_
O3ClassFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
bool _checkImplementation_(O3Class &c, O3Label &i, HashTable< std::string, O3Attribute * > &attrMap, HashTable< std::string, O3Aggregate * > &aggMap, HashTable< std::string, O3ReferenceSlot * > &refMap)
bool _checkAggregateForCompletion_(O3Class &o3class, O3Aggregate &agg)
HashTable< std::string, gum::NodeId > _nameMap_
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
O3ClassFactory(const O3ClassFactory< GUM_SCALAR > &src)
Builds gum::prm::Class from gum::prm::o3prm::O3Class.
void _completeAggregates_(PRMFactory< GUM_SCALAR > &factory, O3Class &c)
bool _checkAggParameters_(O3Class &o3class, O3Aggregate &agg, const PRMType *t)
bool _checkParameterValue_(O3Aggregate &agg, const gum::prm::PRMType &t)
void _addParameters_(PRMFactory< GUM_SCALAR > &factory, O3Class &c)
HashTable< std::string, O3Class *> _classMap_
bool _checkRawCPT_(const PRMClass< GUM_SCALAR > &c, O3RawCPT &attr)
bool _checkRuleCPTSumsTo1_(const PRMClass< GUM_SCALAR > &c, const O3RuleCPT &attr, const O3RuleCPT::O3Rule &rule)
bool _checkAggregateForDeclaration_(O3Class &o3class, O3Aggregate &agg)
bool _checkRemoteParent_(const PRMClassElementContainer< GUM_SCALAR > &c, const O3Label &prnt)
bool _checkLocalParent_(const PRMClass< GUM_SCALAR > &c, const O3Label &prnt)
O3ClassFactory< GUM_SCALAR > & operator=(const O3ClassFactory< GUM_SCALAR > &src)
bool _checkAttributeForCompletion_(const O3Class &o3_c, O3Attribute &attr)
bool _checkAggTypeLegality_(O3Class &o3class, O3Aggregate &agg)
bool _checkImplementation_(O3Label &o3_type, const PRMClassElementContainer< GUM_SCALAR > &type)