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 >
74 if (
this == &src) {
return *
this; }
82 template <
typename GUM_SCALAR >
85 if (
this == &src) {
return *
this; }
86 __prm = std::move(src.__prm);
93 template <
typename GUM_SCALAR >
111 O3PRM_SYSTEM_INSTANTIATION_FAILED(*sys, *
__errors);
117 template <
typename GUM_SCALAR >
121 if (i.parameters().size() > 0) {
123 for (
auto& p : i.parameters()) {
124 params.
insert(p.name().label(), (
double)p.value().value());
126 factory.
addInstance(i.type().label(), i.name().label(), params);
129 if (i.size().value() > 1) {
131 i.type().label(), i.name().label(), i.size().value());
133 factory.
addInstance(i.type().label(), i.name().label());
139 template <
typename GUM_SCALAR >
145 auto leftInstance = ass.leftInstance().label();
146 auto leftReference = ass.leftReference().label();
147 auto rightInstance = ass.rightInstance().label();
149 if (ass.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
150 std::stringstream sBuff;
151 sBuff << leftInstance <<
"[" << ass.leftIndex().value() <<
"]";
152 leftInstance = sBuff.str();
155 if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
156 std::stringstream sBuff;
157 sBuff << rightInstance <<
"[" << ass.rightIndex().value() <<
"]";
158 rightInstance = sBuff.str();
165 template <
typename GUM_SCALAR >
170 auto leftInstance = inc.leftInstance().label();
171 auto leftReference = inc.leftReference().label();
172 auto rightInstance = inc.rightInstance().label();
174 if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
175 std::stringstream sBuff;
176 sBuff << leftInstance <<
"[" << inc.leftIndex().value() <<
"]";
177 leftInstance = sBuff.str();
180 if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
181 std::stringstream sBuff;
182 sBuff << rightInstance <<
"[" << inc.rightIndex().value() <<
"]";
183 rightInstance = sBuff.str();
190 template <
typename GUM_SCALAR >
200 template <
typename GUM_SCALAR >
203 if (!
__solver->resolveClass(i.type())) {
return false; }
205 const auto& type =
__prm->getClass(i.type().label());
206 if (type.parameters().size() > 0) {
210 if (
__nameMap.exists(i.name().label())) {
211 O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *
__errors);
221 template <
typename GUM_SCALAR >
225 if (!type.
exists(param.name().label())) {
226 O3PRM_SYSTEM_PARAMETER_NOT_FOUND(param, *
__errors);
231 type.
get(param.name().label()))) {
232 O3PRM_SYSTEM_NOT_A_PARAMETER(param, *
__errors);
236 const auto& type_param =
238 type.
get(param.name().label()));
240 switch (type_param.valueType()) {
242 if (!param.isInteger()) {
243 O3PRM_SYSTEM_PARAMETER_NOT_INT(param, *
__errors);
250 if (param.isInteger()) {
251 O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(param, *
__errors);
265 template <
typename GUM_SCALAR >
274 if (!
__nameMap.exists(ass.leftInstance().label())) {
275 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.leftInstance(), *
__errors);
279 auto i =
__nameMap[ass.leftInstance().label()];
280 const auto& type =
__prm->getClass(i->type().label());
281 const auto& ref = ass.leftReference().label();
283 if (!(type.exists(ass.leftReference().label())
286 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
287 ass.leftReference(), type.name(), *
__errors);
291 const auto& real_ref =
294 if (!
__nameMap.exists(ass.rightInstance().label())) {
295 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.rightInstance(), *
__errors);
299 if (real_ref.isArray()
300 &&
__nameMap[ass.rightInstance().label()]->size().value() == 0) {
301 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *
__errors);
305 if ((!real_ref.isArray())
306 &&
__nameMap[ass.rightInstance().label()]->size().value() > 0
307 && ass.rightIndex().value() == -1) {
308 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.leftReference(), *
__errors);
315 template <
typename GUM_SCALAR >
323 if (!
__nameMap.exists(inc.leftInstance().label())) {
324 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *
__errors);
328 auto i =
__nameMap[inc.leftInstance().label()];
329 const auto& type =
__prm->getClass(i->type().label());
330 const auto& ref = inc.leftReference().label();
332 if (!(type.exists(inc.leftReference().label())
335 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
336 inc.leftReference(), type.name(), *
__errors);
340 const auto& real_ref =
343 if (!real_ref.isArray()) {
344 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-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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)