48#ifndef DOXYGEN_SHOULD_SKIP_THIS
59 template <
typename GUM_SCALAR >
65 template <
typename GUM_SCALAR >
75 template <
typename GUM_SCALAR >
77 if (!output.good()) {
GUM_ERROR(IOError,
"Input/Output error : stream not writable.") }
79 output <<
"net " << bn.propertyWithDefault(
"name",
"unnamedBN") << std::endl
82 output <<
"// property softwar aGrUM " << GUM_VERSION << std::endl << std::endl;
84 for (
auto node: bn.topologicalOrder()) {
85 output << _variableBloc_(bn, bn.variable(node));
92 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
102 template <
typename GUM_SCALAR >
105 std::ofstream output(filePath.c_str(), std::ios_base::trunc);
107 _doWrite(output, bn);
110 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed.") }
116 template <
typename GUM_SCALAR >
120 std::ostringstream oss;
122 id = bn.idFromName(var.name());
124 oss <<
"\tnode " << this->_onlyValidCharsInName(var.name()) <<
"\n\t{\n";
126 oss <<
"\t\tTYPE = CPT;\n";
128 oss <<
"\t\tHEADER =\n\t\t{\n";
129 oss <<
"\t\t\tID = " << this->_onlyValidCharsInName(var.name()) <<
";\n";
130 oss <<
"\t\t\tNAME = \"" << this->_onlyValidCharsInName(var.name()) <<
"\";\n";
133 oss <<
"\t\tPARENTS = (";
136 for (
Idx i = tmp_vars.size() - 1; i > 0; i--) {
137 if (i < tmp_vars.size() - 1) oss <<
", ";
139 oss << this->_onlyValidCharsInName(tmp_vars[i]->name());
144 oss <<
"\t\tDEFINITION =\n\t\t{\n";
147 oss <<
"\t\t\tNAMESTATES = (";
149 for (
Idx i = 0; i < var.domainSize(); i++) {
150 if (i != 0) oss <<
", ";
152 oss << this->_onlyValidCharsInName(var.label(i));
160 oss <<
"\t\t\tPROBABILITIES = (";
164 for (iter.setFirst(); i < bn.cpt(
id).domainSize(); ++iter, ++i) {
165 if (i != 0) oss <<
", ";
166 oss << bn.cpt(
id)[iter];
180 template <
typename GUM_SCALAR >
182 this->_validCharInNamesCheck(bn);
Class representing the minimal interface for Bayesian network with no numerical data.
Writes a IBayesNet in the DSL format.
void _doWrite(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn) final
Writes a Bayesian network in the output stream using the DSL format.
std::string _variableBloc_(const IBayesNet< GUM_SCALAR > &bn, const DiscreteVariable &var)
void _syntacticalCheck(const IBayesNet< GUM_SCALAR > &bn) final
Check whether the BN is syntactically correct for BIF format.
DSLWriter()
Default constructor.
~DSLWriter() override
Destructor.
Base class for discrete random variable.
Class representing the minimal interface for Bayesian network with no numerical data.
Class for assigning/browsing values to tuples of discrete variables.
The generic class for storing (ordered) sequences of objects.
#define GUM_ERROR(type, msg)
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities