aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
gum::prm::o3prm::O3SystemFactory< GUM_SCALAR > Class Template Reference

Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System. More...

#include <agrum/PRM/o3prm/O3SystemFactory.h>

+ Collaboration diagram for gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >:

Public Member Functions

 O3SystemFactory (PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
 
 O3SystemFactory (const O3SystemFactory< GUM_SCALAR > &src)
 
 O3SystemFactory (O3SystemFactory< GUM_SCALAR > &&src)
 
 ~O3SystemFactory ()
 
O3SystemFactory< GUM_SCALAR > & operator= (const O3SystemFactory< GUM_SCALAR > &src)
 
O3SystemFactory< GUM_SCALAR > & operator= (O3SystemFactory< GUM_SCALAR > &&src)
 
void build ()
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >

Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System.

Template Parameters
GUM_SCALARThe scalar type used by the gum::prm::PRM.

Definition at line 58 of file O3SystemFactory.h.

Constructor & Destructor Documentation

◆ O3SystemFactory() [1/3]

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::O3SystemFactory ( PRM< GUM_SCALAR > &  prm,
O3PRM o3_prm,
O3NameSolver< GUM_SCALAR > &  solver,
ErrorsContainer errors 
)

Definition at line 38 of file O3SystemFactory_tpl.h.

42  :
43  __prm(&prm),
44  __o3_prm(&o3_prm), __solver(&solver), __errors(&errors) {
45  GUM_CONSTRUCTOR(O3SystemFactory);
46  }
O3NameSolver< GUM_SCALAR > * __solver
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

◆ O3SystemFactory() [2/3]

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::O3SystemFactory ( const O3SystemFactory< GUM_SCALAR > &  src)

Definition at line 49 of file O3SystemFactory_tpl.h.

50  :
51  __prm(src.__prm),
52  __o3_prm(src.__o3_prm), __solver(src.__solver), __errors(src.__errors),
53  __nameMap(src.__nameMap) {
54  GUM_CONS_CPY(O3SystemFactory);
55  }
O3NameSolver< GUM_SCALAR > * __solver
HashTable< std::string, O3Instance *> __nameMap
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

◆ O3SystemFactory() [3/3]

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::O3SystemFactory ( O3SystemFactory< GUM_SCALAR > &&  src)

Definition at line 58 of file O3SystemFactory_tpl.h.

59  :
60  __prm(std::move(src.__prm)),
61  __o3_prm(std::move(src.__o3_prm)), __solver(std::move(src.__solver)),
62  __errors(std::move(src.__errors)), __nameMap(std::move(src.__nameMap)) {
63  GUM_CONS_MOV(O3SystemFactory);
64  }
O3NameSolver< GUM_SCALAR > * __solver
HashTable< std::string, O3Instance *> __nameMap
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

◆ ~O3SystemFactory()

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::~O3SystemFactory ( )

Definition at line 67 of file O3SystemFactory_tpl.h.

67  {
68  GUM_DESTRUCTOR(O3SystemFactory);
69  }
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

Member Function Documentation

◆ __addAssignments()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addAssignments ( PRMFactory< GUM_SCALAR > &  factory,
O3System sys 
)
private

Definition at line 142 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3System::assignments(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3System::name(), and gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

143  {
144  const auto& real_sys = __prm->getSystem(sys.name().label());
145 
146  for (auto& ass: sys.assignments()) {
147  auto leftInstance = ass.leftInstance().label();
148  auto leftReference = ass.leftReference().label();
149  auto rightInstance = ass.rightInstance().label();
150 
151  if (ass.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
152  std::stringstream sBuff;
153  sBuff << leftInstance << "[" << ass.leftIndex().value() << "]";
154  leftInstance = sBuff.str();
155  }
156 
157  if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
158  std::stringstream sBuff;
159  sBuff << rightInstance << "[" << ass.rightIndex().value() << "]";
160  rightInstance = sBuff.str();
161  }
162 
163  factory.setReferenceSlot(leftInstance, leftReference, rightInstance);
164  }
165  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __addIncrements()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addIncrements ( PRMFactory< GUM_SCALAR > &  factory,
O3System sys 
)
private

Definition at line 168 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3System::increments(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3System::name(), and gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

169  {
170  const auto& real_sys = __prm->getSystem(sys.name().label());
171  for (auto& inc: sys.increments()) {
172  auto leftInstance = inc.leftInstance().label();
173  auto leftReference = inc.leftReference().label();
174  auto rightInstance = inc.rightInstance().label();
175 
176  if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
177  std::stringstream sBuff;
178  sBuff << leftInstance << "[" << inc.leftIndex().value() << "]";
179  leftInstance = sBuff.str();
180  }
181 
182  if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
183  std::stringstream sBuff;
184  sBuff << rightInstance << "[" << inc.rightIndex().value() << "]";
185  rightInstance = sBuff.str();
186  }
187 
188  factory.setReferenceSlot(leftInstance, leftReference, rightInstance);
189  }
190  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __addInstances()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addInstances ( PRMFactory< GUM_SCALAR > &  factory,
O3System sys 
)
private

Definition at line 120 of file O3SystemFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addArray(), gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), gum::HashTable< Key, Val, Alloc >::insert(), and gum::prm::o3prm::O3System::instances().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

121  {
122  for (auto& i: sys.instances()) {
123  if (i.parameters().size() > 0) {
124  auto params = HashTable< std::string, double >();
125  for (auto& p: i.parameters()) {
126  params.insert(p.name().label(), (double)p.value().value());
127  }
128  factory.addInstance(i.type().label(), i.name().label(), params);
129 
130  } else {
131  if (i.size().value() > 1) {
132  factory.addArray(
133  i.type().label(), i.name().label(), i.size().value());
134  } else {
135  factory.addInstance(i.type().label(), i.name().label());
136  }
137  }
138  }
139  }
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __checkAssignments()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkAssignments ( O3System sys)
private

Definition at line 269 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3System::assignments().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem().

269  {
270  for (auto& ass: sys.assignments()) {
271  // if ( ass.leftInstance().label() == ass.leftReference().label() ) {
272  // O3PRM_SYSTEM_INVALID_LEFT_VALUE( ass.leftInstance(), *__errors );
273  // return false;
274  //}
275 
276  if (!__nameMap.exists(ass.leftInstance().label())) {
277  O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.leftInstance(), *__errors);
278  return false;
279  }
280 
281  auto i = __nameMap[ass.leftInstance().label()];
282  const auto& type = __prm->getClass(i->type().label());
283  const auto& ref = ass.leftReference().label();
284 
285  if (!(type.exists(ass.leftReference().label())
287  type.get(ref)))) {
288  O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
289  ass.leftReference(), type.name(), *__errors);
290  return false;
291  }
292 
293  const auto& real_ref =
294  static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(type.get(ref));
295 
296  if (!__nameMap.exists(ass.rightInstance().label())) {
297  O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.rightInstance(), *__errors);
298  return false;
299  }
300 
301  if (real_ref.isArray()
302  && __nameMap[ass.rightInstance().label()]->size().value() == 0) {
303  O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *__errors);
304  return false;
305  }
306 
307  if ((!real_ref.isArray())
308  && __nameMap[ass.rightInstance().label()]->size().value() > 0
309  && ass.rightIndex().value() == -1) {
310  O3PRM_SYSTEM_NOT_AN_ARRAY(ass.leftReference(), *__errors);
311  return false;
312  }
313  }
314  return true;
315  }
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
HashTable< std::string, O3Instance *> __nameMap
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __checkIncrements()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkIncrements ( O3System sys)
private

Definition at line 318 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3System::increments().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem().

318  {
319  for (auto& inc: sys.increments()) {
320  // if ( inc.leftInstance().label() == inc.leftReference().label() ) {
321  // O3PRM_SYSTEM_INVALID_LEFT_VALUE( inc.leftInstance(), *__errors );
322  // return false;
323  //}
324 
325  if (!__nameMap.exists(inc.leftInstance().label())) {
326  O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *__errors);
327  return false;
328  }
329 
330  auto i = __nameMap[inc.leftInstance().label()];
331  const auto& type = __prm->getClass(i->type().label());
332  const auto& ref = inc.leftReference().label();
333 
334  if (!(type.exists(inc.leftReference().label())
336  type.get(ref)))) {
337  O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
338  inc.leftReference(), type.name(), *__errors);
339  return false;
340  }
341 
342  const auto& real_ref =
343  static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(type.get(ref));
344 
345  if (!real_ref.isArray()) {
346  O3PRM_SYSTEM_NOT_AN_ARRAY(inc.leftReference(), *__errors);
347  return false;
348  }
349  }
350 
351  return true;
352  }
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
HashTable< std::string, O3Instance *> __nameMap
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __checkInstance()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkInstance ( O3System sys)
private

Definition at line 203 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkParameters(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__solver, and gum::prm::o3prm::O3System::instances().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem().

203  {
204  for (auto& i: sys.instances()) {
205  if (!__solver->resolveClass(i.type())) { return false; }
206 
207  const auto& type = __prm->getClass(i.type().label());
208  if (type.parameters().size() > 0) {
209  if (!__checkParameters(type, i)) { return false; }
210  }
211 
212  if (__nameMap.exists(i.name().label())) {
213  O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *__errors);
214  return false;
215  }
216 
217  __nameMap.insert(i.name().label(), &i);
218  }
219 
220  return true;
221  }
bool __checkParameters(const PRMClass< GUM_SCALAR > &type, const O3Instance &inst)
O3NameSolver< GUM_SCALAR > * __solver
HashTable< std::string, O3Instance *> __nameMap
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __checkParameters()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkParameters ( const PRMClass< GUM_SCALAR > &  type,
const O3Instance inst 
)
private

Definition at line 224 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), GUM_ERROR, and gum::prm::o3prm::O3Instance::parameters().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkInstance().

225  {
226  for (const auto& param: inst.parameters()) {
227  if (!type.exists(param.name().label())) {
228  O3PRM_SYSTEM_PARAMETER_NOT_FOUND(param, *__errors);
229  return false;
230  }
231 
233  type.get(param.name().label()))) {
234  O3PRM_SYSTEM_NOT_A_PARAMETER(param, *__errors);
235  return false;
236  }
237 
238  const auto& type_param =
239  static_cast< const PRMParameter< GUM_SCALAR >& >(
240  type.get(param.name().label()));
241 
242  switch (type_param.valueType()) {
243  case PRMParameter< GUM_SCALAR >::ParameterType::INT: {
244  if (!param.isInteger()) {
245  O3PRM_SYSTEM_PARAMETER_NOT_INT(param, *__errors);
246  return false;
247  }
248  break;
249  }
250 
251  case PRMParameter< GUM_SCALAR >::ParameterType::REAL: {
252  if (param.isInteger()) {
253  O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(param, *__errors);
254  return false;
255  }
256  break;
257  }
258 
259  default: {
260  GUM_ERROR(FatalError, "unknown parameter type");
261  }
262  }
263  }
264  return true;
265  }
static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMParameter.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __checkSystem()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem ( O3System sys)
private

Definition at line 193 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkAssignments(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkIncrements(), and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkInstance().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

193  {
194  if (__checkInstance(sys) && __checkAssignments(sys)
195  && __checkIncrements(sys)) {
196  return true;
197  }
198 
199  return false;
200  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ build()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build ( )

Definition at line 96 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addAssignments(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addIncrements(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addInstances(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__checkSystem(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__nameMap, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::endSystem(), gum::prm::PRMFactory< GUM_SCALAR >::startSystem(), and gum::prm::o3prm::O3PRM::systems().

96  {
97  PRMFactory< GUM_SCALAR > factory(__prm);
98 
99  for (auto& sys: __o3_prm->systems()) {
100  // Reseting name map for each system
101  __nameMap = HashTable< std::string, O3Instance* >();
102 
103  if (__checkSystem(*sys)) {
104  factory.startSystem(sys->name().label());
105 
106  __addInstances(factory, *sys);
107  __addAssignments(factory, *sys);
108  __addIncrements(factory, *sys);
109 
110  try {
111  factory.endSystem();
112  } catch (FatalError&) {
113  O3PRM_SYSTEM_INSTANTIATION_FAILED(*sys, *__errors);
114  }
115  }
116  }
117  }
void __addIncrements(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
void __addAssignments(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
O3SystemList & systems()
Definition: O3prm.cpp:507
HashTable< std::string, O3Instance *> __nameMap
void __addInstances(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
+ Here is the call graph for this function:

◆ operator=() [1/2]

template<typename GUM_SCALAR >
INLINE O3SystemFactory< GUM_SCALAR > & gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::operator= ( const O3SystemFactory< GUM_SCALAR > &  src)

Definition at line 73 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__solver.

74  {
75  if (this == &src) { return *this; }
76  __prm = src.__prm;
77  __o3_prm = src.__o3_prm;
78  __solver = src.__solver;
79  __errors = src.__errors;
80  return *this;
81  }
O3NameSolver< GUM_SCALAR > * __solver

◆ operator=() [2/2]

template<typename GUM_SCALAR >
INLINE O3SystemFactory< GUM_SCALAR > & gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::operator= ( O3SystemFactory< GUM_SCALAR > &&  src)

Definition at line 85 of file O3SystemFactory_tpl.h.

References gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__errors, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__o3_prm, gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__prm, and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__solver.

86  {
87  if (this == &src) { return *this; }
88  __prm = std::move(src.__prm);
89  __o3_prm = std::move(src.__o3_prm);
90  __solver = std::move(src.__solver);
91  __errors = std::move(src.__errors);
92  return *this;
93  }
O3NameSolver< GUM_SCALAR > * __solver

Member Data Documentation

◆ __errors

◆ __nameMap

◆ __o3_prm

template<typename GUM_SCALAR>
O3PRM* gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__o3_prm
private

◆ __prm

◆ __solver

template<typename GUM_SCALAR>
O3NameSolver< GUM_SCALAR >* gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__solver
private

The documentation for this class was generated from the following files: