29 #ifndef GUM_PRM_FACTORY_H 30 #define GUM_PRM_FACTORY_H 38 #include <agrum/agrum.h> 39 #include <agrum/tools/core/list.h> 41 #include <agrum/tools/multidim/implementations/multiDimSparse.h> 42 #include <agrum/tools/variables/discreteVariable.h> 44 #include <agrum/PRM/IPRMFactory.h> 45 #include <agrum/PRM/PRM.h> 46 #include <agrum/PRM/utils_prm.h> 73 template <
typename GUM_SCALAR >
74 class PRMFactory:
public IPRMFactory {
89 PRMFactory(PRM< GUM_SCALAR >* prm);
92 PRMFactory(
const PRMFactory& from) =
delete;
95 PRMFactory& operator=(
const PRMFactory& from) =
delete;
99 virtual ~PRMFactory();
113 PRM< GUM_SCALAR >* prm()
const;
119 virtual PRMObject::prm_type currentType()
const override;
125 virtual PRMObject* getCurrent() override;
126 virtual const PRMObject* getCurrent()
const override;
139 virtual PRMObject* closeCurrent() override;
144 virtual std::string currentPackage()
const override;
154 PRMClass< GUM_SCALAR >& retrieveClass(
const std::string& name);
164 PRMType& retrieveType(
const std::string& name);
191 PRMType& retrieveCommonType(
const std::vector< PRMClassElement< GUM_SCALAR >* >& elts);
207 virtual void pushPackage(
const std::string& name) override;
214 virtual std::string popPackage() override;
235 virtual void addImport(
const std::string& name) override;
252 virtual void startDiscreteType(
const std::string& name, std::string super =
"") override;
267 virtual void addLabel(
const std::string& l, std::string ext =
"") override;
275 virtual void endDiscreteType() override;
285 virtual void startDiscretizedType(
const std::string& name) override;
292 virtual void addTick(
double tick) override;
300 virtual void endDiscretizedType() override;
314 virtual void addRangeType(
const std::string& name,
long minVal,
long maxVal) override;
319 virtual bool isClassOrInterface(
const std::string& type)
const override;
320 virtual bool isArrayInCurrentSystem(
const std::string& name)
const override;
341 virtual void startClass(
const std::string& c,
342 const std::string& ext =
"",
343 const Set< std::string >* implements =
nullptr,
344 bool delayInheritance =
false) override;
349 virtual void continueClass(
const std::string& c) override;
358 virtual void endClass(
bool checkImplementations =
true) override;
380 virtual void startInterface(
const std::string& i,
381 const std::string& ext =
"",
382 bool delayInheritance =
false) override;
387 virtual void continueInterface(
const std::string& name) override;
393 virtual void addAttribute(
const std::string& type,
const std::string& name) override;
398 virtual void endInterface() override;
426 virtual void addAttribute(PRMAttribute< GUM_SCALAR >* attr);
432 virtual void startAttribute(
const std::string& type,
433 const std::string& name,
434 bool scalar_atttr =
false) override;
439 virtual void continueAttribute(
const std::string& name) override;
449 virtual void addParent(
const std::string& name) override;
470 void setRawCPFByLines(
const std::vector< GUM_SCALAR >& array);
492 void setRawCPFByColumns(
const std::vector< GUM_SCALAR >& array);
506 virtual void setCPFByRule(
const std::vector< std::string >& labels,
507 const std::vector< GUM_SCALAR >& values);
521 virtual void setCPFByRule(
const std::vector< std::string >& labels,
522 const std::vector< std::string >& values) override;
543 virtual void setRawCPFByFloatLines(
const std::vector<
float >& array) override;
565 virtual void setRawCPFByFloatColumns(
const std::vector<
float >& array) override;
587 virtual void setRawCPFByColumns(
const std::vector< std::string >& array) override;
608 virtual void setRawCPFByLines(
const std::vector< std::string >& array) override;
622 virtual void setCPFByFloatRule(
const std::vector< std::string >& labels,
623 const std::vector<
float >& values) override;
629 virtual void endAttribute() override;
648 void addParameter(
const std::string& type,
const std::string& name,
double value) override;
677 virtual void addAggregator(
const std::string& name,
678 const std::string& agg_type,
679 const std::vector< std::string >& chains,
680 const std::vector< std::string >& params,
681 std::string type =
"") override;
692 void startAggregator(
const std::string& name,
693 const std::string& agg_type,
694 const std::string& rv_type,
695 const std::vector< std::string >& params);
700 void continueAggregator(
const std::string& name);
706 void endAggregator();
732 virtual void addNoisyOrCompound(
const std::string& name,
733 const std::vector< std::string >& chains,
734 const std::vector<
float >& numbers,
736 const std::vector< std::string >& label) override;
748 addReferenceSlot(
const std::string& type,
const std::string& name,
bool isArray) override;
760 virtual void startSystem(
const std::string& name) override;
766 virtual void endSystem() override;
771 virtual void addInstance(
const std::string& type,
const std::string& name) override;
776 void addInstance(
const std::string& type,
777 const std::string& name,
778 const HashTable< std::string,
double >& params) override;
786 virtual void addArray(
const std::string& type,
const std::string& name, Size size) override;
791 virtual void incArray(
const std::string& l_i,
const std::string& r_i) override;
807 virtual void setReferenceSlot(
const std::string& left_instance,
808 const std::string& left_reference,
809 const std::string& right_instance) override;
825 virtual void setReferenceSlot(
const std::string& l_i,
const std::string& r_i) override;
840 std::string _addPrefix_(
const std::string& str)
const;
847 PRMObject* _checkStack_(Idx i, PRMObject::prm_type obj_type);
849 PRMClassElement< GUM_SCALAR >*
850 _checkStack_(Idx i,
typename PRMClassElement< GUM_SCALAR >::ClassElementType obj_type);
852 PRMClassElementContainer< GUM_SCALAR >* _checkStackContainter_(Idx i);
876 PRMType* _retrieveType_(
const std::string& name)
const;
883 PRMClass< GUM_SCALAR >* _retrieveClass_(
const std::string& name)
const;
890 PRMInterface< GUM_SCALAR >* _retrieveInterface_(
const std::string& name)
const;
905 PRMSlotChain< GUM_SCALAR >* _buildSlotChain_(PRMClassElementContainer< GUM_SCALAR >* start,
906 const std::string& name);
929 bool _retrieveInputs_(PRMClass< GUM_SCALAR >* c,
930 const std::vector< std::string >& chains,
931 std::vector< PRMClassElement< GUM_SCALAR >* >& inputs);
955 PRMType* _retrieveCommonType_(
const std::vector< PRMClassElement< GUM_SCALAR >* >& elts);
964 int _typeDepth_(
const PRMType* t);
967 void _checkInterfaceImplementation_(PRMClass< GUM_SCALAR >* c);
970 void _addParent_(PRMClassElementContainer< GUM_SCALAR >* c,
971 PRMAttribute< GUM_SCALAR >* agg,
972 const std::string& name);
975 void _addParent_(PRMClass< GUM_SCALAR >* c,
976 PRMAggregate< GUM_SCALAR >* agg,
977 const std::string& name);
986 void _addInstance_(PRMClass< GUM_SCALAR >* type,
const std::string& name);
995 void _buildAggregateCPF_(PRMSystem< GUM_SCALAR >* model);
998 void _instantiateSlotChain_(PRMSystem< GUM_SCALAR >* model,
999 PRMInstance< GUM_SCALAR >* inst,
1000 PRMReferenceSlot< GUM_SCALAR >* ref,
1001 PRMSlotChain< GUM_SCALAR >* sc);
1008 std::string _retrieveInstanceSequence_(PRMInstance< GUM_SCALAR >* inst,
1009 Sequence< PRMInstance< GUM_SCALAR >* >& seq,
1010 PRMSlotChain< GUM_SCALAR >* sc);
1020 std::vector< std::string > _packages_;
1023 std::vector< List< std::string >* > _namespaces_;
1026 PRM< GUM_SCALAR >* _prm_;
1029 std::vector< PRMObject* > _stack_;
1032 HashTable< PRMAggregate< GUM_SCALAR >*, std::vector< std::string > > _agg_params_;
1039 #include <agrum/PRM/PRMFactory_tpl.h>