57 template <
typename GUM_SCALAR >
66 template <
typename GUM_SCALAR >
74 template <
typename GUM_SCALAR >
82 template <
typename GUM_SCALAR >
87 template <
typename GUM_SCALAR >
90 if (
this == &src) {
return *
this; }
98 template <
typename GUM_SCALAR >
101 if (
this == &src) {
return *
this; }
102 _prm_ = std::move(src._prm_);
109 template <
typename GUM_SCALAR >
113 for (
auto& sys:
_o3_prm_->systems()) {
131 template <
typename 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 <
typename 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 std::stringstream sBuff;
164 sBuff << leftInstance <<
"[" << ass.leftIndex().value() <<
"]";
165 leftInstance = sBuff.str();
168 if (ass.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
169 std::stringstream sBuff;
170 sBuff << rightInstance <<
"[" << ass.rightIndex().value() <<
"]";
171 rightInstance = sBuff.str();
178 template <
typename GUM_SCALAR >
183 auto leftInstance = inc.leftInstance().label();
184 auto leftReference = inc.leftReference().label();
185 auto rightInstance = inc.rightInstance().label();
187 if (inc.leftIndex().value() > -1 && real_sys.isArray(leftInstance)) {
188 std::stringstream sBuff;
189 sBuff << leftInstance <<
"[" << inc.leftIndex().value() <<
"]";
190 leftInstance = sBuff.str();
193 if (inc.rightIndex().value() > -1 && real_sys.isArray(rightInstance)) {
194 std::stringstream sBuff;
195 sBuff << rightInstance <<
"[" << inc.rightIndex().value() <<
"]";
196 rightInstance = sBuff.str();
203 template <
typename GUM_SCALAR >
212 template <
typename GUM_SCALAR >
215 if (!
_solver_->resolveClass(i.type())) {
return false; }
217 const auto& type =
_prm_->getClass(i.type().label());
218 if (type.parameters().size() > 0) {
222 if (
_nameMap_.exists(i.name().label())) {
223 O3PRM_SYSTEM_DUPLICATE_INSTANCE(i, *
_errors_);
233 template <
typename GUM_SCALAR >
238 if (!type.
exists(param.name().label())) {
239 O3PRM_SYSTEM_PARAMETER_NOT_FOUND(param, *
_errors_);
244 O3PRM_SYSTEM_NOT_A_PARAMETER(param, *
_errors_);
248 const auto& type_param
251 switch (type_param.valueType()) {
253 if (!param.isInteger()) {
254 O3PRM_SYSTEM_PARAMETER_NOT_INT(param, *
_errors_);
261 if (param.isInteger()) {
262 O3PRM_SYSTEM_PARAMETER_NOT_FLOAT(param, *
_errors_);
276 template <
typename GUM_SCALAR >
284 if (!
_nameMap_.exists(ass.leftInstance().label())) {
285 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.leftInstance(), *
_errors_);
289 auto i =
_nameMap_[ass.leftInstance().label()];
290 const auto& type =
_prm_->getClass(i->type().label());
291 const auto& ref = ass.leftReference().label();
293 if (!(type.exists(ass.leftReference().label())
295 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(ass.leftReference(), type.name(), *
_errors_);
302 if (!
_nameMap_.exists(ass.rightInstance().label())) {
303 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(ass.rightInstance(), *
_errors_);
307 if (real_ref.isArray() &&
_nameMap_[ass.rightInstance().label()]->size().value() == 0) {
308 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.rightInstance(), *
_errors_);
312 if ((!real_ref.isArray()) &&
_nameMap_[ass.rightInstance().label()]->size().value() > 0
313 && ass.rightIndex().value() == -1) {
314 O3PRM_SYSTEM_NOT_AN_ARRAY(ass.leftReference(), *
_errors_);
321 template <
typename GUM_SCALAR >
329 if (!
_nameMap_.exists(inc.leftInstance().label())) {
330 O3PRM_SYSTEM_INSTANCE_NOT_FOUND(inc.leftInstance(), *
_errors_);
334 auto i =
_nameMap_[inc.leftInstance().label()];
335 const auto& type =
_prm_->getClass(i->type().label());
336 const auto& ref = inc.leftReference().label();
338 if (!(type.exists(inc.leftReference().label())
340 O3PRM_SYSTEM_REFERENCE_NOT_FOUND(inc.leftReference(), type.name(), *
_errors_);
347 if (!real_ref.isArray()) {
348 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(const std::string &name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMParameter.
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
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)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
Factory which builds a PRM<GUM_SCALAR>.
virtual void addInstance(const std::string &type, const std::string &name) override
Add an instance to the model.
virtual void endSystem() override
Tells the factory that we finished declaring a model.
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.
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.
virtual void startSystem(const std::string &name) override
Tells the factory that we started declaring a model.
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 _checkParameters_(const PRMClass< GUM_SCALAR > &type, const O3Instance &inst)
void _addIncrements_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
O3SystemFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
PRM< GUM_SCALAR > * _prm_
O3SystemFactory< GUM_SCALAR > & operator=(const O3SystemFactory< GUM_SCALAR > &src)
void _addAssignments_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
bool _checkIncrements_(O3System &sys)
ErrorsContainer * _errors_
bool _checkAssignments_(O3System &sys)
HashTable< std::string, O3Instance * > _nameMap_
void _addInstances_(PRMFactory< GUM_SCALAR > &factory, O3System &sys)
O3NameSolver< GUM_SCALAR > * _solver_
bool _checkSystem_(O3System &sys)
bool _checkInstance_(O3System &sys)
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