35 template <
typename GUM_SCALAR >
42 __o3_prm(&o3_prm), __solver(&solver), __errors(&errors) {
46 template <
typename GUM_SCALAR >
55 template <
typename GUM_SCALAR >
64 template <
typename GUM_SCALAR >
69 template <
typename GUM_SCALAR >
72 if (
this == &src) {
return *
this; }
80 template <
typename GUM_SCALAR >
83 if (
this == &src) {
return *
this; }
84 __prm = std::move(src.__prm);
91 template <
typename GUM_SCALAR >
109 O3PRM_SYSTEM_INSTANTIATION_FAILED(*sys, *
__errors);
115 template <
typename GUM_SCALAR >
119 if (i.parameters().size() > 0) {
121 for (
auto& p : i.parameters()) {
122 params.
insert(p.name().label(), (
double)p.value().value());
124 factory.
addInstance(i.type().label(), i.name().label(), params);
127 if (i.size().value() > 1) {
129 i.type().label(), i.name().label(), i.size().value());
131 factory.
addInstance(i.type().label(), i.name().label());
137 template <
typename GUM_SCALAR >
143 auto leftInstance = ass.leftInstance().label();
144 auto leftReference = ass.leftReference().label();
145 auto rightInstance = ass.rightInstance().label();
147 if (ass.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
148 std::stringstream sBuff;
149 sBuff << leftInstance <<
"[" << ass.leftIndex().value() <<
"]";
150 leftInstance = sBuff.str();
153 if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
154 std::stringstream sBuff;
155 sBuff << rightInstance <<
"[" << ass.rightIndex().value() <<
"]";
156 rightInstance = sBuff.str();
163 template <
typename GUM_SCALAR >
168 auto leftInstance = inc.leftInstance().label();
169 auto leftReference = inc.leftReference().label();
170 auto rightInstance = inc.rightInstance().label();
172 if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
173 std::stringstream sBuff;
174 sBuff << leftInstance <<
"[" << inc.leftIndex().value() <<
"]";
175 leftInstance = sBuff.str();
178 if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
179 std::stringstream sBuff;
180 sBuff << rightInstance <<
"[" << inc.rightIndex().value() <<
"]";
181 rightInstance = sBuff.str();
188 template <
typename GUM_SCALAR >
198 template <
typename GUM_SCALAR >
201 if (!
__solver->resolveClass(i.type())) {
return false; }
203 const auto& type =
__prm->getClass(i.type().label());
204 if (type.parameters().size() > 0) {
208 if (
__nameMap.exists(i.name().label())) {
209 O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *
__errors);
219 template <
typename GUM_SCALAR >
223 if (!type.
exists(param.name().label())) {
224 O3PRM_SYSTEM_PARAMETER_NOT_FOUND(param, *
__errors);
229 type.
get(param.name().label()))) {
230 O3PRM_SYSTEM_NOT_A_PARAMETER(param, *
__errors);
234 const auto& type_param =
236 type.
get(param.name().label()));
238 switch (type_param.valueType()) {
240 if (!param.isInteger()) {
241 O3PRM_SYSTEM_PARAMETER_NOT_INT(param, *
__errors);
248 if (param.isInteger()) {
249 O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(param, *
__errors);
261 template <
typename GUM_SCALAR >
270 if (!
__nameMap.exists(ass.leftInstance().label())) {
271 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.leftInstance(), *
__errors);
275 auto i =
__nameMap[ass.leftInstance().label()];
276 const auto& type =
__prm->getClass(i->type().label());
277 const auto& ref = ass.leftReference().label();
279 if (!(type.exists(ass.leftReference().label())
282 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
283 ass.leftReference(), type.name(), *
__errors);
287 const auto& real_ref =
290 if (!
__nameMap.exists(ass.rightInstance().label())) {
291 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.rightInstance(), *
__errors);
295 if (real_ref.isArray()
296 &&
__nameMap[ass.rightInstance().label()]->size().value() == 0) {
297 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *
__errors);
301 if ((!real_ref.isArray())
302 &&
__nameMap[ass.rightInstance().label()]->size().value() > 0
303 && ass.rightIndex().value() == -1) {
304 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.leftReference(), *
__errors);
311 template <
typename GUM_SCALAR >
319 if (!
__nameMap.exists(inc.leftInstance().label())) {
320 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *
__errors);
324 auto i =
__nameMap[inc.leftInstance().label()];
325 const auto& type =
__prm->getClass(i->type().label());
326 const auto& ref = inc.leftReference().label();
328 if (!(type.exists(inc.leftReference().label())
331 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(
332 inc.leftReference(), type.name(), *
__errors);
336 const auto& real_ref =
339 if (!real_ref.isArray()) {
340 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)
Headers for the O3SystemFactory class.
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...
gum is the global namespace for all aGrUM entities
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)