21 #ifndef DOXYGEN_SHOULD_SKIP_THIS 34 template <
typename GUM_SCALAR >
36 InfluenceDiagram< GUM_SCALAR >* infdiag,
const std::string& filePath) :
37 IDReader< GUM_SCALAR >(infdiag, filePath) {
46 template <
typename GUM_SCALAR >
57 template <
typename GUM_SCALAR >
61 std::string status =
"Loading File ...";
67 if (xmlDoc.NoChildren()) {
69 ": Loading fail, please check the file for any syntax error.");
73 status =
"File loaded. Now looking for BIF element ...";
79 status =
"BIF Element reached. Now searching network ...";
85 status =
"Network found. Now proceeding variables instanciation...";
91 status =
"All variables have been instancied. Now filling up diagram...";
96 status =
"Instanciation of network completed";
104 template <
typename GUM_SCALAR >
111 for (varIte = varIte.begin(parentNetwork); varIte != varIte.end(); ++varIte)
117 for (varIte = varIte.begin(parentNetwork); varIte != varIte.end(); ++varIte) {
129 LabelizedVariable newVar(varName, varDescription, 0);
134 for (varOutComesIte = varOutComesIte.begin(currentVar);
135 varOutComesIte != varOutComesIte.end();
137 newVar.addLabel(varOutComesIte->GetTextOrDefault(
""));
140 std::string nodeType = currentVar->
GetAttribute< std::string >(
"TYPE");
143 if (nodeType.compare(
"decision") == 0)
145 else if (nodeType.compare(
"utility") == 0)
152 "Network found. Now proceedind variables instanciation...";
153 int progress = (int)((
float)nbIte / (float)nbVar * 45) + 10;
159 template <
typename GUM_SCALAR >
166 for (definitionIte = definitionIte.begin(parentNetwork);
167 definitionIte != definitionIte.end();
174 for (definitionIte = definitionIte.begin(parentNetwork);
175 definitionIte != definitionIte.end();
180 std::string currentVarName =
186 List< NodeId > parentList;
188 for (givenIte = givenIte.begin(currentVar); givenIte != givenIte.end();
190 std::string parentNode = givenIte->GetTextOrDefault(
"");
192 parentList.pushBack(parentId);
196 parentListIte != parentList.rendSafe();
198 __infdiag->addArc(*parentListIte, currentVarId);
201 if (!
__infdiag->isDecisionNode(currentVarId)) {
204 std::list< GUM_SCALAR > tablelist;
207 while (!issTableString.eof()) {
208 issTableString >> value;
209 tablelist.push_back(value);
212 std::vector< GUM_SCALAR > tablevector(tablelist.begin(), tablelist.end());
215 if (
__infdiag->isChanceNode(currentVarId)) {
216 const Potential< GUM_SCALAR >* table = &
__infdiag->cpt(currentVarId);
217 table->populate(tablevector);
218 }
else if (
__infdiag->isUtilityNode(currentVarId)) {
219 const Potential< GUM_SCALAR >* table = &
__infdiag->utility(currentVarId);
220 table->populate(tablevector);
226 "All variables have been instancied. Now filling up diagram...";
227 int progress = (int)((
float)nbIte / (float)nbDef * 45) + 55;
235 #endif // DOXYGEN_SHOULD_SKIP_THIS Wrapper around TiXmlElement.
std::string __filePath
the path to the xml filePath
classe for import of Influence Diagram from a XML file written with BIF Format
gum::Signaler2< int, std::string > onProceed
Signaler used to indicates how many percent of the Xml files have been parsed yet.
std::string GetTextOrDefault(const std::string &defaultValue) const
Gets the text of an Element, if it doesn't exist it will return the defaultValue. ...
ListIteratorSafe< Val > iterator_safe
Types for STL compliance.
gum is the global namespace for all aGrUM entities
void __parsingVariables(ticpp::Element *parentNetwork)
Parsing xml element containing data on variables.
void __fillingDiagram(ticpp::Element *parentNetwork)
fill the diagram
BIFXMLIDReader(InfluenceDiagram< GUM_SCALAR > *infdiag, const std::string &filePath)
Constructor A reader is created to reading a defined file.
const char * what() const
Override std::exception::what() to return m_details.
This is a ticpp exception class.
#define GUM_EMIT2(signal, arg1, arg2)
InfluenceDiagram< GUM_SCALAR > * __infdiag
An handle to the influence diagram in which will be load the content of the xml filePath.
~BIFXMLIDReader()
Default destructor.
Wrapper around TiXmlDocument.
T GetAttribute(const std::string &name, bool throwIfNotFound=true) const
Returns an attribute of name from an element.
Element * FirstChildElement(bool throwIfNoChildren=true) const
The first child element of this node.
Iterator for conveniently stepping through Nodes and Attributes.
virtual void proceed()
Reads the influence diagram from the file referenced by filePath given at the creation of class...
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)