37 template <
typename GUM_SCALAR >
44 __o3_prm(&o3_prm), __solver(&solver), __errors(&errors) {
48 template <
typename GUM_SCALAR >
57 template <
typename GUM_SCALAR >
66 template <
typename GUM_SCALAR >
71 template <
typename GUM_SCALAR >
75 if (
this == &src) {
return *
this; }
83 template <
typename GUM_SCALAR >
87 if (
this == &src) {
return *
this; }
88 __prm = std::move(src.__prm);
95 template <
typename GUM_SCALAR >
113 O3PRM_SYSTEM_INSTANTIATION_FAILED(*sys, *
__errors);
119 template <
typename GUM_SCALAR >
123 if (i.parameters().size() > 0) {
125 for (
auto& p: i.parameters()) {
126 params.
insert(p.name().label(), (
double)p.value().value());
128 factory.
addInstance(i.type().label(), i.name().label(), params);
131 if (i.size().value() > 1) {
133 i.type().label(), i.name().label(), i.size().value());
135 factory.
addInstance(i.type().label(), i.name().label());
141 template <
typename GUM_SCALAR >
147 auto leftInstance = ass.leftInstance().label();
148 auto leftReference = ass.leftReference().label();
149 auto rightInstance = ass.rightInstance().label();
151 if (ass.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
152 std::stringstream sBuff;
153 sBuff << leftInstance <<
"[" << ass.leftIndex().value() <<
"]";
154 leftInstance = sBuff.str();
157 if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
158 std::stringstream sBuff;
159 sBuff << rightInstance <<
"[" << ass.rightIndex().value() <<
"]";
160 rightInstance = sBuff.str();
167 template <
typename GUM_SCALAR >
172 auto leftInstance = inc.leftInstance().label();
173 auto leftReference = inc.leftReference().label();
174 auto rightInstance = inc.rightInstance().label();
176 if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
177 std::stringstream sBuff;
178 sBuff << leftInstance <<
"[" << inc.leftIndex().value() <<
"]";
179 leftInstance = sBuff.str();
182 if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
183 std::stringstream sBuff;
184 sBuff << rightInstance <<
"[" << inc.rightIndex().value() <<
"]";
185 rightInstance = sBuff.str();
192 template <
typename GUM_SCALAR >
202 template <
typename GUM_SCALAR >
205 if (!
__solver->resolveClass(i.type())) {
return false; }
207 const auto& type =
__prm->getClass(i.type().label());
208 if (type.parameters().size() > 0) {
212 if (
__nameMap.exists(i.name().label())) {
213 O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *
__errors);
223 template <
typename GUM_SCALAR >
227 if (!type.
exists(param.name().label())) {
228 O3PRM_SYSTEM_PARAMETER_NOT_FOUND(param, *
__errors);
233 type.
get(param.name().label()))) {
234 O3PRM_SYSTEM_NOT_A_PARAMETER(param, *
__errors);
238 const auto& type_param =
240 type.
get(param.name().label()));
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 <
typename GUM_SCALAR >
276 if (!
__nameMap.exists(ass.leftInstance().label())) {
277 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.leftInstance(), *
__errors);
281 auto i =
__nameMap[ass.leftInstance().label()];
282 const auto& type =
__prm->getClass(i->type().label());
283 const auto& ref = ass.leftReference().label();
285 if (!(type.exists(ass.leftReference().label())
288 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
289 ass.leftReference(), type.name(), *
__errors);
293 const auto& real_ref =
296 if (!
__nameMap.exists(ass.rightInstance().label())) {
297 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.rightInstance(), *
__errors);
301 if (real_ref.isArray()
302 &&
__nameMap[ass.rightInstance().label()]->size().value() == 0) {
303 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *
__errors);
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);
317 template <
typename GUM_SCALAR >
325 if (!
__nameMap.exists(inc.leftInstance().label())) {
326 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *
__errors);
330 auto i =
__nameMap[inc.leftInstance().label()];
331 const auto& type =
__prm->getClass(i->type().label());
332 const auto& ref = inc.leftReference().label();
334 if (!(type.exists(inc.leftReference().label())
337 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
338 inc.leftReference(), type.name(), *
__errors);
342 const auto& real_ref =
345 if (!real_ref.isArray()) {
346 O3PRM_SYSTEM_NOT_AN_ARRAY(inc.leftReference(), *
__errors);
O3IncrementList & increments()
PRMParameter is a member of a Class in a PRM.
virtual void setReferenceSlot(const std::string &left_instance, const std::string &left_reference, const std::string &right_instance) override
Instantiate a reference in the current model.
bool __checkParameters(const PRMClass< GUM_SCALAR > &type, const O3Instance &inst)
virtual void addInstance(const std::string &type, const std::string &name) override
Add an instance to the model.
virtual void addArray(const std::string &type, const std::string &name, Size size) override
Creates an array with the given number of instances of the given type.
void __addIncrements(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Abstract class representing an element of PRM class.
O3InstanceParameterList & parameters()
bool __checkInstance(O3System &sys)
O3InstanceList & instances()
O3NameSolver< GUM_SCALAR > * __solver
This class is used contain and manipulate gum::ParseError.
virtual bool exists(const std::string &name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Builds gum::prm::PRMSystem from gum::prm::o3prm::O3System.
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
The class for generic Hash Tables.
virtual void startSystem(const std::string &name) override
Tells the factory that we started declaring a model.
Resolves names for the different O3PRM factories.
Factory which builds a PRM<GUM_SCALAR>.
The O3Instance is part of the AST of the O3PRM language.
O3AssignmentList & assignments()
PRMClassElement< GUM_SCALAR > & get(NodeId id)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
void __addAssignments(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
The O3System is part of the AST of the O3PRM language.
bool __checkAssignments(O3System &sys)
HashTable< std::string, O3Instance *> __nameMap
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
bool __checkSystem(O3System &sys)
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
void __addInstances(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
bool __checkIncrements(O3System &sys)
O3SystemFactory< GUM_SCALAR > & operator=(const O3SystemFactory< GUM_SCALAR > &src)
PRM< GUM_SCALAR > * __prm
ErrorsContainer * __errors
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
The O3PRM is part of the AST of the O3PRM language.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
virtual void endSystem() override
Tells the factory that we finished declaring a model.
#define GUM_ERROR(type, msg)