aGrUM 3.3.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 >:
[legend]

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 ()

Private Member Functions

void _addInstances_ (PRMFactory< GUM_SCALAR > &factory, O3System &sys)
void _addAssignments_ (PRMFactory< GUM_SCALAR > &factory, O3System &sys)
void _addIncrements_ (PRMFactory< GUM_SCALAR > &factory, O3System &sys)
bool _checkSystem_ (O3System &sys)
bool _checkIncrements_ (O3System &sys)
bool _checkParameters_ (const PRMClass< GUM_SCALAR > &type, const O3Instance &inst)
bool _checkInstance_ (O3System &sys)
bool _checkAssignments_ (O3System &sys)

Private Attributes

PRM< GUM_SCALAR > * _prm_
O3PRM * _o3_prm_
O3NameSolver< GUM_SCALAR > * _solver_
ErrorsContainer * _errors_
HashTable< std::string, O3Instance * > _nameMap_

Detailed Description

template<GUM_Numeric 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 73 of file O3SystemFactory.h.

Constructor & Destructor Documentation

◆ O3SystemFactory() [1/3]

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

Definition at line 59 of file O3SystemFactory_tpl.h.

62 :
65 }
Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System.
O3NameSolver< GUM_SCALAR > * _solver_
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

References O3SystemFactory(), _errors_, _o3_prm_, _prm_, and _solver_.

Referenced by O3SystemFactory(), O3SystemFactory(), O3SystemFactory(), ~O3SystemFactory(), gum::prm::o3prm::O3prmReader< GUM_SCALAR >::_readStream_(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ O3SystemFactory() [2/3]

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

Definition at line 68 of file O3SystemFactory_tpl.h.

References O3SystemFactory(), _errors_, _nameMap_, _o3_prm_, _prm_, and _solver_.

Here is the call graph for this function:

◆ O3SystemFactory() [3/3]

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

Definition at line 75 of file O3SystemFactory_tpl.h.

References O3SystemFactory(), _errors_, _nameMap_, _o3_prm_, _prm_, and _solver_.

Here is the call graph for this function:

◆ ~O3SystemFactory()

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

Definition at line 83 of file O3SystemFactory_tpl.h.

References O3SystemFactory().

Here is the call graph for this function:

Member Function Documentation

◆ _addAssignments_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_addAssignments_ ( PRMFactory< GUM_SCALAR > & factory,
O3System & sys )
private

Definition at line 155 of file O3SystemFactory_tpl.h.

156 {
157 const auto& real_sys = _prm_->getSystem(sys.name().label());
158
159 for (auto& ass: sys.assignments()) {
160 auto leftInstance = ass.leftInstance().label();
161 auto leftReference = ass.leftReference().label();
162 auto rightInstance = ass.rightInstance().label();
163
164 if (ass.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
165 leftInstance = std::format("{}[{}]", leftInstance, ass.leftIndex().value());
166 }
167
168 if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
169 rightInstance = std::format("{}[{}]", rightInstance, ass.rightIndex().value());
170 }
171
173 }
174 }

References _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 build().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _addIncrements_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_addIncrements_ ( PRMFactory< GUM_SCALAR > & factory,
O3System & sys )
private

Definition at line 177 of file O3SystemFactory_tpl.h.

178 {
179 const auto& real_sys = _prm_->getSystem(sys.name().label());
180 for (auto& inc: sys.increments()) {
181 auto leftInstance = inc.leftInstance().label();
182 auto leftReference = inc.leftReference().label();
183 auto rightInstance = inc.rightInstance().label();
184
185 if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
186 leftInstance = std::format("{}[{}]", leftInstance, inc.leftIndex().value());
187 }
188
189 if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
190 rightInstance = std::format("{}[{}]", rightInstance, inc.rightIndex().value());
191 }
192
194 }
195 }

References _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 build().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _addInstances_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_addInstances_ ( PRMFactory< GUM_SCALAR > & factory,
O3System & sys )
private

Definition at line 134 of file O3SystemFactory_tpl.h.

