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()) {
131 template < GUM_Numeric GUM_SCALAR >
135 if (i.parameters().size() > 0) {
137 for (
auto& p: i.parameters()) {
138 params.insert(p.name().label(), (
double)p.value().value());
140 factory.
addInstance(i.type().label(), i.name().label(), params);
143 if (i.size().value() > 1) {
144 factory.
addArray(i.type().label(), i.name().label(), i.size().value());
146 factory.
addInstance(i.type().label(), i.name().label());
152 template < GUM_Numeric GUM_SCALAR >
158 auto leftInstance = ass.leftInstance().label();
159 auto leftReference = ass.leftReference().label();
160 auto rightInstance = ass.rightInstance().label();
162 if (ass.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
163 leftInstance = std::format(
"{}[{}]", leftInstance, ass.leftIndex().value());
166 if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
167 rightInstance = std::format(
"{}[{}]", rightInstance, ass.rightIndex().value());
174 template < GUM_Numeric GUM_SCALAR >
179 auto leftInstance = inc.leftInstance().label();
180 auto leftReference = inc.leftReference().label();
181 auto rightInstance = inc.rightInstance().label();
183 if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
184 leftInstance = std::format(
"{}[{}]", leftInstance, inc.leftIndex().value());
187 if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
188 rightInstance = std::format(
"{}[{}]", rightInstance, inc.rightIndex().value());
195 template < GUM_Numeric GUM_SCALAR >
204 template < GUM_Numeric GUM_SCALAR >
207 if (!
_solver_->resolveClass(i.type())) {
return false; }
209 const auto& type =
_prm_->getClass(i.type().label());
210 if (type.parameters().size() > 0) {
214 if (
_nameMap_.exists(i.name().label())) {
215 O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *
_errors_);
225 template < GUM_Numeric GUM_SCALAR >
229 if (!type.
exists(param.name().label())) {
230 O3PRM_SYSTEM_PARAMETER_NOT_FOUND(param, *
_errors_);
235 O3PRM_SYSTEM_NOT_A_PARAMETER(param, *
_errors_);
239 const auto& type_param
242 switch (type_param.valueType()) {
244 if (!param.isInteger()) {
245 O3PRM_SYSTEM_PARAMETER_NOT_INT(param, *
_errors_);
252 if (param.isInteger()) {
253 O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(param, *
_errors_);
267 template < GUM_Numeric GUM_SCALAR >
275 if (!
_nameMap_.exists(ass.leftInstance().label())) {
276 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.leftInstance(), *
_errors_);
280 auto i =
_nameMap_[ass.leftInstance().label()];
281 const auto& type =
_prm_->getClass(i->type().label());
282 const auto& ref = ass.leftReference().label();
284 if (!(type.exists(ass.leftReference().label())
286 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(ass.leftReference(), type.name(), *
_errors_);
293 if (!
_nameMap_.exists(ass.rightInstance().label())) {
294 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.rightInstance(), *
_errors_);
298 if (real_ref.isArray() &&
_nameMap_[ass.rightInstance().label()]->size().value() == 0) {
299 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *
_errors_);
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_);
312 template < GUM_Numeric GUM_SCALAR >
320 if (!
_nameMap_.exists(inc.leftInstance().label())) {
321 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *
_errors_);
325 auto i =
_nameMap_[inc.leftInstance().label()];
326 const auto& type =
_prm_->getClass(i->type().label());
327 const auto& ref = inc.leftReference().label();
329 if (!(type.exists(inc.leftReference().label())
331 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(inc.leftReference(), type.name(), *
_errors_);
338 if (!real_ref.isArray()) {
339 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