30 #ifndef GUM_PRM_FACTORY_H 31 #define GUM_PRM_FACTORY_H 74 template <
typename GUM_SCALAR >
75 class PRMFactory :
public IPRMFactory {
114 PRM< GUM_SCALAR >*
prm()
const;
127 virtual const PRMObject*
getCurrent()
const override;
155 PRMClass< GUM_SCALAR >&
retrieveClass(
const std::string& name);
193 const std::vector< PRMClassElement< GUM_SCALAR >* >& elts);
209 virtual void pushPackage(
const std::string& name)
override;
237 virtual void addImport(
const std::string& name)
override;
255 std::string super =
"")
override;
270 virtual void addLabel(
const std::string& l, std::string ext =
"")
override;
295 virtual void addTick(
double tick)
override;
318 addRangeType(
const std::string& name,
long minVal,
long maxVal)
override;
346 const std::string& ext =
"",
348 bool delayInheritance =
false)
override;
362 virtual void endClass(
bool checkImplementations =
true)
override;
385 const std::string& ext =
"",
386 bool delayInheritance =
false)
override;
398 const std::string& name)
override;
431 virtual void addAttribute(PRMAttribute< GUM_SCALAR >* attr);
438 const std::string& name,
439 bool scalar_atttr =
false)
override;
454 virtual void addParent(
const std::string& name)
override;
511 virtual void setCPFByRule(
const std::vector< std::string >& labels,
512 const std::vector< GUM_SCALAR >& values);
526 virtual void setCPFByRule(
const std::vector< std::string >& labels,
527 const std::vector< std::string >& values)
override;
632 const std::vector< float >& values)
override;
658 const std::string& name,
659 double value)
override;
689 const std::string& agg_type,
690 const std::vector< std::string >& chains,
691 const std::vector< std::string >& params,
692 std::string type =
"")
override;
704 const std::string& agg_type,
705 const std::string& rv_type,
706 const std::vector< std::string >& params);
745 const std::vector< std::string >& chains,
746 const std::vector< float >& numbers,
748 const std::vector< std::string >& label)
override;
760 const std::string& name,
761 bool isArray)
override;
773 virtual void startSystem(
const std::string& name)
override;
785 const std::string& name)
override;
791 const std::string& name,
800 virtual void addArray(
const std::string& type,
801 const std::string& name,
807 virtual void incArray(
const std::string& l_i,
808 const std::string& r_i)
override;
825 const std::string& left_reference,
826 const std::string& right_instance)
override;
843 const std::string& r_i)
override;
850 const std::string& str);
858 std::string
__addPrefix(
const std::string& str)
const;
901 PRMClass< GUM_SCALAR >*
__retrieveClass(
const std::string& name)
const;
908 PRMInterface< GUM_SCALAR >*
924 PRMSlotChain< GUM_SCALAR >*
926 const std::string& name);
950 const std::vector< std::string >& chains,
951 std::vector< PRMClassElement< GUM_SCALAR >* >& inputs);
976 const std::vector< PRMClassElement< GUM_SCALAR >* >& elts);
991 void __addParent(PRMClassElementContainer< GUM_SCALAR >* c,
992 PRMAttribute< GUM_SCALAR >* agg,
993 const std::string& name);
997 PRMAggregate< GUM_SCALAR >* agg,
998 const std::string& name);
1007 void __addInstance(PRMClass< GUM_SCALAR >* type,
const std::string& name);
1021 PRMInstance< GUM_SCALAR >* inst,
1022 PRMReferenceSlot< GUM_SCALAR >* ref,
1023 PRMSlotChain< GUM_SCALAR >* sc);
1032 Sequence< PRMInstance< GUM_SCALAR >* >& seq,
1033 PRMSlotChain< GUM_SCALAR >* sc);
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
virtual void endInterface() override
Tells the factory that we finished an interface declaration.
virtual void pushPackage(const std::string &name) override
Define the current package.
virtual void addAggregator(const std::string &name, const std::string &agg_type, const std::vector< std::string > &chains, const std::vector< std::string > ¶ms, std::string type="") override
Add an aggregator in the current declared class.
virtual void addRangeType(const std::string &name, long minVal, long maxVal) override
Add a range variable type declaration.
HashTable< PRMAggregate< GUM_SCALAR > *, std::vector< std::string > > __agg_params
A mapping between aggregators and their parameters.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void endAggregator()
Finishes an aggregate declaration.
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 ~PRMFactory()
Destructor.
virtual void addNoisyOrCompound(const std::string &name, const std::vector< std::string > &chains, const std::vector< float > &numbers, float leak, const std::vector< std::string > &label) override
Add a compound noisy-or as an PRMAttribute<GUM_SCALAR> to the current Class<GUM_SCALAR>.
virtual std::string popPackage() override
Pop the current package from the package stack.
virtual void addInstance(const std::string &type, const std::string &name) override
Add an instance to the model.
virtual void setRawCPFByFloatColumns(const std::vector< float > &array) override
Gives the factory the CPF in its raw form.
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 setCPFByFloatRule(const std::vector< std::string > &labels, const std::vector< float > &values) override
Fills the CPF using a rule.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
PRMType * __retrieveType(const std::string &name) const
Returns a pointer on a PRMType given it's name. Since the type can be given either with it's local na...
virtual void continueClass(const std::string &c) override
Continue the declaration of a class.
PRMClassElementContainer< GUM_SCALAR > * __checkStackContainter(Idx i)
Adds __prefix to str iff __prefix != "".
virtual void continueInterface(const std::string &name) override
Continue the declaration of an interface.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void addImport(const std::string &name) override
Add an import for namespace lookup.
virtual void startDiscretizedType(const std::string &name) override
Start a discretized type declaration.
void __buildAggregateCPF(PRMSystem< GUM_SCALAR > *model)
Builds all Aggregates CPF in the given model. This must be called after all the slot chains have been...
PRMClass< GUM_SCALAR > & retrieveClass(const std::string &name)
Returns a reference over a Class<GUM_SCALAR> given its name.
virtual void endAttribute() override
Tells the factory that we finished declaring an attribute.
virtual void startInterface(const std::string &i, const std::string &ext="", bool delayInheritance=false) override
Tells the factory that we start an interface declaration.
virtual void addReferenceSlot(const std::string &type, const std::string &name, bool isArray) override
Tells the factory that we started declaring a slot.
PRMType & retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
PRMType & retrieveType(const std::string &name)
Returns a reference over a PRMType given its name.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void __addInstance(PRMClass< GUM_SCALAR > *type, const std::string &name)
Adds a instance to the current model.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void addAttribute(const std::string &type, const std::string &name) override
Add an attribute to an interface.
virtual void startClass(const std::string &c, const std::string &ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start a class declaration.
void __instantiateSlotChain(PRMSystem< GUM_SCALAR > *model, PRMInstance< GUM_SCALAR > *inst, PRMReferenceSlot< GUM_SCALAR > *ref, PRMSlotChain< GUM_SCALAR > *sc)
Instantiate a slot chain in the given instance.
void __buildSlotChains(PRMSystem< GUM_SCALAR > *model)
Builds all PRMSlotChain<GUM_SCALAR><PRMInstance<GUM_SCALAR>> in the given model.
void continueAggregator(const std::string &name)
Conitnues an aggregator declaration.
virtual void incArray(const std::string &l_i, const std::string &r_i) override
Add an instance to an array.
virtual void startSystem(const std::string &name) override
Tells the factory that we started declaring a model.
virtual void setRawCPFByFloatLines(const std::vector< float > &array) override
Gives the factory the CPF in its raw form.
virtual void startAttribute(const std::string &type, const std::string &name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
virtual std::string currentPackage() const override
PRMType * __retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.
void setRawCPFByColumns(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
prm_type
Enumeration of the different types of objects handled by a PRM.
virtual PRMObject::prm_type currentType() const override
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void __fill_sc_in_vector(std::vector< std::string > &v, const std::string &str)
Decompose a string in v using dots ('.') as delimiters.
virtual void setCPFByRule(const std::vector< std::string > &labels, const std::vector< GUM_SCALAR > &values)
Fills the CPF using a rule.
PRMSlotChain< GUM_SCALAR > * __buildSlotChain(PRMClassElementContainer< GUM_SCALAR > *start, const std::string &name)
This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.
void __addParent(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, const std::string &name)
Add a parent to an attribute.
virtual PRMObject * getCurrent() override
std::vector< std::string > __packages
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
PRMFactory()
Default constructor.
std::string __retrieveInstanceSequence(PRMInstance< GUM_SCALAR > *inst, Sequence< PRMInstance< GUM_SCALAR > * > &seq, PRMSlotChain< GUM_SCALAR > *sc)
Fill seq with the sequence of instance build using inst as the instantiation of sc->__class and seeki...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
virtual PRMObject * closeCurrent() override
Close current object being built.
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
void __checkInterfaceImplementation(PRMClass< GUM_SCALAR > *c)
Check if c implements correctly all his interfaces.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
std::string __addPrefix(const std::string &str) const
Adds __prefix to str iff __prefix != "".
virtual void startDiscreteType(const std::string &name, std::string super="") override
Start a discrete subtype declaration.
PRMClass< GUM_SCALAR > * __retrieveClass(const std::string &name) const
Returns a pointer on a class given it's name. Used when building models, meaning that the class name ...
virtual void endDiscretizedType() override
End the current discretized type declaration.
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
virtual void endDiscreteType() override
End the current discrete type declaration.
virtual void continueAttribute(const std::string &name) override
Continues the declaration of an attribute.
void addParameter(const std::string &type, const std::string &name, double value) override
Add a parameter to the current class with a default value.
std::vector< List< std::string > *> __namespaces
Set of all declared namespaces.
int __typeDepth(const PRMType *t)
Returns the inheritance depth of a PRMType.
virtual bool isClassOrInterface(const std::string &type) const override
virtual void addLabel(const std::string &l, std::string ext="") override
Add a label to the current discrete type.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
PRMFactory & operator=(const PRMFactory &from)=delete
Copy operator. Don't use it.
virtual void endSystem() override
Tells the factory that we finished declaring a model.
PRMInterface< GUM_SCALAR > * __retrieveInterface(const std::string &name) const
Returns a pointer on an interface given it's name. Used when building models, meaning that the interf...
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
virtual bool isArrayInCurrentSystem(const std::string &name) const override
void startAggregator(const std::string &name, const std::string &agg_type, const std::string &rv_type, const std::vector< std::string > ¶ms)
Start an aggregator declaration.
virtual void addParent(const std::string &name) override
Tells the factory that we add a parent to the current declared attribute.
virtual void addTick(double tick) override
Add a tick to the current discretized type.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
bool __retrieveInputs(PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
Retrieve inputs for an PRMAggregate.