135 {
136 for (auto& i: sys.instances()) {
137 if (i.parameters().size() > 0) {
139 for (auto& p: i.parameters()) {
140 params.insert(p.name().label(), (double)p.value().value());
141 }
142 factory.addInstance(i.type().label(), i.name().label(), params);
143
144 } else {
145 if (i.size().value() > 1) {
146 factory.addArray(i.type().label(), i.name().label(), i.size().value());
147 } else {
148 factory.addInstance(i.type().label(), i.name().label());
149 }
150 }
151 }
152 }

References gum::prm::PRMFactory< GUM_SCALAR >::addArray(), gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), and gum::prm::o3prm::O3System::instances().

Referenced by build().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkAssignments_()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_checkAssignments_ ( O3System & sys)
private

Definition at line 270 of file O3SystemFactory_tpl.h.

270 {
271 for (auto& ass: sys.assignments()) {
272 // if ( ass.leftInstance().label() == ass.leftReference().label() ) {
273 // O3PRM_SYSTEM_INVALID_LEFT_VALUE( ass.leftInstance(), * _errors_ );
274 // return false;
275 //}
276
277 if (!_nameMap_.exists(ass.leftInstance().label())) {
279 return false;
280 }
281
282 auto i = _nameMap_[ass.leftInstance().label()];
283 const auto& type = _prm_->getClass(i->type().label());
284 const auto& ref = ass.leftReference().label();
285
286 if (!(type.exists(ass.leftReference().label())
288 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(ass.leftReference(), type.name(), *_errors_);
289 return false;
290 }
291
292 const auto& real_ref
293 = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(type.get(ref));
294
295 if (!_nameMap_.exists(ass.rightInstance().label())) {
297 return false;
298 }
299
300 if (real_ref.isArray() && _nameMap_[ass.rightInstance().label()]->size().value() == 0) {
301 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *_errors_);
302 return false;
303 }
304
305 if ((!real_ref.isArray()) && _nameMap_[ass.rightInstance().label()]->size().value() > 0
306 && ass.rightIndex().value() == -1) {
307 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.leftReference(), *_errors_);
308 return false;
309 }
310 }
311 return true;
312 }

References _errors_, _nameMap_, _prm_, gum::prm::o3prm::O3System::assignments(), and gum::prm::PRMClassElement< GUM_SCALAR >::isReferenceSlot().

Referenced by _checkSystem_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkIncrements_()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_checkIncrements_ ( O3System & sys)
private

Definition at line 315 of file O3SystemFactory_tpl.h.

315 {
316 for (auto& inc: sys.increments()) {
317 // if ( inc.leftInstance().label() == inc.leftReference().label() ) {
318 // O3PRM_SYSTEM_INVALID_LEFT_VALUE( inc.leftInstance(), * _errors_ );
319 // return false;
320 //}
321
322 if (!_nameMap_.exists(inc.leftInstance().label())) {
324 return false;
325 }
326
327 auto i = _nameMap_[inc.leftInstance().label()];
328 const auto& type = _prm_->getClass(i->type().label());
329 const auto& ref = inc.leftReference().label();
330
331 if (!(type.exists(inc.leftReference().label())
333 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(inc.leftReference(), type.name(), *_errors_);
334 return false;
335 }
336
337 const auto& real_ref
338 = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(type.get(ref));
339
340 if (!real_ref.isArray()) {
341 O3PRM_SYSTEM_NOT_AN_ARRAY(inc.leftReference(), *_errors_);
342 return false;
343 }
344 }
345
346 return true;
347 }

References _errors_, _nameMap_, _prm_, gum::prm::o3prm::O3System::increments(), and gum::prm::PRMClassElement< GUM_SCALAR >::isReferenceSlot().

Referenced by _checkSystem_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkInstance_()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_checkInstance_ ( O3System & sys)
private

Definition at line 207 of file O3SystemFactory_tpl.h.

207 {
208 for (auto& i: sys.instances()) {
209 if (!_solver_->resolveClass(i.type())) { return false; }
210
211 const auto& type = _prm_->getClass(i.type().label());
212 if (type.parameters().size() > 0) {
213 if (!_checkParameters_(type, i)) { return false; }
214 }
215
216 if (_nameMap_.exists(i.name().label())) {
218 return false;
219 }
220
221 _nameMap_.insert(i.name().label(), &i);
222 }
223
224 return true;
225 }
bool _checkParameters_(const PRMClass< GUM_SCALAR > &type, const O3Instance &inst)

References _checkParameters_(), _errors_, _nameMap_, _prm_, _solver_, and gum::prm::o3prm::O3System::instances().

Referenced by _checkSystem_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkParameters_()

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

Definition at line 228 of file O3SystemFactory_tpl.h.

229 {
230 for (const auto& param: inst.parameters()) {
231 if (!type.exists(param.name().label())) {
233 return false;
234 }
235
236 if (!PRMClassElement< GUM_SCALAR >::isParameter(type.get(param.name().label()))) {
238 return false;
239 }
240
241 const auto& type_param
242 = static_cast< const PRMParameter< GUM_SCALAR >& >(type.get(param.name().label()));
243
244 switch (type_param.valueType()) {
246 if (!param.isInteger()) {
248 return false;
249 }
250 break;
251 }
252
254 if (param.isInteger()) {
256 return false;
257 }
258 break;
259 }
260
261 default : {
262 GUM_ERROR(FatalError, "unknown parameter type")
263 }
264 }
265 }
266 return true;
267 }

References _errors_, gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), GUM_ERROR, gum::prm::PRMParameter< GUM_SCALAR >::INT, gum::prm::PRMClassElement< GUM_SCALAR >::isParameter(), gum::prm::o3prm::O3Instance::parameters(), and gum::prm::PRMParameter< GUM_SCALAR >::REAL.

Referenced by _checkInstance_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkSystem_()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_checkSystem_ ( O3System & sys)
private

Definition at line 198 of file O3SystemFactory_tpl.h.

198 {
200 return true;
201 }
202
203 return false;
204 }

References _checkAssignments_(), _checkIncrements_(), and _checkInstance_().

Referenced by build().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ build()

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

Definition at line 110 of file O3SystemFactory_tpl.h.

110 {
112
113 for (auto& sys: _o3_prm_->systems()) {
114 // Reseting name map for each system
116
117 if (_checkSystem_(*sys)) {
118 factory.startSystem(sys->name().label());
119
123
124 try {
125 factory.endSystem();
126 } catch (FatalError const& e) {
128 }
129 }
130 }
131 }
void _addInstances_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
void _addAssignments_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
void _addIncrements_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)

References _addAssignments_(), _addIncrements_(), _addInstances_(), _checkSystem_(), _errors_, _nameMap_, _o3_prm_, _prm_, gum::prm::PRMFactory< GUM_SCALAR >::endSystem(), and gum::prm::PRMFactory< GUM_SCALAR >::startSystem().

Here is the call graph for this function:

◆ operator=() [1/2]

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

Definition at line 89 of file O3SystemFactory_tpl.h.

89 {
90 if (this == &src) { return *this; }
91 _prm_ = src._prm_;
95 return *this;
96 }

References O3SystemFactory(), _errors_, _o3_prm_, _prm_, and _solver_.

Here is the call graph for this function:

◆ operator=() [2/2]

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

Definition at line 100 of file O3SystemFactory_tpl.h.

100 {
101 if (this == &src) { return *this; }
106 return *this;
107 }

References O3SystemFactory(), _errors_, _o3_prm_, _prm_, and _solver_.

Here is the call graph for this function:

Member Data Documentation

◆ _errors_

◆ _nameMap_

template<GUM_Numeric GUM_SCALAR>
HashTable< std::string, O3Instance* > gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_nameMap_
private

◆ _o3_prm_

template<GUM_Numeric GUM_SCALAR>
O3PRM* gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_o3_prm_
private

◆ _prm_

template<GUM_Numeric GUM_SCALAR>
PRM< GUM_SCALAR >* gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_prm_
private

◆ _solver_

template<GUM_Numeric GUM_SCALAR>
O3NameSolver< GUM_SCALAR >* gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_solver_
private

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