aGrUM 3.2.0
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 153 of file O3SystemFactory_tpl.h.

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

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 175 of file O3SystemFactory_tpl.h.

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

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 132 of file O3SystemFactory_tpl.h.

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

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 268 of file O3SystemFactory_tpl.h.

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

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 313 of file O3SystemFactory_tpl.h.

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

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 205 of file O3SystemFactory_tpl.h.

205 {
206 for (auto& i: sys.instances()) {
207 if (!_solver_->resolveClass(i.type())) { return false; }
208
209 const auto& type = _prm_->getClass(i.type().label());
210 if (type.parameters().size() > 0) {
211 if (!_checkParameters_(type, i)) { return false; }
212 }
213
214 if (_nameMap_.exists(i.name().label())) {
216 return false;
217 }
218
219 _nameMap_.insert(i.name().label(), &i);
220 }
221
222 return true;
223 }
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 226 of file O3SystemFactory_tpl.h.

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

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 196 of file O3SystemFactory_tpl.h.

196 {
198 return true;
199 }
200
201 return false;
202 }

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();
127 }
128 }
129 }
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: