58 template < GUM_Numeric GUM_SCALAR >
67 template < GUM_Numeric GUM_SCALAR >
74 template < GUM_Numeric GUM_SCALAR >
82 template < GUM_Numeric GUM_SCALAR >
87 template < GUM_Numeric GUM_SCALAR >
90 if (
this == &src) {
return *
this; }
98 template < GUM_Numeric GUM_SCALAR >
101 if (
this == &src) {
return *
this; }
102 _prm_ = std::move(src._prm_);
109 template < GUM_Numeric GUM_SCALAR >
113 for (
auto& sys:
_o3_prm_->systems()) {
127 O3PRM_SYSTEM_INSTANTIATION_FAILED(*sys, O3PRM_EXCEPTION_MESSAGE(e), *
_errors_);
133 template < GUM_Numeric GUM_SCALAR >
137 if (i.parameters().size() > 0) {
139 for (
auto& p: i.parameters()) {
140 params.insert(p.name().label(), (
double)p.value().value());
142 factory.
addInstance(i.type().label(), i.name().label(), params);
145 if (i.size().value() > 1) {
146 factory.
addArray(i.type().label(), i.name().label(), i.size().value());
148 factory.
addInstance(i.type().label(), i.name().label());
154 template < GUM_Numeric GUM_SCALAR >
160 auto leftInstance = ass.leftInstance().label();
161 auto leftReference = ass.leftReference().label();
162 auto rightInstance = ass.rightInstance().label();
164 if (ass.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
165 leftInstance = std::format(
"{}[{}]", leftInstance, ass.leftIndex().value());
168 if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
169 rightInstance = std::format(
"{}[{}]", rightInstance, ass.rightIndex().value());
176 template < GUM_Numeric GUM_SCALAR >
181 auto leftInstance = inc.leftInstance().label();
182 auto leftReference = inc.leftReference().label();
183 auto rightInstance = inc.rightInstance().label();
185 if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
186 leftInstance = std::format(
"{}[{}]", leftInstance, inc.leftIndex().value());
189 if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
190 rightInstance = std::format(
"{}[{}]", rightInstance, inc.rightIndex().value());
197 template < GUM_Numeric GUM_SCALAR >
206 template < GUM_Numeric GUM_SCALAR >
209 if (!
_solver_->resolveClass(i.type())) {
return false; }
211 const auto& type =
_prm_->getClass(i.type().label());
212 if (type.parameters().size() > 0) {
216 if (
_nameMap_.exists(i.name().label())) {
217 O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *
_errors_);
227 template < GUM_Numeric GUM_SCALAR >
231 if (!type.
exists(param.name().label())) {
232 O3PRM_SYSTEM_PARAMETER_NOT_FOUND(param, *
_errors_);
237 O3PRM_SYSTEM_NOT_A_PARAMETER(param, *
_errors_);
241 const auto& type_param
244 switch (type_param.valueType()) {
246 if (!param.isInteger()) {
247 O3PRM_SYSTEM_PARAMETER_NOT_INT(param, *
_errors_);
254 if (param.isInteger()) {
255 O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(param, *
_errors_);
269 template < GUM_Numeric GUM_SCALAR >
277 if (!
_nameMap_.exists(ass.leftInstance().label())) {
278 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.leftInstance(), *
_errors_);
282 auto i =
_nameMap_[ass.leftInstance().label()];
283 const auto& type =
_prm_->getClass(i->type().label());
284 const auto& ref = ass.leftReference().label();
286 if (!(type.exists(ass.leftReference().label())
288 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(ass.leftReference(), type.name(), *
_errors_);
295 if (!
_nameMap_.exists(ass.rightInstance().label())) {
296 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.rightInstance(), *
_errors_);
300 if (real_ref.isArray() &&
_nameMap_[ass.rightInstance().label()]->size().value() == 0) {
301 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *
_errors_);
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_);
314 template < GUM_Numeric GUM_SCALAR >
322 if (!
_nameMap_.exists(inc.leftInstance().label())) {
323 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *
_errors_);
327 auto i =
_nameMap_[inc.leftInstance().label()];
328 const auto& type =
_prm_->getClass(i->type().label());
329 const auto& ref = inc.leftReference().label();
331 if (!(type.exists(inc.leftReference().label())
333 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(inc.leftReference(), type.name(), *
_errors_);
340 if (!real_ref.isArray()) {
341 O3PRM_SYSTEM_NOT_AN_ARRAY(inc.leftReference(), *
_errors_);
Headers for the O3SystemFactory class.
This class is used contain and manipulate gum::ParseError.
Exception : fatal (unknown ?) error.
The class for generic Hash Tables.
virtual bool exists(std::string_view name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMParameter.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
PRMClassElement< GUM_SCALAR > & get(NodeId id) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
Factory which builds a PRM<GUM_SCALAR>.
void setReferenceSlot(std::string_view left_instance, std::string_view left_reference, std::string_view right_instance) override
Instantiate a reference in the current model.
void startSystem(std::string_view name) override
Tells the factory that we started declaring a model.
void addInstance(std::string_view type, std::string_view name) override
Add an instance to the model.
void endSystem() override
Tells the factory that we finished declaring a model.
void addArray(std::string_view type, std::string_view name, Size size) override
Creates an array with the given number of instances of the given type.
PRMParameter is a member of a Class in a PRM.
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
The O3Instance is part of the AST of the O3PRM language.
O3InstanceParameterList & parameters()
Resolves names for the different O3PRM factories.
The O3PRM is part of the AST of the O3PRM language.
Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System.
bool _checkSystem_(O3System &sys)
void _addInstances_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
O3SystemFactory< GUM_SCALAR > & operator=(const O3SystemFactory< GUM_SCALAR > &src)
bool _checkParameters_(const PRMClass< GUM_SCALAR > &type, const O3Instance &inst)
PRM< GUM_SCALAR > * _prm_
bool _checkAssignments_(O3System &sys)
void _addAssignments_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
bool _checkInstance_(O3System &sys)
ErrorsContainer * _errors_
HashTable< std::string, O3Instance * > _nameMap_
void _addIncrements_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
O3NameSolver< GUM_SCALAR > * _solver_
bool _checkIncrements_(O3System &sys)
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
The O3System is part of the AST of the O3PRM language.
O3AssignmentList & assignments()
O3InstanceList & instances()
O3IncrementList & increments()
#define GUM_ERROR(type, msg)
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities