21 #ifndef DOXYGEN_SHOULD_SKIP_THIS 30 template <
typename GUM_SCALAR >
32 GUM_CONSTRUCTOR(UAIWriter);
38 template <
typename GUM_SCALAR >
40 GUM_DESTRUCTOR(UAIWriter);
50 template <
typename GUM_SCALAR >
52 const IBayesNet< GUM_SCALAR >& bn) {
54 GUM_ERROR(IOError,
"Stream states flags are not all unset.");
57 output << __preambule(bn) << std::endl;
59 for (
auto node : bn.nodes())
60 output << __cptBloc(bn, node) << std::endl;
66 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed."); }
78 template <
typename GUM_SCALAR >
80 const IBayesNet< GUM_SCALAR >& bn) {
81 std::ofstream output(filePath.c_str(), std::ios_base::trunc);
87 if (output.fail()) {
GUM_ERROR(IOError,
"Writing in the ostream failed."); }
90 template <
typename GUM_SCALAR >
93 std::stringstream str;
95 str <<
"BAYES" << std::endl;
97 str << bn.size() << std::endl;
99 for (
auto node : bn.nodes())
100 str << bn.variable(node).domainSize() <<
" ";
103 str << bn.size() << std::endl;
105 for (
auto node : bn.nodes()) {
106 const auto& p = bn.cpt(node);
107 str << p.nbrDim() <<
" ";
112 for (
auto k : p.variablesSequence()) {
115 first = bn.idFromName(k->name());
117 str << bn.idFromName(k->name()) <<
" ";
120 str << first <<
" # " << bn.variable(node).name() << std::endl;
126 template <
typename GUM_SCALAR >
130 std::stringstream str;
132 const auto& p = bn.cpt(node);
133 str << p.domainSize();
135 for (I.setFirst(); !I.end(); ++I) {
136 if (I.val(0) == 0) str << std::endl <<
" ";
146 #endif // DOXYGEN_SHOULD_SKIP_THIS ~UAIWriter() final
Destructor.
gum is the global namespace for all aGrUM entities
std::string __cptBloc(const IBayesNet< GUM_SCALAR > &bn, NodeId node)
Definition file for BIF XML exportation class.
void write(std::ostream &output, const IBayesNet< GUM_SCALAR > &bn) final
Writes an bayes net in the given ouput stream.
UAIWriter()
Default constructor.
std::string __preambule(const IBayesNet< GUM_SCALAR > &bn)
Returns the header of the BIF file.
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)